-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ardalan Amini
committed
Dec 26, 2017
1 parent
9bfc391
commit cc58cd7
Showing
4 changed files
with
64 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env node | ||
|
||
const path = require('path') | ||
const rimraf = require('rimraf') | ||
const {spawn} = require('child_process') | ||
const fs = require('fs') | ||
const readdir = require('fs-readdir-recursive') | ||
const Uglify = require('uglify-js') | ||
|
||
rimraf(path.join(__dirname, '..', 'dist'), (err) => { | ||
if (err) throw new Error(err) | ||
|
||
const tsc = spawn(path.join(__dirname, '..', 'node_modules', '.bin', 'tsc')) | ||
|
||
tsc.stdout.on('data', (data) => { | ||
console.log(`stdout: ${data}`) | ||
}) | ||
|
||
tsc.stderr.on('data', (data) => console.log(`stderr: ${data}`)) | ||
|
||
tsc.on('close', (code) => { | ||
const distDir = path.join(__dirname, '..', 'dist') | ||
|
||
const distFileNames = readdir(distDir, (filename) => /(?<!\.ts)$/.test(filename)) | ||
|
||
distFileNames.map((filename) => { | ||
let filePath = path.join(distDir, filename) | ||
let content = fs.readFileSync(filePath, 'utf8') | ||
|
||
const jsonFiles = content.match(/require\("(.*\.json)"\)/g) | ||
if (jsonFiles) { | ||
for (let jsonFile of jsonFiles) { | ||
let jsonContent = fs.readFileSync( | ||
path.join( | ||
path.dirname(filePath.replace(/\/dist\//, '/src/')), | ||
/"(.*\.json)"/.exec(jsonFile)[1] | ||
), | ||
'utf8' | ||
) | ||
|
||
content = content.replace(jsonFile, jsonContent) | ||
} | ||
} | ||
|
||
content = Uglify.minify(content, { | ||
toplevel: true, | ||
}) | ||
|
||
if (content.error) throw new Error(content.error) | ||
|
||
fs.writeFileSync(filePath, content.code, 'utf8') | ||
}) | ||
|
||
if (code === 0) console.log('prepared and ready to go ;)') | ||
else console.log(`child process exited with code ${code}`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters