early/ts/early.child.ts

48 lines
1.1 KiB
TypeScript
Raw Normal View History

import 'typings-global'
import chalk = require('chalk')
import readline = require('readline')
2016-06-10 03:59:21 +00:00
let rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
let moduleName: string
let loaderLength: number
let frameCounter: number = 0
2016-08-20 05:03:49 +00:00
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 = () => {
2016-08-20 05:03:49 +00:00
if (!logEarlyAbort) {
rl.write(null, { ctrl: true, name: 'u' })
rl.write(makeFrame())
2016-08-20 05:03:49 +00:00
setTimeout(function () {
logEarly()
}, 80)
} else {
readline.clearLine(process.stdout,0)
process.exit(0)
2016-08-20 05:03:49 +00:00
}
}
let start = function (moduleNameArg: string = '', loaderLengthArg: string = '10') {
moduleName = moduleNameArg
loaderLength = parseInt(loaderLengthArg)
logEarly()
}
2016-06-10 03:59:21 +00:00
2016-08-20 05:41:56 +00:00
process.on('SIGINT', () => {
logEarlyAbort = true
})
start()