diff --git a/lib/Generator.js b/lib/Generator.js index 85de85e..c3f0f05 100644 --- a/lib/Generator.js +++ b/lib/Generator.js @@ -6,7 +6,7 @@ const ora = require('ora'); const chalk = require('chalk'); const Editor = require('./Editor'); -const { spawn, getPluginName } = require('./utils'); +const { spawn, getPluginName, getPackageName } = require('./utils'); class Generator extends Editor { constructor({ root, questions }) { @@ -33,6 +33,7 @@ class Generator extends Editor { const answers = { ...this.answers, pluginName: getPluginName(this.answers.projectName, this.answers.scopeName), + packageName: getPackageName(this.answers.projectName, this.answers.scopeName), }; await this.copyFiles( this.templatePath(), diff --git a/lib/index.js b/lib/index.js index 5b5c48d..f0fb67e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -47,22 +47,6 @@ module.exports = (argv) => { return true; }, }, - { - type: 'input', - name: 'packageName', - message: 'The npm package name:', - default({ projectName, scopeName }) { - if (!scopeName) return projectName; - if (scopeName === '@svrx') { - return `${scopeName}/plugin-${projectName.substr(12)}`; - } - return `${scopeName}/${projectName}`; - }, - validate(input) { - if (input) return true; - return 'Please input package name!'; - }, - }, { type: 'input', name: 'author', diff --git a/lib/utils.js b/lib/utils.js index 0110cfb..d0dc881 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -12,6 +12,13 @@ exports.getPluginName = (name, scope) => { return pluginName; }; +exports.getPackageName = (name, scope) => { + if (scope) { + return `${scope}/${name}`; + } + return name; +}; + exports.correctFullName = (name) => { if (isSvrxPlugin(name)) return paramCase(name); return `svrx-plugin-${paramCase(name)}`;