Skip to content

Commit

Permalink
feat: get packageName from projectName by default
Browse files Browse the repository at this point in the history
  • Loading branch information
int64ago committed Sep 27, 2019
1 parent b8cf358 commit ddd5fb4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
3 changes: 2 additions & 1 deletion lib/Generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand All @@ -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(),
Expand Down
16 changes: 0 additions & 16 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 7 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`;
Expand Down

0 comments on commit ddd5fb4

Please sign in to comment.