early/dist/index.js

52 lines
4.0 KiB
JavaScript
Raw Normal View History

2016-05-20 17:06:25 +00:00
"use strict";
2016-06-10 03:18:03 +00:00
require("typings-global");
2016-08-20 05:03:49 +00:00
const path = require("path");
const chalk = require("chalk");
let q = require("q");
const childProcess = require("child_process");
let earlyChild;
let doAnimation = true;
let doText = false;
let moduleName = "undefined module name";
let startTime;
2016-06-10 03:36:06 +00:00
if (process.argv.indexOf("-v") != -1 || process.env.CI) {
2016-06-10 03:18:03 +00:00
doAnimation = false;
}
2016-08-20 05:51:04 +00:00
if (process.argv.indexOf("-v") == -1 && process.env.CI) {
2016-06-10 03:36:06 +00:00
doText = true;
}
2016-05-21 18:33:13 +00:00
// exports
2016-08-20 05:03:49 +00:00
exports.start = function (moduleNameArg = "", loaderLengthArg = "10") {
startTime = Date.now();
2016-08-20 05:03:49 +00:00
moduleName = moduleNameArg;
2016-06-10 03:18:03 +00:00
if (doAnimation) {
earlyChild = childProcess.fork(path.join(__dirname, "early.child.js"), [], {
env: {
moduleNameArg: moduleNameArg,
loaderLengthArg: loaderLengthArg,
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:36:06 +00:00
}
2016-05-20 17:06:25 +00:00
};
exports.stop = function () {
2016-08-20 05:03:49 +00:00
let done = q.defer();
let endTime = Date.now();
let executionTime = ((endTime - startTime) / 1000).toString();
2016-06-10 03:18:03 +00:00
if (doAnimation) {
2016-08-20 05:41:56 +00:00
earlyChild.kill("SIGINT");
2016-06-11 21:47:52 +00:00
earlyChild.on("close", function () {
console.log(`loaded ${chalk.green(moduleName)} in ${executionTime} seconds!`);
2016-06-11 21:53:48 +00:00
done.resolve();
2016-06-11 21:47:52 +00:00
});
2016-06-10 03:18:03 +00:00
}
2016-06-11 21:53:48 +00:00
else {
2016-08-20 05:51:04 +00:00
console.log(`... finished loading ${moduleName} in ${executionTime}`);
2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