flamebird

Форк
0
/
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

8
const program = require('commander')
9
const emitter = require('./server/utils/emitter')
10
const { createConfig } = require('./server/config')
11
const { yellow, red, grey, cyan } = require('./server/utils/colors')
12
const processWorker = require('./server/processWorker')
13
const server = require('./server/server')
14

15
process.title = 'flamebird (nodejs task manager)'
16

17
/* special properties for colorizing output logs */
18
process.env.FORCE_COLOR = true
19
process.env.colors = true
20
process.env.color = true
21

22
process.once('SIGINT', function() {
23
  emitter.emit('killall', 'SIGINT')
24
  process.exit()
25
})
26

27
// Kill All Child Processes & Exit on SIGTERM
28
process.once('SIGTERM', function() {
29
  emitter.emit('killall', 'SIGTERM')
30
  process.exit()
31
})
32

33
program.on('--help', function() {
34
  console.log('\r\nExamples:')
35
  console.log(
36
    '  ' +
37
      grey('$') +
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
      '  ' +
41
      grey('$') +
42
      ' fb start                               ' +
43
      '- launch all commands from Procfile and output logs to this command line\r\n' +
44
      '  ' +
45
      grey('$') +
46
      ' fb web                                 ' +
47
      '- launch web GUI which have contained all possible commands from package.json etc.\r\n' +
48
      '  ' +
49
      grey('$') +
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
      '  ' +
53
      grey('$') +
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

59
program.version(getLogo(true), '-v, --version')
60
program.usage('[command] [options]')
61

62
program.option('-f, --procfile <FILE>', 'load procfile from file', 'Procfile')
63
program.option(
64
  '-e, --env <FILE>',
65
  'load environment from file, a comma-separated list',
66
  '.env'
67
)
68

69
program
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 )',
76
    false
77
  )
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 => {
91
    const config = createConfig(args)
92
    processWorker.runAll(config.commands)
93
  })
94

95
program
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 )',
102
    false
103
  )
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',
121
    false
122
  )
123
  .option(
124
    '-s, --sort-by-name',
125
    'This option using to sort all commands by name (asc)',
126
    false
127
  )
128
  .description(
129
    'Launch ' +
130
      cyan('web application') +
131
      ' which will help to manage all commands from package.json/Procfile/Grunt/Gulp'
132
  )
133
  .action(args => {
134
    const config = createConfig(args, true)
135
    if (config.main) server.start(config)
136
    else server.update(config)
137
  })
138

139
program.parse(process.argv)
140

141
if (!process.argv.slice(2).length) {
142
  console.log(getLogo())
143
  program.outputHelp()
144
}
145

146
function getLogo(displayOnlyVersion) {
147
  const { version } = require('./package.json')
148
  const strings = []
149
  if (!displayOnlyVersion) {
150
    strings.push(yellow('  ╔══╗ ╔╗   ╔══╗ ╔╗  ╔╗ ╔═══╗ ╔══╗  ╔══╗ ╔═══╗ ╔══╗ '))
151
    strings.push(
152
      red('  ║╔═╝') +
153
        yellow(' ║║   ║╔╗║ ║║  ║║ ║╔══╝ ║╔╗║  ╚╗╔╝ ║╔═╗║ ') +
154
        red('║╔╗╚╗ ')
155
    )
156
    strings.push(
157
      red('  ║╚═╗ ') +
158
        yellow('║║   ║╚╝║ ║╚╗╔╝║ ║╚══╗ ║╚╝╚╗  ║║  ║╚═╝║') +
159
        red(' ║║╚╗║ ')
160
    )
161
    strings.push(
162
      red('  ║╔═╝ ║║   ║╔╗║') +
163
        yellow(' ║╔╗╔╗║ ║╔══╝ ║╔═╗║  ') +
164
        red('║║  ║╔╗╔╝ ║║ ║║ ')
165
    )
166
    strings.push(
167
      red('  ║║   ║╚═╗ ║║║║ ') +
168
        yellow('║║╚╝║║ ║╚══╗ ║╚═╝║') +
169
        red(' ╔╝╚╗ ║║║║  ║╚═╝║ ')
170
    )
171
    strings.push(
172
      red('  ╚╝   ╚══╝ ╚╝╚╝ ╚╝  ╚╝ ') +
173
        yellow('╚═══╝') +
174
        red(' ╚═══╝ ╚══╝ ╚╝╚╝  ╚═══╝ ')
175
    )
176
    strings.push(
177
      '            ' + grey(' - wonderful nodejs task manager ') + '        '
178
    )
179
  }
180
  const v =
181
    version +
182
    new Array(version.length >= 10 ? 10 : version.length - version.length).join(
183
      ' '
184
    )
185
  const commonSpace = displayOnlyVersion ? '  ' : '                           '
186
  strings.push(commonSpace + red('╔═══════════════╗  '))
187
  strings.push(commonSpace + red('║') + yellow('    v' + v + ' ') + red('║  '))
188
  strings.push(commonSpace + red('╚═══════════════╝  ') + '\r\n')
189
  return strings.join('\r\n')
190
}
191

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.