Skip to content

Commit

Permalink
fix(cli): 增加运行提示
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Dec 31, 2019
1 parent 0760a99 commit ff7463d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/taro-cli/bin/taro
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#! /usr/bin/env node

const program = require('commander')
const { getPkgVersion, printPkgVersion } = require('../dist/util')
const { getPkgVersion, printPkgVersion, printVersionTip } = require('../dist/util')

printPkgVersion()
printVersionTip()

program
.version(getPkgVersion())
Expand Down
27 changes: 25 additions & 2 deletions packages/taro-cli/src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
processTypeEnum,
MINI_APP_FILES,
NODE_MODULES,
BUILD_TYPES
BUILD_TYPES,
TARO_CONFIG_FLODER
} from './constants'

const execSync = child_process.execSync
Expand Down Expand Up @@ -83,7 +84,7 @@ export function getRootPath (): string {
}

export function getTaroPath (): string {
const taroPath = path.join(homedir(), '.taro')
const taroPath = path.join(homedir(), TARO_CONFIG_FLODER)
if (!fs.existsSync(taroPath)) {
fs.ensureDirSync(taroPath)
}
Expand Down Expand Up @@ -578,3 +579,25 @@ export function extnameExpRegOf (filePath: string): RegExp {
export function generateAlipayPath (filePath) {
return filePath.replace(/@/g, '_')
}


interface IRemindVersion {
remindTimes: number
}
export function printVersionTip () {
const taroPath = getTaroPath()
let remindVersion: IRemindVersion = { remindTimes: 0 }
const remindVersionFilePath = path.join(taroPath, '.remind_version.json')
if (!fs.existsSync(remindVersionFilePath)) {
fs.ensureDirSync(taroPath)
fs.writeFileSync(remindVersionFilePath, JSON.stringify(remindVersion))
} else {
remindVersion = fs.readJSONSync(remindVersionFilePath)
}
if (remindVersion.remindTimes < 5) {
console.log(chalk.red('当前您正在使用 2.0 beta 版本,请先执行 taro doctor 确保编译配置正确'))
console.log(chalk.red('如出现令你束手无策的问题,请使用 taro update 命令更新到你指定的稳定版本'))
remindVersion.remindTimes++
fs.writeFileSync(remindVersionFilePath, JSON.stringify(remindVersion))
}
}

0 comments on commit ff7463d

Please sign in to comment.