Skip to content

Commit

Permalink
base version done
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkTangCd committed May 14, 2022
1 parent 806849f commit f901561
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
39 changes: 30 additions & 9 deletions commands/init/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class InitCommand extends Command {
}
} catch(e) {
log.error(e.message);
if (process.env.LOG_LEVEL === 'verbose') {
console.log(e);
}
}
}

Expand Down Expand Up @@ -92,11 +95,11 @@ class InitCommand extends Command {
Promise.all(files.map(file => {
const filePath = path.join(dir, file);
return new Promise((resolve2, reject2) => {
ejs.renderFile(filePath, {}, (err, result) => {
console.log(err, result);
ejs.renderFile(filePath, this.projectInfo, {}, (err, result) => {
if (err) {
reject2(err);
} else {
fse.writeFileSync(filePath, result);
resolve2(result);
}
});
Expand Down Expand Up @@ -127,13 +130,15 @@ class InitCommand extends Command {
log.success('Template installed successfully.');
}

const ignore = ['node_modules/**', 'public/**'];
const ignore = ['node_modules/**', 'public/**', 'packages/**'];
await this.ejsRender({ ignore });
const { installCommand, startCommand } = this.templateInfo;
// install
// await this.execCommand(installCommand);
await this.execCommand(installCommand);
// start
// await this.execCommand(installCommand);
if (startCommand && startCommand.length > 0) {
await this.execCommand(startCommand);
}
}

async downloadTemplate() {
Expand Down Expand Up @@ -221,7 +226,16 @@ class InitCommand extends Command {
}

async getProjectInfo() {
function isValidName(name) {
return /^[a-zA-Z]+([-][a-zA-Z][a-zA-Z0-9]*|[_][a-zA-Z][a-zA-Z0-9]*|[a-zA-Z0-9])*$/.test(name);
}

let projectInfo = {};
let isProjectNameValid = false;
if (isValidName(this.projectName)) {
isProjectNameValid = true;
projectInfo.projectName = this.projectName;
}
const { type } = await inquirer.prompt({
type: 'list',
name: 'type',
Expand All @@ -239,14 +253,14 @@ class InitCommand extends Command {
log.verbose('type', type);

if (type === TYPE_PROJECT) {
const project = await inquirer.prompt([{
const projectNamePrompt = {
type: 'input',
name: 'projectName',
message: 'Please enter the project name',
validate: function(v) {
const done = this.async();
setTimeout(function () {
if (!/^[a-zA-Z]+([-][a-zA-Z][a-zA-Z0-9]*|[_][a-zA-Z][a-zA-Z0-9]*|[a-zA-Z0-9])*$/.test(v)) {
if (!isValidName(v)) {
done('Please enter the project name in the correct format');
return;
}
Expand All @@ -256,7 +270,12 @@ class InitCommand extends Command {
filter: function(v) {
return v;
}
}, {
};
const projectPrompt = [];
if (!isProjectNameValid) {
projectPrompt.push(projectNamePrompt);
}
projectPrompt.push({
type: 'input',
name: 'projectVersion',
message: 'Please enter the project version number',
Expand All @@ -283,8 +302,10 @@ class InitCommand extends Command {
name: 'projectTemplate',
message: 'Please select a project template',
choices: this.createTemplateChoice()
}]);
});
const project = await inquirer.prompt(projectPrompt);
projectInfo = {
...projectInfo,
type,
...project
}
Expand Down
4 changes: 3 additions & 1 deletion models/package/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ class Package {
{ name: this.packageName, version: latestPackageVersion }
]
});
this.packageVersion = latestPackageVersion;
} else {
this.packageVersion = latestPackageVersion;
}
this.packageVersion = latestPackageVersion;
}

// get the entry file path
Expand Down

0 comments on commit f901561

Please sign in to comment.