early/dist/index.js

53 lines
4.2 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFDUCxDQUFDLENBRHNCO0FBQ3ZCLE1BQU8sSUFBSSxXQUFXLE1BQU0sQ0FBQyxDQUFBO0FBQzdCLE1BQU8sS0FBSyxXQUFXLE9BQU8sQ0FBQyxDQUFBO0FBQy9CLE1BQU8sQ0FBQyxXQUFXLEdBQUcsQ0FBQyxDQUFBO0FBQ3ZCLE1BQU8sWUFBWSxXQUFXLG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