+44
-44
@@ -5,49 +5,49 @@ const co = require('co') | ||
| const chalk = require('chalk') | ||
| const fs = require("fs") | ||
| const path = require("path") | ||
| const fs = require('fs') | ||
| const path = require('path') | ||
| const exec = require('child_process').exec | ||
| const deleteFolder = function (path) { | ||
| let files = [] | ||
| if (fs.existsSync(path)) { | ||
| files = fs.readdirSync(path) | ||
| files.forEach(function (file, index) { | ||
| let curPath = path + "/" + file | ||
| if (fs.statSync(curPath).isDirectory()) { | ||
| deleteFolder(curPath) | ||
| } else { | ||
| fs.unlinkSync(curPath) | ||
| } | ||
| }) | ||
| fs.rmdirSync(path) | ||
| } | ||
| const deleteFolder = function(path) { | ||
| let files = [] | ||
| if (fs.existsSync(path)) { | ||
| files = fs.readdirSync(path) | ||
| files.forEach(function(file, index) { | ||
| let curPath = path + '/' + file | ||
| if (fs.statSync(curPath).isDirectory()) { | ||
| deleteFolder(curPath) | ||
| } else { | ||
| fs.unlinkSync(curPath) | ||
| } | ||
| }) | ||
| fs.rmdirSync(path) | ||
| } | ||
| } | ||
| module.exports = () => { | ||
| co(function *() { | ||
| let tplName = yield prompt('Template name: ') | ||
| let projectName = yield prompt('Project name: ') | ||
| let gitUrl | ||
| let branch | ||
| tplName=tplName.toLocaleLowerCase().trim() | ||
| if (!config.tpl[tplName]) { | ||
| console.log(chalk.red('\n × Template does not exit!')) | ||
| process.exit() | ||
| } | ||
| gitUrl = config.tpl[tplName].url | ||
| branch = config.tpl[tplName].branch || 'master' | ||
| const cmdStr = `git clone ${gitUrl} ${projectName} && cd ${projectName} && git checkout ${branch}` | ||
| console.log(chalk.white('\n Start generating...')) | ||
| exec(cmdStr, (error, stdout, stderr) => { | ||
| if (error) { | ||
| console.log(error) | ||
| process.exit() | ||
| } | ||
| const gitPath = path.join(process.cwd(), projectName, '.git') | ||
| deleteFolder(gitPath) | ||
| console.log(chalk.green('\n √ Generation completed!')) | ||
| console.log(chalk.green(`\n cd ${projectName}`)) | ||
| console.log(chalk.green('\n npm install or yarn')) | ||
| console.log(chalk.green('\n npm start or yarn start')) | ||
| process.exit() | ||
| }) | ||
| co(function*() { | ||
| let tplName = yield prompt('Template name: ') | ||
| let projectName = yield prompt('Project name: ') | ||
| let gitUrl | ||
| let branch | ||
| tplName = tplName.toLocaleLowerCase().trim() | ||
| if (!config.tpl[tplName]) { | ||
| console.log(chalk.red('\n × Template does not exit!')) | ||
| process.exit() | ||
| } | ||
| gitUrl = config.tpl[tplName].url | ||
| branch = config.tpl[tplName].branch || 'master' | ||
| const cmdStr = `git clone ${gitUrl} ${projectName} && cd ${projectName} && git checkout ${branch}` | ||
| console.log(chalk.white('\n Start generating...')) | ||
| exec(cmdStr, (error, stdout, stderr) => { | ||
| if (error) { | ||
| console.log(error) | ||
| process.exit() | ||
| } | ||
| const gitPath = path.join(process.cwd(), projectName, '.git') | ||
| deleteFolder(gitPath) | ||
| console.log(chalk.green('\n √ Generation completed!')) | ||
| console.log(chalk.green(`\n cd ${projectName}`)) | ||
| console.log(chalk.green('\n npm install or yarn')) | ||
| console.log(chalk.green('\n npm start or yarn start')) | ||
| process.exit() | ||
| }) | ||
| } | ||
| }) | ||
| } |
+1
-1
| { | ||
| "name": "hlj-cli", | ||
| "version": "1.3.3", | ||
| "version": "1.3.6", | ||
| "description": "A simple CLI for creating your projects", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
+4
-15
@@ -14,19 +14,8 @@  | ||
| # template Looks like : | ||
| ``` | ||
| { | ||
| "tpl": { | ||
| "react": { | ||
| "url": "https://github.com/hunliji/hlj-react-template.git", | ||
| "branch": "master" | ||
| }, | ||
| "vue":{ | ||
| "url": "https://github.com/hunliji/hlj-vue-template.git", | ||
| "branch": "master" | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
| # template name : | ||
| -- react | ||
| -- vue | ||
| -- antd | ||
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
163
0.62%4305672
-0.01%21
-34.37%