lovelope-react-cli
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -1,4 +0,4 @@ | ||
const fs = require('fs'); | ||
const fs = require('fs-extra'); | ||
const ora = require('ora'); | ||
const download = require('download-git-repo'); | ||
const git = require('isomorphic-git'); | ||
const inquirer = require('inquirer'); | ||
@@ -8,42 +8,47 @@ const chalk = require('chalk'); | ||
const pkg = require('../package.json'); | ||
const config = require('../config'); | ||
const getQuestions = require('./questions'); | ||
git.plugins.set('fs', fs); | ||
const { remote: gitRemote, branch: gitBranchs } = config.git; | ||
function assert(v) { | ||
console.dir(v); | ||
process.exit(); | ||
} | ||
module.exports = function init(program, name) { | ||
inquirer | ||
.prompt([ | ||
{ | ||
name: 'description', | ||
message: '请输入项目描述', | ||
}, | ||
{ | ||
name: 'author', | ||
message: '请输入作者名称', | ||
}, | ||
]) | ||
.prompt( | ||
// TODO: hasType 其它类型 | ||
getQuestions({ hasName: Boolean(name), hasType: program.typescript }) | ||
) | ||
.then(answers => { | ||
// 开始下载 | ||
// 项目配置 | ||
const meta = { | ||
name, | ||
projectType: program.typescript ? 'ts' : 'default', | ||
...answers, | ||
}; | ||
// git仓库分支 | ||
const branch = gitBranchs[meta.projectType]; | ||
// 开始下载动画 | ||
const spinner = ora('正在下载模板...'); | ||
spinner.start(); | ||
// 项目类型 | ||
let remoteUrl = pkg.template.default; | ||
if (program.typescript) { | ||
remoteUrl = pkg.template.typescript; | ||
} | ||
download(remoteUrl, name, { clone: true }, err => { | ||
if (err) { | ||
// 下载失败调用 | ||
spinner.fail(); | ||
console.log(symbols.error, chalk.red(err)); | ||
} else { | ||
git | ||
.clone({ | ||
url: gitRemote, // git 仓库地址 | ||
dir: name, // 目标文件夹 | ||
ref: branch, // 分支名 | ||
singleBranch: true, // 单分支克隆 | ||
depth: 1, // 浅克隆 | ||
}) | ||
.then(() => { | ||
// 下载成功调用 | ||
spinner.succeed(); | ||
const meta = { | ||
name, | ||
description: answers.description, | ||
author: answers.author, | ||
}; | ||
const fileName = `${name}/package.json`; | ||
if (fs.existsSync(fileName)) { | ||
if (fs.pathExistsSync(fileName)) { | ||
const content = fs.readFileSync(fileName).toString(); | ||
@@ -55,5 +60,9 @@ const json = JSON.parse(content); | ||
console.log(symbols.success, chalk.green('项目初始化完成')); | ||
} | ||
}); | ||
}) | ||
.catch(err => { | ||
// 下载失败调用 | ||
spinner.fail(); | ||
console.log(symbols.error, chalk.red(err)); | ||
}); | ||
}); | ||
}; |
{ | ||
"name": "lovelope-react-cli", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "A cli for react-starter.", | ||
@@ -63,3 +63,5 @@ "bin": { | ||
"download-git-repo": "^1.1.0", | ||
"fs-extra": "^7.0.1", | ||
"inquirer": "^6.2.2", | ||
"isomorphic-git": "^0.51.12", | ||
"log-symbols": "^2.2.0", | ||
@@ -69,7 +71,3 @@ "ora": "^3.2.0", | ||
"validate-npm-package-name": "^3.0.0" | ||
}, | ||
"template": { | ||
"default": "direct:https://github.com/lovelope/react-project.git#feature/antd", | ||
"typescript": "direct:https://github.com/lovelope/react-project.git#feature/ts" | ||
} | ||
} |
@@ -1,3 +0,9 @@ | ||
# [R-CLI](https://github.com/lovelope/r-cli) · [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/lovelope/r-cli/blob/master/LICENSE) [![npm version](https://img.shields.io/npm/v/lovelope-react-cli.svg?style=flat)](https://www.npmjs.com/package/lovelope-react-cli) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/lovelope/r-cli/pulls) | ||
# [Lovelope React Cli](https://github.com/lovelope/r-cli) | ||
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/lovelope/r-cli/blob/master/LICENSE) | ||
[![npm version](https://img.shields.io/npm/v/lovelope-react-cli.svg?style=flat)](https://www.npmjs.com/package/lovelope-react-cli) | ||
[![downloads per month](https://img.shields.io/npm/dm/lovelope-react-cli.svg)](https://www.npmjs.org/package/lovelope-react-cli) | ||
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-airbnb-brightgreen.svg)](https://github.com/airbnb/javascript) | ||
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/lovelope/r-cli/pulls) | ||
A cli for react-starter. | ||
@@ -4,0 +10,0 @@ |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
8542
11
163
32
10
+ Addedfs-extra@^7.0.1
+ Addedisomorphic-git@^0.51.12
+ Addedasync-lock@1.4.1(transitive)
+ Addedbase64-js@0.0.2(transitive)
+ Addedbenchmark@1.0.0(transitive)
+ Addedbops@0.0.7(transitive)
+ Addedclean-git-ref@1.0.3(transitive)
+ Addedcrc-32@1.2.2(transitive)
+ Addeddecompress-response@4.2.1(transitive)
+ Addeddiff@3.5.0(transitive)
+ Addeddiff-lines@1.1.1(transitive)
+ Addedfs-extra@7.0.1(transitive)
+ Addedgit-apply-delta@0.0.7(transitive)
+ Addedglobalyzer@0.1.4(transitive)
+ Addedglobrex@0.1.2(transitive)
+ Addedignore@5.3.1(transitive)
+ Addedisomorphic-git@0.51.13(transitive)
+ Addedjsonfile@4.0.0(transitive)
+ Addedmarky@1.2.5(transitive)
+ Addedmimic-response@2.1.0(transitive)
+ Addedminimisted@2.0.1(transitive)
+ Addednick@0.1.3(transitive)
+ Addedpako@1.0.11(transitive)
+ Addedpify@4.0.1(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedsha.js@2.4.11(transitive)
+ Addedsimple-concat@1.0.1(transitive)
+ Addedsimple-get@3.1.1(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedto-utf8@0.0.1(transitive)
+ Addeduniversalify@0.1.2(transitive)
+ Addedvarint@0.0.3(transitive)