Skip to content

Commit

Permalink
feat: 新增依赖自动安装功能
Browse files Browse the repository at this point in the history
  • Loading branch information
murongg committed Dec 21, 2020
1 parent 7c2a6cb commit 85328ef
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
10 changes: 9 additions & 1 deletion lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const path_1 = require("path");
const inquirer_1 = __importDefault(require("inquirer"));
const axios_1 = __importDefault(require("axios"));
const tip_style_1 = require("./tip-style");
const shelljs_1 = __importDefault(require("shelljs"));
const prompt = [
{
type: 'input',
Expand Down Expand Up @@ -89,8 +90,15 @@ async function create(dirName) {
file_handle_1.checkFileExistsAndCreate(linConfigPath, linuiConfig, enum_1.checkFileExistsAndCreateType.FILE);
// 复制项目文件
file_handle_1.copyFolder(currentPath, rootPath);
if (!shelljs_1.default.which('npm')) {
tip_style_1.Warn(tip_style_1.warn('Sorry, this script requires npm! Please install npm!'));
shelljs_1.default.exit(1);
}
tip_style_1.Success(`${tip_style_1.success(`Waiting...`)}`);
tip_style_1.Success(`${tip_style_1.success(`Dependencies are now being installed`)}`);
shelljs_1.default.cd(dirName).exec('npm install');
tip_style_1.Success(`${tip_style_1.success(`Successfully created project ${tip_style_1.primary(name)}, directory name is ${tip_style_1.primary(dirName)}`)}`);
tip_style_1.Success(`${tip_style_1.success(`Next: Please run ${tip_style_1.primary(`cd ${dirName} && npm install or yarn`)}`)}`);
shelljs_1.default.exit(1);
}
catch (err) {
tip_style_1.Error(tip_style_1.error('create error'));
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
},
"homepage": "http://doc.mini.talelin.com",
"devDependencies": {
"@types/node": "^12.0.27"
"@types/node": "^12.0.27",
"@types/shelljs": "^0.8.8"
},
"dependencies": {
"@types/inquirer": "^7.3.0",
"axios": "^0.19.2",
"chalk": "^4.1.0",
"commander": "^6.0.0",
"consola": "^2.15.0",
"inquirer": "^7.3.3"
"inquirer": "^7.3.3",
"shelljs": "^0.8.4"
}
}
12 changes: 10 additions & 2 deletions src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { PromptInput } from './interface'
import { join } from 'path'
import inquirer from 'inquirer'
import axios from 'axios'
import { Success, Error, error, primary, success } from './tip-style'
import { Success, Error, error, primary, success, warn, Warn } from './tip-style'
import shell from 'shelljs'

const prompt = [
{
Expand Down Expand Up @@ -90,8 +91,15 @@ export default async function create(dirName: string) {
checkFileExistsAndCreate(linConfigPath, linuiConfig, checkFileExistsAndCreateType.FILE)
// 复制项目文件
copyFolder(currentPath, rootPath)
if (!shell.which('npm')) {
Warn(warn('Sorry, this script requires npm! Please install npm!'))
shell.exit(1);
}
Success(`${success(`Waiting...`)}`)
Success(`${success(`Dependencies are now being installed`)}`)
shell.cd(dirName).exec('npm install')
Success(`${success(`Successfully created project ${primary(name)}, directory name is ${primary(dirName)}`)}`)
Success(`${success(`Next: Please run ${primary(`cd ${dirName} && npm install or yarn`)}`)}`)
shell.exit(1)
} catch (err) {
Error(error('create error'))
Error(error(err))
Expand Down

0 comments on commit 85328ef

Please sign in to comment.