early/dist/index.js

53 lines
4.1 KiB
JavaScript

"use strict";
require("typings-global");
const path = require("path");
const chalk = require("chalk");
const q = require("q");
const childProcess = require("child_process");
let earlyChild;
let doAnimation = true;
let doText = false;
let moduleName = 'undefined module name';
let startTime;
if (process.argv.indexOf('-v') !== -1 || process.env.CI) {
doAnimation = false;
}
if (process.argv.indexOf('-v') === -1 && process.env.CI) {
doText = true;
}
// exports
exports.start = function (moduleNameArg = '', loaderLengthArg = '10') {
startTime = Date.now();
moduleName = moduleNameArg;
if (doAnimation) {
earlyChild = childProcess.fork(path.join(__dirname, 'early.child.js'), [], {
env: {
moduleNameArg: moduleNameArg,
loaderLengthArg: loaderLengthArg,
CI: process.env.CI
}
});
}
else if (doText) {
console.log(`**** starting ${chalk.green(moduleNameArg)} ****`);
}
};
exports.stop = () => {
let done = q.defer();
let endTime = Date.now();
let earlyExecutionTime = (endTime - startTime);
let earlyExecutionTimeString = (earlyExecutionTime / 1000).toString();
if (doAnimation) {
earlyChild.kill('SIGINT');
earlyChild.on('close', function () {
console.log(`loaded ${chalk.green(moduleName)} in ${earlyExecutionTimeString} seconds!`);
done.resolve(earlyExecutionTime);
});
}
else {
console.log(`... finished loading ${moduleName} in ${earlyExecutionTimeString}`);
done.resolve(earlyExecutionTime);
}
return done.promise;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLDZCQUE2QjtBQUM3QiwrQkFBK0I7QUFDL0IsdUJBQXVCO0FBQ3ZCLDhDQUE4QztBQUM5QyxJQUFJLFVBQVUsQ0FBQTtBQUVkLElBQUksV0FBVyxHQUFZLElBQUksQ0FBQTtBQUMvQixJQUFJLE1BQU0sR0FBWSxLQUFLLENBQUE7QUFDM0IsSUFBSSxVQUFVLE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