| 30 | }; |
| 31 | |
| 32 | function build(options) { |
| 33 | const hasDebug = obj => { |
| 34 | return obj && typeof obj === 'object' && obj.debug; |
| 35 | }; |
| 36 | const isDebug = hasDebug(options); |
| 37 | if (isDebug) { |
| 38 | let ns = typeof isDebug === 'string' ? isDebug : '*'; |
| 39 | if (ns !== 'speed') ns = `brunch:${ns}`; |
| 40 | process.env.DEBUG = ns; |
| 41 | } |
| 42 | const {BrunchWatcher} = require('./watch'); |
| 43 | // We require `watch` after we assigned `process.env.DEBUG` any value. |
| 44 | // Otherwise it would be `undefined` and debug messages wouldn't be shown. |
| 45 | const watcher = new BrunchWatcher(options); |
| 46 | watcher.init(); |
| 47 | return watcher; |
| 48 | }; |
| 49 | |
| 50 | exports.new = create; |
| 51 | exports.build = options => build({path: '.', ...options, persistent: false}); |