-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbeve-cli.js
More file actions
75 lines (67 loc) · 2.06 KB
/
Copy pathbeve-cli.js
File metadata and controls
75 lines (67 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import R from 'ramda'
import fs from 'fs'
import path from 'path'
import yargs from 'yargs'
import {isLocal} from 'be-goods'
if (!isLocal('gulp', {strict: true})) {
let where = path.normalize(`${process.cwd()}/node_modules/`)
console.error('Gulp insists to be installed locally.')
console.error(`It wasn't found in ${where}.`)
console.error('Preferably a devDependency, try this:')
console.error('npm install gulp --save-dev')
process.exit(1)
}
let found = false
const gulp = [
path.normalize(process.cwd() + '/node_modules/.bin/gulp'),
path.join(path.dirname(fs.realpathSync(__filename)), '/gulp'),
path.normalize(process.cwd() + '/node_modules/beverage/node_modules/gulp/bin/gulp.js')
]
let argv = yargs
.usage('beverage [gulp-tasks]')
.option('h', {alias: ['help', '?'], type: 'boolean', description: 'show beverage help + `gulp help --silent`'})
.option('o', {alias: 'options', type: 'boolean', description: 'same as `gulp beverage --silent`'})
.argv
let tasks = argv._
let beverage = argv.o || R.contains('beverage', tasks)
let help = argv.h || R.contains('help', tasks) || R.isEmpty(tasks)
// if it's juts node + beverage (with neither task nor options given)
if (process.argv.length <= 2) {
console.log('')
console.log('Usage: beverage -?')
}
// *non-beverage-options*
// not passed on to gulp
process.argv = R.difference(process.argv,
['-o', '--options', '-?', '-h', '--help'])
if (beverage || help) {
// this is a silent gulp
process.argv.push('--silent')
// add tasks for options
if (help && !R.contains('help', tasks)) {
process.argv.splice(2, 0, 'help')
}
if (beverage && !R.contains('beverage', tasks)) {
process.argv.splice(2, 0, 'beverage')
}
}
for (let file of gulp) {
try {
require(file) // delegate to gulp
found = true
if (argv.h) {
console.log(
'\n' +
yargs.help() +
'\nRunning `gulp ' +
process.argv.slice(2).join(' ') +
'` now...'
)
}
break
} catch (e) {}
}
if (!found) {
console.error('gulp not found at:'); console.error(gulp)
process.exit(1)
}