Skip to content

Instantly share code, notes, and snippets.

@RhinoLu
Last active November 7, 2017 07:39
Show Gist options
  • Save RhinoLu/e7884bb86c444b1f305bcd7338027811 to your computer and use it in GitHub Desktop.
Save RhinoLu/e7884bb86c444b1f305bcd7338027811 to your computer and use it in GitHub Desktop.
[ Typescript ] 編譯多語系與 standalone/bundle (for IntelliJ IDEA watcher)
{
"compilerOptions": {
"target": "ES5",
"removeComments": true,
"sourceMap": false,
"allowSyntheticDefaultImports": true,
"lib": [
"dom",
"es5",
"es2015.promise"
],
"outFile": "./bundles.js"
},
"files": [
"Home.ts",
"Nav.ts",
"Index.ts"
]
}
/// <reference path="./node_modules/@types/node/index.d.ts" />
/// <reference path="./node_modules/@types/shelljs/index.d.ts" />
import {ParsedPath} from "path";
const path = require("path");
const shell = require("shelljs");
shell.config.fatal = true;
shell.config.verbose = true;
shell.cd(path.parse(process.argv[1]).dir);
if(process.argv.length > 2){
console.log("\x1b[33m %s \x1b[0m", "start compiling...");
const fileObj: ParsedPath = path.parse(process.argv[2]);
const filePath: string = fileObj.dir + path.sep + fileObj.base;
const fileBase: string = fileObj.base;
if (fileBase.indexOf("Utils.ts") > -1) {
// 工具類,編譯一次,再複製到各個語系目錄
shell.exec(`tsc ./common/js/Utils.ts --removeComments`);
// 壓縮
shell.exec(`uglifyjs ./common/js/Utils.js --compress --source-map --output ./common/js/Utils.min.js`);
// 複製到各個語系目錄
shell.cp("./common/js/Utils.min.js", "./tw/js");
shell.cp("./common/js/Utils.min.js", "./hk/js");
// 移除 raw
shell.rm("./common/js/Utils.js");
} else if (filePath.indexOf("common/js/Abstract") > -1) {
// 父類有更動,各個語系子類依照 tsconfig 重新編譯
shell.exec(`tsc -p ./tw/js/bundles.json`);
shell.exec(`tsc -p ./hk/js/bundles.json`);
// 壓縮
shell.exec(`uglifyjs ./tw/js/bundles.js --compress --source-map --output ./tw/js/bundles.min.js`);
shell.exec(`uglifyjs ./hk/js/bundles.js --compress --source-map --output ./hk/js/bundles.min.js`);
// 移除 raw
shell.rm("./tw/js/bundles.js");
shell.rm("./hk/js/bundles.js");
} else if (fileBase.indexOf("Index.ts") > -1 || fileBase.indexOf("Home.ts") > -1 || fileBase.indexOf("Nav.ts") > -1) {
// 各個語系子類有更動,各自依照 tsconfig 重新編譯
shell.exec(`tsc -p ${fileObj.dir + "/bundles.json"}`);
// 壓縮
shell.exec(`uglifyjs ${fileObj.dir + "/bundles.js"} --compress --source-map --output ${fileObj.dir + "/bundles.min.js"}`);
// 移除 raw
shell.rm(`${fileObj.dir + "/bundles.js"}`);
} else {
console.log("\x1b[37m %s \x1b[0m", "no match !");
}
} else {
console.log("\x1b[37m %s \x1b[0m", "error");
}
@RhinoLu
Copy link
Author

RhinoLu commented Nov 7, 2017

folder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment