Skip to content

Commit

Permalink
notice
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkTangCd committed May 8, 2022
1 parent 687e0d6 commit 9bbd1a4
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 11 deletions.
48 changes: 39 additions & 9 deletions commands/init/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
const fs = require('fs');
const inquirer = require('inquirer');
const fse = require('fs-extra');
const semver = require('semver');
const Command = require('@dapp-cli/command');
const log = require('@dapp-cli/log');
const templates = require('./templates');

const TYPE_PROJECT = 'project';
const TYPE_COMPONENT = 'component';
Expand All @@ -19,16 +21,23 @@ class InitCommand extends Command {

async exec() {
try {
const ret = await this.prepare();
if (ret) {
const projectInfo = await this.prepare();
if (projectInfo) {
// 2. Download template
log.verbose('projectInfo', projectInfo);
this.projectInfo = projectInfo;
this.downloadTemplate();
// 3. Install template
}
} catch(e) {
log.error(e.message);
}
}

downloadTemplate() {
console.log(this.projectInfo, templates);
}

async prepare() {
const localPath = process.cwd();
if(!this.isDirEmpty(localPath)) {
Expand Down Expand Up @@ -62,7 +71,7 @@ class InitCommand extends Command {
}

async getProjectInfo() {
const projectInfo = {};
let projectInfo = {};
const { type } = await inquirer.prompt({
type: 'list',
name: 'type',
Expand All @@ -79,13 +88,20 @@ class InitCommand extends Command {
log.verbose('type', type);

if (type === TYPE_PROJECT) {
const o = await inquirer.prompt([{
const project = await inquirer.prompt([{
type: 'input',
name: 'projectName',
message: 'Please enter the project name',
default: '',
validate: function(v) {
return typeof v === 'string';
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)) {
done('Please enter the project name in the correct format');
return;
}
done(null, true);
}, 0);
},
filter: function(v) {
return v;
Expand All @@ -94,15 +110,29 @@ class InitCommand extends Command {
type: 'input',
name: 'projectVersion',
message: 'Please enter the project version number',
default: '',
default: '1.0.0',
validate: function(v) {
return typeof v === 'string';
const done = this.async();
setTimeout(function () {
if (!(!!semver.valid(v))) {
done('Please enter the project version number in the correct format');
return;
}
done(null, true);
}, 0);
},
filter: function(v) {
return v;
if (!!semver.valid(v)) {
return semver.valid(v);
} else {
return v;
}
}
}]);
console.log(o);
projectInfo = {
type,
...project
}
} else if (type === TYPE_COMPONENT) {

}
Expand Down
16 changes: 16 additions & 0 deletions commands/init/lib/templates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = [
{
id: 1,
name: 'normal',
npmName: 'dapp-cli-template-normal',
version: '1.0.0',
disabled: false
},
{
id: 2,
name: 'NFT-Market',
npmName: 'dapp-cli-template-nft-market',
version: '0.0.0',
disabled: true
}
]
21 changes: 21 additions & 0 deletions commands/init/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion commands/init/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"@dapp-cli/command": "file:../../models/command",
"@dapp-cli/log": "file:../../utils/log",
"fs-extra": "^10.1.0",
"inquirer": "^8.2.4"
"inquirer": "^8.2.4",
"semver": "^7.3.7"
},
"bugs": {
"url": "https://github.com/MarkTangCd/dapp-cli/issues"
Expand Down
24 changes: 23 additions & 1 deletion core/cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9bbd1a4

Please sign in to comment.