Skip to content

Commit

Permalink
refactor(cli): 创建文件夹统一使用 fs.ensureDirSync (#2576)
Browse files Browse the repository at this point in the history
  • Loading branch information
js-newbee authored and luckyadam committed Mar 25, 2019
1 parent abbe23e commit 3589621
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 26 deletions.
3 changes: 1 addition & 2 deletions packages/taro-cli/src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ const CONFIG = require('./config')

const appPath = process.cwd()


function build (args, buildConfig) {
const { type, watch } = buildConfig
const configDir = require(path.join(appPath, Util.PROJECT_CONFIG))(_.merge)
const outputPath = path.join(appPath, configDir.outputRoot || CONFIG.OUTPUT_DIR)
if (!fs.existsSync(outputPath)) {
fs.mkdirSync(outputPath)
fs.ensureDirSync(outputPath)
} else {
if (type !== Util.BUILD_TYPES.H5) {
Util.emptyDirectory(outputPath)
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-cli/src/convertor.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Convertor {
if (fs.existsSync(this.convertRoot)) {
emptyDirectory(this.convertRoot, { excludes: ['node_modules'] })
} else {
fs.mkdirpSync(this.convertRoot)
fs.ensureDirSync(this.convertRoot)
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/taro-cli/src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ exports.getRootPath = function () {
exports.getTaroPath = function () {
const taroPath = path.join(exports.homedir(), '.taro')
if (!fs.existsSync(taroPath)) {
fs.mkdirSync(taroPath)
fs.ensureDirSync(taroPath)
}
return taroPath
}
Expand Down
8 changes: 4 additions & 4 deletions packages/taro-cli/templates/default/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ module.exports = function (creater, params, helper, cb) {
}
const currentStyleExt = styleExtMap[css] || 'css'

fs.mkdirSync(projectPath)
fs.mkdirSync(sourceDir)
fs.mkdirSync(configDir)
fs.mkdirSync(path.join(sourceDir, 'pages'))
fs.ensureDirSync(projectPath)
fs.ensureDirSync(sourceDir)
fs.ensureDirSync(configDir)
fs.ensureDirSync(path.join(sourceDir, 'pages'))

creater.template(template, 'pkg', path.join(projectPath, 'package.json'), {
description,
Expand Down
8 changes: 4 additions & 4 deletions packages/taro-cli/templates/mobx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ module.exports = function (creater, params, helper, cb) {
}
const currentStyleExt = styleExtMap[css] || 'css'

fs.mkdirSync(projectPath)
fs.mkdirSync(sourceDir)
fs.mkdirSync(configDir)
fs.mkdirSync(path.join(sourceDir, 'pages'))
fs.ensureDirSync(projectPath)
fs.ensureDirSync(sourceDir)
fs.ensureDirSync(configDir)
fs.ensureDirSync(path.join(sourceDir, 'pages'))

creater.template(template, 'pkg', path.join(projectPath, 'package.json'), {
description,
Expand Down
16 changes: 8 additions & 8 deletions packages/taro-cli/templates/redux/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ module.exports = function (creater, params, helper, cb) {
}
const currentStyleExt = styleExtMap[css] || 'css'

fs.mkdirSync(projectPath)
fs.mkdirSync(sourceDir)
fs.mkdirSync(configDir)
fs.mkdirSync(path.join(sourceDir, 'pages'))
fs.mkdirSync(constantsDir)
fs.mkdirSync(actionsDir)
fs.mkdirSync(reducersDir)
fs.mkdirSync(storeDir)
fs.ensureDirSync(projectPath)
fs.ensureDirSync(sourceDir)
fs.ensureDirSync(configDir)
fs.ensureDirSync(path.join(sourceDir, 'pages'))
fs.ensureDirSync(constantsDir)
fs.ensureDirSync(actionsDir)
fs.ensureDirSync(reducersDir)
fs.ensureDirSync(storeDir)

creater.template(template, 'pkg', path.join(projectPath, 'package.json'), {
description,
Expand Down
12 changes: 6 additions & 6 deletions packages/taro-cli/templates/wxcloud/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ module.exports = function (creater, params, helper, cb) {
}
const currentStyleExt = styleExtMap[css] || 'css'

fs.mkdirSync(projectPath)
fs.mkdirSync(projectClientPath)
fs.mkdirSync(projectCloudPath)
fs.mkdirSync(sourceDir)
fs.mkdirSync(configDir)
fs.mkdirSync(path.join(sourceDir, 'pages'))
fs.ensureDirSync(projectPath)
fs.ensureDirSync(projectClientPath)
fs.ensureDirSync(projectCloudPath)
fs.ensureDirSync(sourceDir)
fs.ensureDirSync(configDir)
fs.ensureDirSync(path.join(sourceDir, 'pages'))

creater.template(template, path.join(clientDirName, 'pkg'), path.join(projectClientPath, 'package.json'), {
description,
Expand Down

0 comments on commit 3589621

Please sign in to comment.