Skip to content

Commit

Permalink
download template done
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkTangCd committed May 9, 2022
1 parent 741d456 commit b614b9d
Show file tree
Hide file tree
Showing 4 changed files with 6,839 additions and 156 deletions.
24 changes: 21 additions & 3 deletions commands/init/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
'use strict';

const fs = require('fs');
const path = require('path');
const inquirer = require('inquirer');
const fse = require('fs-extra');
const semver = require('semver');
const userHome = require('user-home');
const Command = require('@dapp-cli/command');
const Package = require('@dapp-cli/package');
const log = require('@dapp-cli/log');
const templates = require('./templates');

Expand All @@ -26,16 +29,31 @@ class InitCommand extends Command {
// 2. Download template
log.verbose('projectInfo', projectInfo);
this.projectInfo = projectInfo;
this.downloadTemplate();
await this.downloadTemplate();
// 3. Install template
}
} catch(e) {
log.error(e.message);
}
}

downloadTemplate() {
console.log(this.projectInfo);
async downloadTemplate() {
const { projectTemplate } = this.projectInfo;
const templateInfo = templates.find(item => item.npmName === projectTemplate);
const targetPath = path.resolve(userHome, '.dapp-cli-dev', 'template');
const storeDir = path.resolve(userHome, '.dapp-cli-dev', 'template', 'node_modules');
const { npmName, version } = templateInfo;
const templateNpm = new Package({
targetPath,
storeDir,
packageName: npmName,
packageVersion: version
});
if (! await templateNpm.exists()) {
await templateNpm.install();
} else {
await templateNpm.update();
}
}

async prepare() {
Expand Down
Loading

0 comments on commit b614b9d

Please sign in to comment.