Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cli-ant

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cli-ant - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

LICENSE

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);

3

package.json
{
"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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc