flamebird
/
flamebird.js
190 строк · 6.3 Кб
1#!/usr/bin/env node
2
3// Copyright IBM Corp. 2012,2015. All Rights Reserved.
4// Node module: flamebird
5// This file is licensed under the MIT License.
6// License text available at https://opensource.org/licenses/MIT
7
8const program = require('commander')9const emitter = require('./server/utils/emitter')10const { createConfig } = require('./server/config')11const { yellow, red, grey, cyan } = require('./server/utils/colors')12const processWorker = require('./server/processWorker')13const server = require('./server/server')14
15process.title = 'flamebird (nodejs task manager)'16
17/* special properties for colorizing output logs */
18process.env.FORCE_COLOR = true19process.env.colors = true20process.env.color = true21
22process.once('SIGINT', function() {23emitter.emit('killall', 'SIGINT')24process.exit()25})26
27// Kill All Child Processes & Exit on SIGTERM
28process.once('SIGTERM', function() {29emitter.emit('killall', 'SIGTERM')30process.exit()31})32
33program.on('--help', function() {34console.log('\r\nExamples:')35console.log(36' ' +37grey('$') +38' fb start -p -t start:dev,server:dev ' +39'- launch commands "start:dev" and "server:dev" (-t start:dev,server:dev) from package.json (-p)\r\n' +40' ' +41grey('$') +42' fb start ' +43'- launch all commands from Procfile and output logs to this command line\r\n' +44' ' +45grey('$') +46' fb web ' +47'- launch web GUI which have contained all possible commands from package.json etc.\r\n' +48' ' +49grey('$') +50' fb web -w -u yarn ' +51'- launch web GUI without opening new tab in the browser (-w) and will use another package manager (-u yarn) for launching commands from package.json\r\n' +52' ' +53grey('$') +54' fb web -i ' +55'- launch web GUI which will launch tasks without yarn or npm (using absolute paths: webpack -> node_modules/.bin/webpack) (-i)'56)57})58
59program.version(getLogo(true), '-v, --version')60program.usage('[command] [options]')61
62program.option('-f, --procfile <FILE>', 'load procfile from file', 'Procfile')63program.option(64'-e, --env <FILE>',65'load environment from file, a comma-separated list',66'.env'67)
68
69program
70.command('start')71.usage('[Options]')72.option('-p, --package', 'Use package.json for managing tasks')73.option(74'-i, --ignore-trs',75'Allows to launch tasks without yarn or npm ( using absolute paths: webpack -> node_modules/.bin/webpack )',76false77)78.option(79'-t, --tasks [tasks]',80'List of tasks which will be run flamebird ( example : --tasks start,start:dev,start-server )'81)82.option(83'-r, --task-runner <NAME>',84`Allows to use another task runner for launch tasks. By default will use npm ( For example: -r yarn )`,85'npm'86)87.description(88'Launch commands from Procfile/package.json and output logs in the current command line'89)90.action(args => {91const config = createConfig(args)92processWorker.runAll(config.commands)93})94
95program
96.command('web')97.usage('[Options]')98.option('-p, --port <PORT>', 'sets the server port', 5050)99.option(100'-i, --ignore-trs',101'Allows to launch tasks without yarn or npm ( use absolute paths: webpack -> node_modules/.bin/webpack )',102false103)104.option(105'-n, --name <NAME>',106'Sets the project name. By default takes from "package.json" else "flamebird"',107'flamebird'108)109.option(110'-t, --tasks [tasks]',111'List of tasks which will be run flamebird ( example : --tasks start,start:dev,start-server )'112)113.option(114'-r, --task-runner <NAME>',115`Allows to use another task runner for launch tasks. By default will use npm ( For example: -r yarn )`,116'npm'117)118.option(119'-w, --without-browser',120'This option disable opening the new tab in Google Chrome browser',121false122)123.option(124'-s, --sort-by-name',125'This option using to sort all commands by name (asc)',126false127)128.description(129'Launch ' +130cyan('web application') +131' which will help to manage all commands from package.json/Procfile/Grunt/Gulp'132)133.action(args => {134const config = createConfig(args, true)135if (config.main) server.start(config)136else server.update(config)137})138
139program.parse(process.argv)140
141if (!process.argv.slice(2).length) {142console.log(getLogo())143program.outputHelp()144}
145
146function getLogo(displayOnlyVersion) {147const { version } = require('./package.json')148const strings = []149if (!displayOnlyVersion) {150strings.push(yellow(' ╔══╗ ╔╗ ╔══╗ ╔╗ ╔╗ ╔═══╗ ╔══╗ ╔══╗ ╔═══╗ ╔══╗ '))151strings.push(152red(' ║╔═╝') +153yellow(' ║║ ║╔╗║ ║║ ║║ ║╔══╝ ║╔╗║ ╚╗╔╝ ║╔═╗║ ') +154red('║╔╗╚╗ ')155)156strings.push(157red(' ║╚═╗ ') +158yellow('║║ ║╚╝║ ║╚╗╔╝║ ║╚══╗ ║╚╝╚╗ ║║ ║╚═╝║') +159red(' ║║╚╗║ ')160)161strings.push(162red(' ║╔═╝ ║║ ║╔╗║') +163yellow(' ║╔╗╔╗║ ║╔══╝ ║╔═╗║ ') +164red('║║ ║╔╗╔╝ ║║ ║║ ')165)166strings.push(167red(' ║║ ║╚═╗ ║║║║ ') +168yellow('║║╚╝║║ ║╚══╗ ║╚═╝║') +169red(' ╔╝╚╗ ║║║║ ║╚═╝║ ')170)171strings.push(172red(' ╚╝ ╚══╝ ╚╝╚╝ ╚╝ ╚╝ ') +173yellow('╚═══╝') +174red(' ╚═══╝ ╚══╝ ╚╝╚╝ ╚═══╝ ')175)176strings.push(177' ' + grey(' - wonderful nodejs task manager ') + ' '178)179}180const v =181version +182new Array(version.length >= 10 ? 10 : version.length - version.length).join(183' '184)185const commonSpace = displayOnlyVersion ? ' ' : ' '186strings.push(commonSpace + red('╔═══════════════╗ '))187strings.push(commonSpace + red('║') + yellow(' v' + v + ' ') + red('║ '))188strings.push(commonSpace + red('╚═══════════════╝ ') + '\r\n')189return strings.join('\r\n')190}
191