UNPKG

1.52 kBJavaScriptView Raw
1'use strict';
2require('micro-es7-shim');
3require('promise.prototype.finally').shim();
4const logger = require('loggy');
5const BrunchError = require('./utils/error');
6const 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
18const hasDebug = obj => {
19 return obj && typeof obj === 'object' && obj.debug;
20};
21
22const defaultSkeleton = 'https://github.com/brunch/dead-simple';
23exports.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
38const 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 // We require `watch` after we assigned `process.env.DEBUG` any value.
46 // Otherwise it would be `undefined` and debug messages wouldn't be shown.
47 return require('./watch')(persistent, arg2, arg3);
48};
49
50exports.build = start.bind(null, false);
51exports.watch = start.bind(null, true);