-
Notifications
You must be signed in to change notification settings - Fork 102
/
bin.js
executable file
·144 lines (110 loc) · 3.63 KB
/
bin.js
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#! /usr/bin/env node
process.title = 'bankai'
require('v8-compile-cache')
var ansi = require('ansi-escape-sequences')
var minimist = require('minimist')
var path = require('path')
var USAGE = `
$ ${clr('bankai', 'bold')} ${clr('<command> [entry]', 'green')} [options]
Commands:
build compile all files to ${clr('dist/', 'green')}
inspect inspect the bundle dependencies
start start a development server
Options:
-d, --debug output lots of logs
-h, --help print usage
-q, --quiet don't output any logs
-v, --version print version
Examples:
Start a development server
${clr('$ bankai start index.js', 'cyan')}
Visualize all dependencies in your project
${clr('$ bankai inspect index.js', 'cyan')}
Compile all files in the project to disk
${clr('$ bankai build index.js', 'cyan')}
For configuration usage, type 'bankai --help config'
Running into trouble? Feel free to file an issue:
${clr('https://github.com/choojs/bankai/issues/new', 'cyan')}
Do you enjoy using this software? Become a backer:
${clr('https://opencollective.com/choo', 'cyan')}
`.replace(/\n$/, '').replace(/^\n/, '')
var NOCOMMAND = `
Please specify a bankai command:
${clr('$ bankai', 'cyan')} ${clr('<command>', 'green')}
For example:
${clr('$ bankai start', 'cyan')} ${clr('index.js', 'green')}
Run ${clr('bankai --help', 'cyan')} to see all options.
`.replace(/\n$/, '').replace(/^\n/, '')
var CONFIG_USAGE = `
${clr('Configuration', 'bold')}
Bankai is built on top of compilers for scripts, styles and documents.
Each of them can be configured by adding a field to your project's
package.json file.
These three fields are, respectively: ${clr('"browserify"', 'cyan')}, ${clr('"sheetify"', 'cyan')} and
${clr('"documentify"', 'cyan')}. Each one should have a configuration object as it's value.
There is currently one possible configuration field: "transform".
It can be one of either:
1. An array of transform names.
ie: ${clr('[ "vueify" ]', 'cyan')}
2. An array of tuples transform name + configuration object.
ie: ${clr('[[ "vueify", { "sass": { "includePaths": [ "src/assets/css" ] } } ]]', 'cyan')}
Full example:
${clr(`{
"browserify": {
"transform": [
[ "vueify", { "sass": { "includePaths": [ "src/assets/css" ] } } ]
]
},
"sheetify": {
"transform": [
"sheetify-cssnext"
]
},
"documentify": {
"transform": [
[ "posthtmlify", { "use": [ "posthtml-custom-elements" ] } ]
]
}
}`, 'cyan')}
`.replace(/\n$/, '').replace(/^\n/, '')
var argv = minimist(process.argv.slice(2), {
alias: {
help: 'h',
quiet: 'q',
version: 'v',
base: 'b'
},
boolean: [
'help',
'quiet',
'version'
]
})
;(function main (argv) {
var cmd = argv._[0]
var entry = argv._[1]
if (entry) {
if (!path.isAbsolute(entry)) entry = path.join(process.cwd(), entry)
} else {
entry = process.cwd()
}
if (argv.help) {
if (cmd === 'config') return console.log(CONFIG_USAGE)
console.log(USAGE)
} else if (argv.version) {
console.log(require('./package.json').version)
} else if (cmd === 'build') {
var outdir = argv._[2]
require('./lib/cmd-build')(path.join(entry), outdir, argv)
} else if (cmd === 'inspect') {
require('./lib/cmd-inspect')(path.join(entry), argv)
} else if (cmd === 'start') {
require('./lib/cmd-start')(path.join(entry), argv)
} else {
console.log(NOCOMMAND)
process.exit(1)
}
})(argv)
function clr (text, color) {
return process.stdout.isTTY ? ansi.format(text, color) : text
}