1 | 'use strict';
|
2 | require('micro-es7-shim');
|
3 | require('promise.prototype.finally').shim();
|
4 | const logger = require('loggy');
|
5 | const BrunchError = require('./utils/error');
|
6 | const checkLegacyNewSyntax = options => {
|
7 | const rawArgs = options.parent.rawArgs;
|
8 | const newArgs = rawArgs.slice(rawArgs.indexOf('new') + 1);
|
9 | const oldSyntax = !options.skeleton && newArgs.length === 2;
|
10 | if (!oldSyntax) return;
|
11 |
|
12 | throw new BrunchError('LEGACY_NEW_SYNTAX', {
|
13 | skeleton: newArgs[0],
|
14 | path: newArgs[1],
|
15 | });
|
16 | };
|
17 |
|
18 | const hasDebug = obj => {
|
19 | return obj && typeof obj === 'object' && obj.debug;
|
20 | };
|
21 |
|
22 | const defaultSkeleton = 'https://github.com/brunch/dead-simple';
|
23 | exports.new = (rootPath, options) => {
|
24 | checkLegacyNewSyntax(options);
|
25 |
|
26 | const initSkeleton = require('init-skeleton').init;
|
27 | const skeleton = options.skeleton ||
|
28 | process.env.BRUNCH_INIT_SKELETON ||
|
29 | defaultSkeleton;
|
30 |
|
31 | return initSkeleton(skeleton, {
|
32 | logger,
|
33 | rootPath,
|
34 | commandName: 'brunch new',
|
35 | });
|
36 | };
|
37 |
|
38 | const start = (persistent, arg2, arg3) => {
|
39 | const isDebug = hasDebug(arg2) || hasDebug(arg3);
|
40 | if (isDebug) {
|
41 | let ns = typeof isDebug === 'string' ? isDebug : '*';
|
42 | if (ns !== 'speed') ns = `brunch:${ns}`;
|
43 | process.env.DEBUG = ns;
|
44 | }
|
45 |
|
46 |
|
47 | return require('./watch')(persistent, arg2, arg3);
|
48 | };
|
49 |
|
50 | exports.build = start.bind(null, false);
|
51 | exports.watch = start.bind(null, true);
|