Closed KRISBOTZ closed 2 years ago
console.log('Starting...') let cluster = require('cluster') let path = require('path') let fs = require('fs') let package = require('./package.json') const CFonts = require('cfonts') const Readline = require('readline') const yargs = require('yargs/yargs') const rl = Readline.createInterface(process.stdin, process.stdout)
CFonts.say('KRISBOT\nMulti-device ', { font: 'chrome', align: 'center', gradient: ['red', 'magenta'] }) CFonts.say('${package.name}' By @${package.author.name || package.author}, { font: 'console', align: 'center', gradient: ['red', 'magenta'] })
'${package.name}' By @${package.author.name || package.author}
var isRunning = false /**
path/to/file
start('main.js')
console.log('Starting...') let cluster = require('cluster') let path = require('path') let fs = require('fs') let package = require('./package.json') const CFonts = require('cfonts') const Readline = require('readline') const yargs = require('yargs/yargs') const rl = Readline.createInterface(process.stdin, process.stdout)
CFonts.say('KRISBOT\nMulti-device ', { font: 'chrome', align: 'center', gradient: ['red', 'magenta'] }) CFonts.say(
'${package.name}' By @${package.author.name || package.author}
, { font: 'console', align: 'center', gradient: ['red', 'magenta'] })var isRunning = false /**
path/to/file
*/ function start(file) { if (isRunning) return isRunning = true let args = [path.join(dirname, file), ...process.argv.slice(2)] CFonts.say([process.argv[0], ...args].join(' '), { font: 'console', align: 'center', gradient: ['red', 'magenta'] }) cluster.setupMaster({ exec: path.join(dirname, file), args: args.slice(1), }) let p = cluster.fork() p.on('message', data => { console.log('[RECEIVED]', data) switch (data) { case 'reset': p.kill() isRunning = false start.apply(this, arguments) break case 'uptime': p.send(process.uptime()) break } }) p.on('exit', code => { isRunning = false console.error('Exited with code:', code) if (code === 0) return fs.watchFile(args[0], () => { fs.unwatchFile(args[0]) start(file) }) }) let opts = new Object(yargs(process.argv.slice(2)).exitProcess(false).parse()) if (!opts['test']) if (!rl.listenerCount()) rl.on('line', line => { p.emit('message', line.trim()) }) // console.log(p) }start('main.js')