early/dist/index.js

53 lines
4.1 KiB
JavaScript
Raw Normal View History

2016-05-20 17:06:25 +00:00
"use strict";
require("typings-global");
const path = require("path");
const chalk = require("chalk");
const q = require("q");
const childProcess = require("child_process");
2016-08-20 05:03:49 +00:00
let earlyChild;
let doAnimation = true;
let doText = false;
2016-09-15 12:45:58 +00:00
let moduleName = 'undefined module name';
2016-08-20 05:03:49 +00:00
let startTime;
2016-09-15 12:45:58 +00:00
if (process.argv.indexOf('-v') !== -1 || process.env.CI) {
2016-06-10 03:18:03 +00:00
doAnimation = false;
}
2016-09-15 12:45:58 +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-09-15 12:45:58 +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) {
2016-09-15 12:45:58 +00:00
earlyChild = childProcess.fork(path.join(__dirname, 'early.child.js'), [], {
2016-06-10 03:18:03 +00:00
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
};
2016-09-15 12:45:58 +00:00
exports.stop = () => {
2016-08-20 05:03:49 +00:00
let done = q.defer();
let endTime = Date.now();
let earlyExecutionTime = (endTime - startTime);
let earlyExecutionTimeString = (earlyExecutionTime / 1000).toString();
2016-06-10 03:18:03 +00:00
if (doAnimation) {
2016-09-15 12:45:58 +00:00
earlyChild.kill('SIGINT');
earlyChild.on('close', function () {
console.log(`loaded ${chalk.green(moduleName)} in ${earlyExecutionTimeString} seconds!`);
done.resolve(earlyExecutionTime);
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 {
console.log(`... finished loading ${moduleName} in ${earlyExecutionTimeString}`);
done.resolve(earlyExecutionTime);
2016-06-11 21:53:48 +00:00
}
return done.promise;
2016-05-20 17:06:25 +00:00
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLDZCQUE2QjtBQUM3QiwrQkFBK0I7QUFDL0IsdUJBQXVCO0FBQ3ZCLDhDQUE4QztBQUM5QyxJQUFJLFVBQVUsQ0FBQTtBQUVkLElBQUksV0FBVyxHQUFZLElBQUksQ0FBQTtBQUMvQixJQUFJLE1BQU0sR0FBWSxLQUFLLENBQUE7QUFDM0IsSUFBSSxVQUFVLEdBQVcsdUJBQXVCLENBQUE7QUFDaEQsSUFBSSxTQUFTLENBQUE7QUFFYixFQUFFLENBQUMsQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsS0FBSyxDQUFDLENBQUMsSUFBSSxPQUFPLENBQUMsR0FBRyxDQUFDLEVBQUUsQ0FBQyxDQUFDLENBQUM7SUFDdEQsV0FBVyxHQUFHLEtBQUssQ0FBQTtBQUN2QixDQUFDO0FBQ0QsRUFBRSxDQUFDLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxDQUFDLElBQUksT0FBTyxDQUFDLEdBQUcsQ0FBQyxFQUFFLENBQUMsQ0FBQyxDQUFDO0lBQ3RELE1BQU0sR0FBRyxJQUFJLENBQUE7QUFDakIsQ0FBQztBQUVELFVBQVU7QUFDQyxRQUFBLEtBQUssR0FBRyxVQUFVLGFBQWEsR0FBVyxFQUFFLEVBQUUsZ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