improved early and added loading time

This commit is contained in:
Philipp Kunz 2016-08-20 07:03:49 +02:00
parent 5f17ea48ed
commit 569c597f8b
6 changed files with 95 additions and 87 deletions

41
dist/early.child.js vendored
View File

@ -1,21 +1,16 @@
"use strict";
require("typings-global");
var colors = require("colors");
var readline = require("readline");
var rl = readline.createInterface({
const chalk = require("chalk");
const readline = require("readline");
let rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var moduleName;
var loaderLength;
var frameCounter = 0;
var makeFrame = function () {
var resultString = "["
+ "/".green.repeat(frameCounter)
+ " ".repeat(loaderLength - frameCounter)
+ "]"
+ " starting "
+ moduleName.cyan;
let moduleName;
let loaderLength;
let frameCounter = 0;
let makeFrame = () => {
let resultString = `[${chalk.green("/".repeat(frameCounter))}${" ".repeat(loaderLength - frameCounter)}] starting ${moduleName}`;
if (frameCounter == loaderLength) {
frameCounter = 0;
}
@ -24,29 +19,29 @@ var makeFrame = function () {
}
return resultString;
};
var logEarlyAbort = false;
var logEarly = function () {
let logEarlyAbort = false;
let logEarly = () => {
if (!logEarlyAbort) {
rl.write(null, { ctrl: true, name: 'u' });
rl.write(makeFrame());
setTimeout(function () {
if (!logEarlyAbort)
logEarly();
}, 80);
}
};
var start = function (moduleNameArg, loaderLengthArg) {
if (moduleNameArg === void 0) { moduleNameArg = ""; }
if (loaderLengthArg === void 0) { loaderLengthArg = "10"; }
let start = function (moduleNameArg = "", loaderLengthArg = "10") {
moduleName = moduleNameArg;
loaderLength = parseInt(loaderLengthArg);
logEarly();
};
start(process.env.moduleNameArg, process.env.loaderLengthArg);
process.on('SIGINT', function () {
process.on('SIGHUP', () => {
logEarlyAbort = true;
rl.write(null, { ctrl: true, name: 'u' });
rl.write(`loaded ${chalk.green(moduleName)}`);
rl.close();
rl.on("close", function () {
rl.on("close", () => {
process.exit(0);
});
});
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImVhcmx5LmNoaWxkLnRzIl0sIm5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R0FBRyxVQUFVLGFBQWEsR0FBVyxFQUFFLEVBQUUsZUFBZSxHQUFXLElBQUk7SUFDNUUsVUFBVSxHQUFHLGFBQWEsQ0FBQztJQUMzQixZQUFZLEdBQUcsUUFBUSxDQUFDLGVBQWUsQ0FBQyxDQUFDO0lBQ3pDLFFBQVEsRUFBRSxDQUFDO0FBQ2YsQ0FBQyxDQUFDO0FBRUYsS0FBSyxDQUFDLE9BQU8sQ0FBQyxHQUFHLENBQUMsYUFBYSxFQUFFLE9BQU8sQ0FBQyxHQUFHLENBQUMsZUFBZSxDQUFDLENBQUM7QUFFOUQsT0FBTyxDQUFDLEVBQUUsQ0FBQyxRQUFRLEVBQUU7SUFDakIsYUFBYSxHQUFHLElBQUksQ0FBQztJQUNyQixFQUFFLENBQUMsS0FBSyxDQUFDLElBQUksRUFBRSxFQUFFLElBQUksRUFBRSxJQUFJLEVBQUUsSUFBSSxFQUFFLEdBQUcsRUFBRSxDQUFDLENBQUM7SUFDMUMsRUFBRSxDQUFDLEtBQUssQ0FBQyxVQUFVLEtBQUssQ0FBQyxLQUFLLENBQUMsVUFBVSxDQUFDLEVBQUUsQ0FBQyxDQUFDO0lBQzlDLEVBQUUsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUNYLEVBQUUsQ0FBQyxFQUFFLENBQUMsT0FBTyxFQUFDO1FBQ1YsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUMsQ0FBQztJQUNwQixDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFDIn0=

35
dist/index.js vendored
View File

@ -1,11 +1,14 @@
"use strict";
require("typings-global");
var path = require("path");
var q = require("q");
var childProcess = require("child_process");
var earlyChild;
var doAnimation = true;
var doText = false;
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;
if (process.argv.indexOf("-v") != -1 || process.env.CI) {
doAnimation = false;
}
@ -13,9 +16,9 @@ else if (process.argv.indexOf("-v") == -1) {
doText = true;
}
// exports
exports.start = function (moduleNameArg, loaderLengthArg) {
if (moduleNameArg === void 0) { moduleNameArg = ""; }
if (loaderLengthArg === void 0) { loaderLengthArg = "10"; }
exports.start = function (moduleNameArg = "", loaderLengthArg = "10") {
startTime = process.hrtime();
moduleName = moduleNameArg;
if (doAnimation) {
earlyChild = childProcess.fork(path.join(__dirname, "early.child.js"), [], {
env: {
@ -26,22 +29,24 @@ exports.start = function (moduleNameArg, loaderLengthArg) {
});
}
else if (doText) {
console.log("**** starting " + moduleNameArg.cyan + " ****");
console.log(`**** starting ${chalk.green(moduleNameArg)} ****`);
}
};
exports.stop = function () {
var done = q.defer();
let done = q.defer();
let endTime = process.hrtime(startTime);
let executionTime = (endTime[0] * 1e9 + endTime[1]) / 1000000000;
if (doAnimation) {
earlyChild.kill();
earlyChild.kill("SIGHUP");
earlyChild.on("close", function () {
console.log("\n");
console.log(` in ${executionTime} seconds!`);
done.resolve();
});
}
else {
console.log("... finished loading moduleName in {executionTime}");
done.resolve();
}
return done.promise;
};
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUNQLENBQUMsQ0FEc0I7QUFFdkIsSUFBTyxJQUFJLFdBQVcsTUFBTSxDQUFDLENBQUM7QUFDOUIsSUFBSSxDQUFDLEdBQUcsT0FBTyxDQUFDLEdBQUcsQ0FBQyxDQUFDO0FBRXJCLElBQU8sWUFBWSxXQUFXLGVBQWUsQ0FBQyxDQUFDO0FBQy9DLElBQUksVUFBVSxDQUFDO0FBRWYsSUFBSSxXQUFXLEdBQVcsSUFBSSxDQUFDO0FBQy9CLElBQUksTUFBTSxHQUFXLEtBQUssQ0FBQztBQUMzQixFQUFFLENBQUEsQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLE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UFDLENBQUMsQ0FBQztRQUNkLFVBQVUsQ0FBQyxJQUFJLENBQUMsUUFBUSxDQUFDLENBQUM7UUFDMUIsVUFBVSxDQUFDLEVBQUUsQ0FBQyxPQUFPLEVBQUU7WUFDbkIsT0FBTyxDQUFDLEdBQUcsQ0FBQyxPQUFPLGFBQWEsV0FBVyxDQUFDLENBQUM7WUFDN0MsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFDO1FBQ25CLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQztJQUFDLElBQUksQ0FBQyxDQUFDO1FBQ0osT0FBTyxDQUFDLEdBQUcsQ0FBQyxvREFBb0QsQ0FBQyxDQUFDO1FBQ2xFLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQztJQUNuQixDQUFDO0lBQ0QsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7QUFDeEIsQ0FBQyxDQUFDIn0=

View File

@ -21,12 +21,13 @@
},
"homepage": "https://gitlab.com/pushrocks/early#readme",
"devDependencies": {
"npmts-g": "^5.2.6",
"npmts-g": "^5.2.8",
"typings-test": "^1.0.1"
},
"dependencies": {
"colors": "^1.1.2",
"@types/chalk": "^0.4.28",
"chalk": "^1.1.3",
"q": "^1.4.1",
"typings-global": "^1.0.3"
"typings-global": "^1.0.6"
}
}

View File

@ -1,6 +1,6 @@
"use strict";
require("typings-test");
var early = require("../dist/index");
const early = require("../dist/index");
describe("early", function () {
it(".start()", function (done) {
this.timeout(10000);
@ -12,5 +12,4 @@ describe("early", function () {
.then(done);
});
});
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsSUFBTyxLQUFLLFdBQVcsZUFBZSxDQUFDLENBQUM7QUFFeEMsUUFBUSxDQUFDLE9BQU8sRUFBQztJQUNiL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UFDLENBQUE7QUFDdEIsTUFBTyxLQUFLLFdBQVcsZUFBZSxDQUFDLENBQUM7QUFFeEMsUUFBUSxDQUFDLE9BQU8sRUFBQztJQUNiLEVBQUUsQ0FBQyxVQUFVLEVBQUMsVUFBUyxJQUFJO1FBQ3ZCLElBQUksQ0FBQyxPQUFPLENBQUMsS0FBSyxDQUFDLENBQUM7UUFDcEIsS0FBSyxDQUFDLEtBQUssQ0FBQyxPQUFPLENBQUMsQ0FBQztRQUNyQixVQUFVLENBQUMsSUFBSSxFQUFDLElBQUksQ0FBQyxDQUFDO0lBQzFCLENBQUMsQ0FBQyxDQUFDO0lBQ0gsRUFBRSxDQUFDLFNBQVMsRUFBQyxVQUFTLElBQUk7UUFDdEIsS0FBSyxDQUFDLElBQUksRUFBRTthQUNQLElBQUksQ0FBQyxJQUFJLENBQUMsQ0FBQztJQUNwQixDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFBIn0=

View File

@ -1,24 +1,18 @@
import "typings-global";
let colors = require("colors");
import chalk = require("chalk");
import readline = require("readline");
let rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let moduleName:string;
let loaderLength:number;
let frameCounter:number = 0;
let moduleName: string;
let loaderLength: number;
let frameCounter: number = 0;
let makeFrame = ():string => {
let resultString:string = "["
+ "/".green.repeat(frameCounter)
+ " ".repeat(loaderLength - frameCounter)
+ "]"
+ " starting "
+ moduleName.cyan;
if(frameCounter == loaderLength){
let makeFrame = (): string => {
let resultString: string = `[${chalk.green("/".repeat(frameCounter))}${" ".repeat(loaderLength - frameCounter)}] starting ${moduleName}`;
if (frameCounter == loaderLength) {
frameCounter = 0;
} else {
frameCounter++;
@ -28,25 +22,29 @@ let makeFrame = ():string => {
let logEarlyAbort = false;
let logEarly = () => {
rl.write(null, {ctrl: true, name: 'u'});
if (!logEarlyAbort) {
rl.write(null, { ctrl: true, name: 'u' });
rl.write(makeFrame());
setTimeout(function(){
if(!logEarlyAbort) logEarly();
},80);
setTimeout(function () {
logEarly();
}, 80);
}
};
let start = function(moduleNameArg:string = "",loaderLengthArg:string = "10"){
let start = function (moduleNameArg: string = "", loaderLengthArg: string = "10") {
moduleName = moduleNameArg;
loaderLength = parseInt(loaderLengthArg);
logEarly();
};
start(process.env.moduleNameArg,process.env.loaderLengthArg);
start(process.env.moduleNameArg, process.env.loaderLengthArg);
process.on('SIGINT', () => {
process.on('SIGHUP', () => {
logEarlyAbort = true;
rl.write(null, {ctrl: true, name: 'u'});
rl.write(null, { ctrl: true, name: 'u' });
rl.write(`loaded ${chalk.green(moduleName)}`);
rl.close();
rl.on("close",function(){
rl.on("close",() => {
process.exit(0);
})
});

View File

@ -1,43 +1,53 @@
import "typings-global"
import colors = require("colors");
import path = require("path");
import chalk = require("chalk");
let q = require("q");
import readline = require("readline");
import childProcess = require("child_process");
let earlyChild;
let doAnimation:boolean = true;
let doText:boolean = false;
if(process.argv.indexOf("-v") != -1 || process.env.CI){
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) {
doAnimation = false;
} else if(process.argv.indexOf("-v") == -1){
} else if (process.argv.indexOf("-v") == -1) {
doText = true;
}
// exports
export let start = function(moduleNameArg:string = "",loaderLengthArg:string = "10"){
if(doAnimation){
earlyChild = childProcess.fork(path.join(__dirname,"early.child.js"),[],{
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"), [], {
env: {
moduleNameArg:moduleNameArg,
loaderLengthArg:loaderLengthArg,
moduleNameArg: moduleNameArg,
loaderLengthArg: loaderLengthArg,
CI: process.env.CI
}
});
} else if (doText) {
console.log("**** starting " + moduleNameArg.cyan + " ****");
console.log(`**** starting ${chalk.green(moduleNameArg)} ****`);
}
};
export let stop = function(){
export let stop = function () {
let done = q.defer();
if(doAnimation){
earlyChild.kill();
earlyChild.on("close",function(){
console.log("\n");
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!`);
done.resolve();
})
} else {
console.log("... finished loading moduleName in {executionTime}");
done.resolve();
}
return done.promise;