Skip to content

Commit

Permalink
feat:enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
fusheng committed Feb 25, 2018
1 parent 9108e5f commit 8707153
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 26 deletions.
12 changes: 7 additions & 5 deletions cli/jane
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,30 @@ program
program
.command('clean')
.description('清空build目录')
.action(()=>{
rm('./build/', ()=>{ console.log('已清空')})
.action(() => {
rm('./build/', () => {
console.log('已清空')
})
})

program
.command('build')
.description('编译项目')
.action(()=>{
.action(() => {
require('./lib/build')
})

program
.command('new <project>')
.description('新建项目')
.action((project)=>{
.action((project) => {
require('./lib/create')(project)
})

program
.command('upgrade')
.description('更新')
.action(()=>{
.action(() => {
require('./lib/upgrade')
})

Expand Down
30 changes: 15 additions & 15 deletions cli/lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ let fs = require('fs')
let fse = require('fs-extra')
let path = require('path')

module.exports = async (name)=>{
try{
// copy
if (fs.existsSync(name)) {
log.error('创建失败,目录已存在')
return
}
await fse.copy(path.join(__dirname,'../tpl/project'),path.resolve(`${name}`))
log.info(`创建目录成功`)
}
catch(err){
log.error('创建目录失败')
module.exports = async (name) => {
try {
// copy
if (fs.existsSync(name)) {
log.error('创建失败,目录已存在')
return
}
// npm install
log.info(`安装依赖中...`)
cmd(`cd ${path.resolve(name)};pwd; npm install`,{stdio:[0,1,2]})
await fse.copy(path.join(__dirname, '../tpl/project'), path.resolve(`${name}`))
log.info(`创建目录成功`)
}
catch (err) {
log.error('创建目录失败')
return
}
// npm install
log.info(`安装依赖中...`)
cmd(`cd ${path.resolve(name)};pwd; npm install`, {stdio: [0, 1, 2]})

}
13 changes: 7 additions & 6 deletions cli/lib/upgrade.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
let fetch = require('node-fetch')
let localV = require('../package').version
let log = require('../utils/utils').log
let utils = require('../utils/utils')
let localV = utils.getVer()
let log = utils.log
let child_process = require('child_process');

(async function(){
(async function () {
// search on npm
let res = await fetch('https://registry.npmjs.com/@linhun%2Fjane-cli').then(res => res.json())
let onlineV = res['dist-tags'].latest
// diff
if(localV < onlineV){
if (localV < onlineV) {
log.info(`线上最新为${onlineV},升级中...`)
log.info(`请输入密码,赋予读写权限`)
child_process.execSync("sudo npm install @linhun/jane-cli -g",{stdio:[0,1,2]})
child_process.execSync("sudo npm install @linhun/jane-cli -g", {stdio: [0, 1, 2]})
}
else{
else {
log.info('已是最新版')
}
})()
Empty file modified cli/utils/utils.js
100644 → 100755
Empty file.
Empty file modified cover.jpg
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8707153

Please sign in to comment.