Comparing version 0.0.3 to 0.0.4
144
index.js
@@ -8,5 +8,96 @@ #!/usr/bin/env node | ||
const symbols = require('log-symbols'); | ||
const handlebars = require('handlebars'); | ||
const fs = require('fs'); | ||
const fse = require('fs-extra') | ||
const package = require('./package.json') | ||
const ipromptConfig = [ | ||
{ | ||
type: 'input', | ||
name: 'description', | ||
message: '请输入项目描述' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'author', | ||
message: '请输入作者名称' | ||
}, | ||
{ | ||
type: 'list', | ||
name: 'template', | ||
message: '请选择模版', | ||
choices: [ | ||
{ | ||
name: 'Vue', | ||
value: 'vue' | ||
}, | ||
// { | ||
// name: 'React', | ||
// value: 'react' | ||
// } | ||
] | ||
} | ||
] | ||
let ipromptConfigTemplate = [] | ||
let meta = {} | ||
// 下线 Template Repo | ||
const downloadRepo = (target) => { | ||
return new Promise((resolve, reject) => { | ||
download('https://github.com:xiaotiandada/cli-ant#master', target, { clone: true }, (err) => { | ||
if (err) { | ||
reject(err) | ||
} else { | ||
resolve(target) | ||
} | ||
}) | ||
}) | ||
} | ||
// 合并配置文件 | ||
const mergenPackage = (name) => { | ||
try { | ||
// console.log('meta', meta) | ||
const fileName = `./${name}/package.json`; | ||
const content = fs.readFileSync(fileName).toString(); | ||
const temp = handlebars.compile(content)(meta) | ||
fs.writeFileSync(fileName, temp); | ||
// console.log('temp', temp) | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
} | ||
// 处理文件夹 | ||
const handleFolder = async (target, temp ,name) => { | ||
try { | ||
await fse.copySync(`${target}/template/${temp}`, `./${name}`) | ||
await fse.removeSync(target) | ||
await mergenPackage(name) | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
} | ||
// 选择模版 | ||
const chooseTemplate = (name) => { | ||
inquirer | ||
.prompt(ipromptConfigTemplate) | ||
.then(async (ct) => { | ||
// console.log('ct', ct); | ||
const spinner = ora('正在下载模板...'); | ||
spinner.start(); | ||
let target = '.download-temp' | ||
try { | ||
await downloadRepo(target) | ||
await handleFolder(target, ct.template, name) | ||
spinner.succeed(); | ||
console.log(symbols.success, chalk.green('项目创建成功')); | ||
} catch (err) { | ||
spinner.fail(); | ||
console.log(symbols.error, chalk.red(`项目创建失败 ${err}`)); | ||
} | ||
}) | ||
.catch(err => console.log(err)) | ||
} | ||
program | ||
@@ -16,33 +107,38 @@ .version(package.version, '-v, --version') | ||
.action((name) => { | ||
if(fs.existsSync(name)) { | ||
if (fs.existsSync(name)) { | ||
console.log(symbols.error, chalk.red('项目已存在')); | ||
return | ||
} | ||
inquirer.prompt([ | ||
{ | ||
type: 'input', | ||
name: 'description', | ||
message: '请输入项目描述' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'author', | ||
message: '请输入作者名称' | ||
} | ||
]).then((answers) => { | ||
const spinner = ora('正在下载模板...'); | ||
spinner.start(); | ||
console.log(answers.author); | ||
console.log('name', name); | ||
download('https://github.com:eggjs/egg-init#master', name, { clone: true }, (err) => { | ||
if (err) { | ||
spinner.fail(); | ||
console.log(symbols.error, chalk.red(`项目创建失败 ${err}`)); | ||
inquirer | ||
.prompt(ipromptConfig) | ||
.then((c) => { | ||
if (c.template === 'vue') { | ||
ipromptConfigTemplate = [ | ||
{ | ||
type: 'list', | ||
name: 'template', | ||
message: '请选择模版', | ||
choices: [ | ||
{ | ||
name: 'Vue2', | ||
value: 'vue2' | ||
} | ||
] | ||
} | ||
] | ||
// write meta | ||
meta = Object.assign(meta, { | ||
name: name, | ||
description: c.description, | ||
author: c.author, | ||
}) | ||
chooseTemplate(name) | ||
} else { | ||
spinner.succeed(); | ||
console.log(symbols.success, chalk.green('项目创建成功')); | ||
return | ||
} | ||
}) | ||
}) | ||
.catch(err => console.log(err)) | ||
}); | ||
program.parse(process.argv); |
{ | ||
"name": "cli-ant", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "", | ||
@@ -18,2 +18,3 @@ "main": "index.js", | ||
"download-git-repo": "^3.0.2", | ||
"fs-extra": "^9.0.1", | ||
"handlebars": "^4.7.6", | ||
@@ -20,0 +21,0 @@ "inquirer": "^7.3.3", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
526674
40
291
1
9
8
1
3
1
+ Addedfs-extra@^9.0.1
+ Addedat-least-node@1.0.0(transitive)
+ Addedfs-extra@9.1.0(transitive)
+ Addedjsonfile@6.1.0(transitive)
+ Addeduniversalify@2.0.1(transitive)