Skip to content

Commit

Permalink
fix: easy init npm package quickstart steps
Browse files Browse the repository at this point in the history
  • Loading branch information
sky committed Oct 8, 2018
1 parent ef0c810 commit 062b824
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
7 changes: 4 additions & 3 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const boilerplateChoice = [
{
name: `create ${chalk.green('NPM')} package project boilerplate`,
value: 'npm-package-code-template',
choices: ['name', 'description', 'npm']
choices: ['name', 'description', 'npm'],
run: 'npm test'
}
];

Expand Down Expand Up @@ -227,8 +228,8 @@ exports.init = options => {
} else {
const projectInfoChoice = getProjectAskChoices(choices);
inquirer.prompt(projectInfoChoice).then(projectInfoAnswer => {
const boilerplateInfo = { pkgName: boilerplateName };
download.init(projectDir, boilerplateInfo, projectInfoAnswer);
const specialBoilerplateInfo = { pkgName: boilerplateName, run: boilerplateInfo.run };
download.init(projectDir, specialBoilerplateInfo, projectInfoAnswer);
});
}
});
Expand Down
17 changes: 9 additions & 8 deletions lib/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ module.exports = class Download {
}

installDeps(projectDir, info) {
const npm = info.npm;
const { npm } = info;
if (npm) {
const cmd = `${npm} install`;
const spinner = ora(utils.log(`start ${cmd}...`));
Expand All @@ -133,22 +133,23 @@ module.exports = class Download {

quickStart(projectName, info) {
let i = 1;
const { npm, run } = info;
const steps = [`${i}) cd ${projectName}`];
if (!info.npm) {
if (!npm) {
i++;
steps.push(`${i}) npm install or yarn install`);
}
i++;
steps.push(`${i}) npm run dev`);
steps.push(`${i}) ${run || 'npm run dev' }`);

utils.log(`Now, start coding by follow step:\r\n${steps.join('\r\n')}`);
}

init(root, bilerplateInfo, projectInfoAnswer = {}, options = {}) {
const self = this;
const pkgName = bilerplateInfo.pkgName;
const sourceDir = bilerplateInfo.sourceDir || '';
const projectName = projectInfoAnswer.name || bilerplateInfo.value;
const { pkgName, sourceDir = '', run, value } = bilerplateInfo;
const { name, npm } = projectInfoAnswer;
const projectName = name || value;

co(function *() {
const absSourceDir = yield self.download(pkgName, sourceDir);
Expand All @@ -157,8 +158,8 @@ module.exports = class Download {
self.copy(absSourceDir, absTargetDir);
self.updatePackageFile(absTargetDir, projectInfoAnswer);
utils.log(`init ${projectName} project successfully!\r\n`);
self.installDeps(absTargetDir, projectInfoAnswer);
self.quickStart(projectName, projectInfoAnswer);
self.installDeps(absTargetDir, { npm });
self.quickStart(projectName, { npm, run });
}).catch(err => {
/* istanbul ignore next */
console.log('init error', err);
Expand Down

0 comments on commit 062b824

Please # to comment.