update
This commit is contained in:
@ -1,50 +0,0 @@
|
||||
import 'typings-global'
|
||||
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 makeFrame = (): string => {
|
||||
let resultString: string = `[${chalk.green('/'.repeat(frameCounter))}${' '.repeat(loaderLength - frameCounter)}] starting ${moduleName}`
|
||||
if (frameCounter === loaderLength) {
|
||||
frameCounter = 0
|
||||
} else {
|
||||
frameCounter++
|
||||
}
|
||||
return resultString
|
||||
}
|
||||
|
||||
let logEarlyAbort = false
|
||||
let logEarly = () => {
|
||||
if (!logEarlyAbort) {
|
||||
rl.write(null, { ctrl: true, name: 'u' })
|
||||
rl.write(makeFrame())
|
||||
setTimeout(function () {
|
||||
logEarly()
|
||||
}, 80)
|
||||
} else {
|
||||
rl.write(null, { ctrl: true, name: 'u' })
|
||||
rl.close()
|
||||
setTimeout(function () {
|
||||
process.exit(0)
|
||||
}, 80)
|
||||
}
|
||||
}
|
||||
|
||||
let start = function (moduleNameArg: string = '', loaderLengthArg: string = '10') {
|
||||
moduleName = moduleNameArg
|
||||
loaderLength = parseInt(loaderLengthArg)
|
||||
logEarly()
|
||||
}
|
||||
|
||||
process.on('SIGINT', () => {
|
||||
logEarlyAbort = true
|
||||
})
|
||||
|
||||
start()
|
40
ts/index.ts
40
ts/index.ts
@ -2,36 +2,22 @@ import 'typings-global'
|
||||
import path = require('path')
|
||||
import chalk = require('chalk')
|
||||
import q = require('q')
|
||||
import childProcess = require('child_process')
|
||||
let earlyChild
|
||||
|
||||
let doAnimation: boolean = true
|
||||
|
||||
let doText: boolean = false
|
||||
let moduleName: string = 'undefined module name'
|
||||
let startTime
|
||||
let startTime = Date.now()
|
||||
|
||||
if (process.argv.indexOf('-v') !== -1 || process.env.CI) {
|
||||
doAnimation = false
|
||||
}
|
||||
if (process.argv.indexOf('-v') === -1 && process.env.CI) {
|
||||
if (process.argv.indexOf('-v') === -1) {
|
||||
doText = true
|
||||
}
|
||||
|
||||
// exports
|
||||
/**
|
||||
* start the loading
|
||||
*/
|
||||
export let start = function (moduleNameArg: string = '', loaderLengthArg: string = '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) {
|
||||
if (doText) {
|
||||
console.log(`**** starting ${chalk.green(moduleNameArg)} ****`)
|
||||
}
|
||||
}
|
||||
@ -41,15 +27,7 @@ export let stop = (): q.Promise<number> => {
|
||||
let endTime = Date.now()
|
||||
let earlyExecutionTime: number = (endTime - startTime)
|
||||
let earlyExecutionTimeString: string = (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)
|
||||
}
|
||||
console.log(`... finished loading ${moduleName} in ${earlyExecutionTimeString}`)
|
||||
done.resolve(earlyExecutionTime)
|
||||
return done.promise
|
||||
}
|
||||
|
Reference in New Issue
Block a user