1 | #! /usr/bin/env node
|
2 |
|
3 | process.title = 'bankai'
|
4 |
|
5 | require('v8-compile-cache')
|
6 |
|
7 | var ansi = require('ansi-escape-sequences')
|
8 | var minimist = require('minimist')
|
9 | var path = require('path')
|
10 |
|
11 | var USAGE = `
|
12 | $ ${clr('bankai', 'bold')} ${clr('<command> [entry]', 'green')} [options]
|
13 |
|
14 | Commands:
|
15 |
|
16 | build compile all files to ${clr('dist/', 'green')}
|
17 | inspect inspect the bundle dependencies
|
18 | start start a development server
|
19 |
|
20 | Options:
|
21 |
|
22 | -d, --debug output lots of logs
|
23 | -h, --help print usage
|
24 | -q, --quiet don't output any logs
|
25 | -v, --version print version
|
26 |
|
27 | Examples:
|
28 |
|
29 | Start a development server
|
30 | ${clr('$ bankai start index.js', 'cyan')}
|
31 |
|
32 | Visualize all dependencies in your project
|
33 | ${clr('$ bankai inspect index.js', 'cyan')}
|
34 |
|
35 | Compile all files in the project to disk
|
36 | ${clr('$ bankai build index.js', 'cyan')}
|
37 |
|
38 | For configuration usage, type 'bankai --help config'
|
39 |
|
40 | Running into trouble? Feel free to file an issue:
|
41 | ${clr('https://github.com/choojs/bankai/issues/new', 'cyan')}
|
42 |
|
43 | Do you enjoy using this software? Become a backer:
|
44 | ${clr('https://opencollective.com/choo', 'cyan')}
|
45 | `.replace(/\n$/, '').replace(/^\n/, '')
|
46 |
|
47 | var NOCOMMAND = `
|
48 | Please specify a bankai command:
|
49 | ${clr('$ bankai', 'cyan')} ${clr('<command>', 'green')}
|
50 |
|
51 | For example:
|
52 | ${clr('$ bankai start', 'cyan')} ${clr('index.js', 'green')}
|
53 |
|
54 | Run ${clr('bankai --help', 'cyan')} to see all options.
|
55 | `.replace(/\n$/, '').replace(/^\n/, '')
|
56 |
|
57 | var CONFIG_USAGE = `
|
58 |
|
59 | ${clr('Configuration', 'bold')}
|
60 |
|
61 |
|
62 | Bankai is built on top of compilers for scripts, styles and documents.
|
63 | Each of them can be configured by adding a field to your project's
|
64 | package.json file.
|
65 |
|
66 | These three fields are, respectively: ${clr('"browserify"', 'cyan')}, ${clr('"sheetify"', 'cyan')} and
|
67 | ${clr('"documentify"', 'cyan')}. Each one should have a configuration object as it's value.
|
68 |
|
69 | There is currently one possible configuration field: "transform".
|
70 |
|
71 | It can be one of either:
|
72 |
|
73 | 1. An array of transform names.
|
74 | ie: ${clr('[ "vueify" ]', 'cyan')}
|
75 | 2. An array of tuples transform name + configuration object.
|
76 | ie: ${clr('[[ "vueify", { "sass": { "includePaths": [ "src/assets/css" ] } } ]]', 'cyan')}
|
77 |
|
78 |
|
79 | Full example:
|
80 |
|
81 | ${clr(`{
|
82 | "browserify": {
|
83 | "transform": [
|
84 | [ "vueify", { "sass": { "includePaths": [ "src/assets/css" ] } } ]
|
85 | ]
|
86 | },
|
87 | "sheetify": {
|
88 | "transform": [
|
89 | "sheetify-cssnext"
|
90 | ]
|
91 | },
|
92 | "documentify": {
|
93 | "transform": [
|
94 | [ "posthtmlify", { "use": [ "posthtml-custom-elements" ] } ]
|
95 | ]
|
96 | }
|
97 | }`, 'cyan')}
|
98 | `.replace(/\n$/, '').replace(/^\n/, '')
|
99 |
|
100 | var argv = minimist(process.argv.slice(2), {
|
101 | alias: {
|
102 | help: 'h',
|
103 | quiet: 'q',
|
104 | version: 'v',
|
105 | base: 'b'
|
106 | },
|
107 | boolean: [
|
108 | 'help',
|
109 | 'quiet',
|
110 | 'version'
|
111 | ]
|
112 | })
|
113 |
|
114 | ;(function main (argv) {
|
115 | var cmd = argv._[0]
|
116 | var entry = argv._[1]
|
117 |
|
118 | if (entry) {
|
119 | if (!path.isAbsolute(entry)) entry = path.join(process.cwd(), entry)
|
120 | } else {
|
121 | entry = process.cwd()
|
122 | }
|
123 |
|
124 | if (argv.help) {
|
125 | if (cmd === 'config') return console.log(CONFIG_USAGE)
|
126 | console.log(USAGE)
|
127 | } else if (argv.version) {
|
128 | console.log(require('./package.json').version)
|
129 | } else if (cmd === 'build') {
|
130 | var outdir = argv._[2]
|
131 | require('./lib/cmd-build')(path.join(entry), outdir, argv)
|
132 | } else if (cmd === 'inspect') {
|
133 | require('./lib/cmd-inspect')(path.join(entry), argv)
|
134 | } else if (cmd === 'start') {
|
135 | require('./lib/cmd-start')(path.join(entry), argv)
|
136 | } else {
|
137 | console.log(NOCOMMAND)
|
138 | process.exit(1)
|
139 | }
|
140 | })(argv)
|
141 |
|
142 | function clr (text, color) {
|
143 | return process.stdout.isTTY ? ansi.format(text, color) : text
|
144 | }
|