From 0265013a089ce4d1741fd08b2110d3ca41708214 Mon Sep 17 00:00:00 2001 From: Morgan Laco Date: Wed, 31 Oct 2018 15:37:17 -0400 Subject: [PATCH] In validateName: detect, allow scoped package name --- src/lib/validateName.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/lib/validateName.js b/src/lib/validateName.js index 959227253..a54a88de4 100644 --- a/src/lib/validateName.js +++ b/src/lib/validateName.js @@ -5,12 +5,26 @@ const prependIgnite = require('./prependIgnite') * Checks whether a plugin name was given and errors if not. * Also prepends `ignite-*` if plugin name didn't include it. * - * @param {String} pluginName The provided plugin name. + * @param {String} rawPluginName The provided plugin name. * @param {Object} context The gluegun context. * @returns {String} The normalized name. */ -const validateName = (pluginName, context) => { +const validateName = (rawPluginName, context) => { const { strings, print } = context + const scopeRe = /^@([a-z0-9-_])\/(.*)/i + const isScopedPackage = (pluginName) => { + return scopeRe.test(pluginName) + } + + var pluginName, scopeName + + if (isScopedPackage(rawPluginName)) { + const matches = scopeRe.exec(rawPluginName) + scopeName = matches[0] + pluginName = matches[1] + } else { + pluginName = rawPluginName + } if (strings.isBlank(pluginName)) { print.info(`ignite plugin new ignite-foo\n`) @@ -25,7 +39,12 @@ const validateName = (pluginName, context) => { } // Force prepend `ignite-*` to plugin name - return prependIgnite(pluginName) + if (scopeName) { + return `${scopeName}/${prependIgnite(pluginName)}` + } else { + return prependIgnite(pluginName) + } + } module.exports = validateName