early/ts/index.ts

56 lines
1.5 KiB
TypeScript
Raw Normal View History

2016-06-10 03:18:03 +00:00
import "typings-global"
2016-05-23 02:51:45 +00:00
import path = require("path");
2016-08-20 05:03:49 +00:00
import chalk = require("chalk");
2016-06-11 21:47:52 +00:00
let q = require("q");
2016-06-10 03:18:03 +00:00
import readline = require("readline");
import childProcess = require("child_process");
let earlyChild;
2016-06-10 03:18:03 +00:00
2016-08-20 05:03:49 +00:00
let doAnimation: boolean = true;
let doText: boolean = false;
let moduleName:string = "undefined module name";
let startTime;
if (process.argv.indexOf("-v") != -1 || process.env.CI) {
2016-06-10 03:18:03 +00:00
doAnimation = false;
2016-08-20 05:03:49 +00:00
} else if (process.argv.indexOf("-v") == -1) {
2016-06-10 03:36:06 +00:00
doText = true;
2016-06-10 03:18:03 +00:00
}
2016-05-21 18:33:13 +00:00
// exports
2016-08-20 05:03:49 +00:00
export let start = function (moduleNameArg: string = "", loaderLengthArg: string = "10") {
startTime = process.hrtime();
moduleName = moduleNameArg;
if (doAnimation) {
earlyChild = childProcess.fork(path.join(__dirname, "early.child.js"), [], {
2016-06-10 03:18:03 +00:00
env: {
2016-08-20 05:03:49 +00:00
moduleNameArg: moduleNameArg,
loaderLengthArg: loaderLengthArg,
2016-06-10 03:18:03 +00:00
CI: process.env.CI
}
});
2016-06-10 03:36:06 +00:00
} else if (doText) {
2016-08-20 05:03:49 +00:00
console.log(`**** starting ${chalk.green(moduleNameArg)} ****`);
2016-06-10 03:18:03 +00:00
}
2016-05-20 17:06:25 +00:00
};
2016-08-20 05:03:49 +00:00
export let stop = function () {
2016-06-11 21:53:48 +00:00
let done = q.defer();
2016-08-20 05:03:49 +00:00
let endTime = process.hrtime(startTime);
let executionTime = (endTime[0] * 1e9 + endTime[1]) / 1000000000;
if (doAnimation) {
earlyChild.kill("SIGHUP");
earlyChild.on("close", function () {
console.log(` in ${executionTime} seconds!`);
2016-06-11 21:47:52 +00:00
done.resolve();
})
2016-06-11 21:53:48 +00:00
} else {
2016-08-20 05:03:49 +00:00
console.log("... finished loading moduleName in {executionTime}");
2016-06-11 21:53:48 +00:00
done.resolve();
2016-06-10 03:18:03 +00:00
}
2016-06-11 21:53:48 +00:00
return done.promise;
2016-05-20 17:06:25 +00:00
};