diff --git a/.eslintrc.json b/.eslintrc.json index cf2fa4838..6a2f0f146 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -135,6 +135,7 @@ "constructor-super": 2, "generator-star-spacing": [2, "after"], "no-class-assign": 2, + "no-const-assign": 2, "no-dupe-class-members": 2, "no-new-symbol": 2, "no-this-before-super": 2, diff --git a/lib/index.js b/lib/index.js index a2424afb0..c881e8bbe 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,17 +1,17 @@ 'use strict'; require('micro-es7-shim'); const logger = require('loggy'); -const isOldBrunchNewSyntax = options => { +const BrunchError = require('./utils/error'); +const checkLegacyNewSyntax = options => { const rawArgs = options.parent.rawArgs; - const newIdx = rawArgs.indexOf('new'); - const opts = rawArgs.slice(newIdx + 1); - const oldSyntax = !options.skeleton && opts.length === 2; - if (!oldSyntax) return false; + const newArgs = rawArgs.slice(rawArgs.indexOf('new') + 1); + const oldSyntax = !options.skeleton && newArgs.length === 2; + if (!oldSyntax) return; - const skeleton = opts[0]; - const path = opts[1]; - logger.error(`The 'brunch new ${skeleton} ${path}' syntax is no longer supported. Use 'brunch new ${path} -s ${skeleton}'`); - return true; + throw new BrunchError('LEGACY_NEW_SYNTAX', { + skeleton: newArgs[0], + path: newArgs[1], + }); }; const hasDebug = obj => { @@ -20,11 +20,13 @@ const hasDebug = obj => { exports.defaultSkeleton = 'https://github.com/brunch/dead-simple'; exports.new = (rootPath, options) => { - if (isOldBrunchNewSyntax(options)) process.exit(1); + checkLegacyNewSyntax(options); const initSkeleton = require('init-skeleton').init; const skeleton = options.skeleton || - process.env.BRUNCH_INIT_SKELETON || exports.defaultSkeleton; + process.env.BRUNCH_INIT_SKELETON || + exports.defaultSkeleton; + return initSkeleton(skeleton, { logger, rootPath, diff --git a/lib/utils/messages.json b/lib/utils/messages.json index 47a60dcbe..ef8b4b883 100644 --- a/lib/utils/messages.json +++ b/lib/utils/messages.json @@ -18,5 +18,6 @@ "CONVENTION_INVALID": "#{convention} in invalid convention.", "FILE_DATA_INVALID": "File #{path} data is invalid.", "REMOVE_GET_DEPS": "Compiler '#{name}' already passes dependencies. Remove 'getDependencies' method.", - "READ_FAILED": "Failed to read file #{path}." + "READ_FAILED": "Failed to read file #{path}.", + "LEGACY_NEW_SYNTAX": "The 'brunch new #{skeleton} #{path}' syntax is no longer supported. Use 'brunch new #{path} -s #{skeleton}'." } diff --git a/lib/utils/plugin-adapter.js b/lib/utils/plugin-adapter.js index cb6922bba..5df44105e 100644 --- a/lib/utils/plugin-adapter.js +++ b/lib/utils/plugin-adapter.js @@ -8,7 +8,7 @@ const methods = [ 'optimize', ]; -const extToRe = ext => { +const extToRegExp = ext => { if (!ext) return; const escaped = `.${ext}$`.replace(/\./g, '\\.'); return new RegExp(escaped, 'i'); @@ -37,7 +37,7 @@ const safeWrapInFile = (plugin, key) => { }; const promisifyMethod = (plugin, key) => { - const fn = plugin[key]; + let fn = plugin[key]; if (typeof fn !== 'function') return; if (fn.length === 1) return; @@ -80,12 +80,12 @@ module.exports = plugin => { }); plugin.pattern = plugin.pattern || - extToRe(plugin.extension) || + extToRegExp(plugin.extension) || /.^/; // never matches if (plugin.compileStatic) { plugin.staticPattern = plugin.staticPattern || - extToRe(plugin.staticExtension) || + extToRegExp(plugin.staticExtension) || plugin.pattern; }