From ed7e73f8e82746c02a927ca7237467ec43a9c1ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=96=87=E5=AF=8C?= Date: Mon, 25 Mar 2019 09:35:51 +0800 Subject: [PATCH 1/8] chore: `custom` should be optional. (#2572) --- packages/taro/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/taro/types/index.d.ts b/packages/taro/types/index.d.ts index ad537f1ca4f4..774d02abdbc5 100644 --- a/packages/taro/types/index.d.ts +++ b/packages/taro/types/index.d.ts @@ -199,7 +199,7 @@ declare namespace Taro { * @default false * @since 2.1.0 */ - custom: boolean; + custom?: boolean; list: TarbarList[] } From abbe73f6653a9b3d5db6e7fa588c903bfa49ae0d Mon Sep 17 00:00:00 2001 From: jsNewbee Date: Mon, 25 Mar 2019 09:36:27 +0800 Subject: [PATCH 2/8] =?UTF-8?q?fix:=20onError=20=E5=AF=B9=E5=BA=94?= =?UTF-8?q?=E7=9A=84=E7=94=9F=E5=91=BD=E5=91=A8=E6=9C=9F=E5=BA=94=E6=98=AF?= =?UTF-8?q?=20componentDidCatchError=20(#2571)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/taroize.md | 2 +- packages/taro-cli/__tests__/__snapshots__/rn.test.js.snap | 8 ++++---- packages/taro-cli/__tests__/mocks/app.js | 6 +++--- packages/taro-cli/templates/redux/appjs | 2 -- packages/taroize/src/lifecycle.ts | 4 ++-- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/docs/taroize.md b/docs/taroize.md index c5398db27396..2ffd03582e92 100644 --- a/docs/taroize.md +++ b/docs/taroize.md @@ -137,7 +137,7 @@ Taro 会将原始文件的生命周期钩子函数转换为 Taro 的生命周期 | onHide | componentDidHide | | onReady | componentDidMount | | onUnload | componentWillUnmount | -| onError | componentCatchError | +| onError | componentDidCatchError | | App.onLaunch | componentWillMount | | Component.created | componentWillMount | | attached | componentDidMount | diff --git a/packages/taro-cli/__tests__/__snapshots__/rn.test.js.snap b/packages/taro-cli/__tests__/__snapshots__/rn.test.js.snap index 5da143b85902..e6e65cfb16c8 100644 --- a/packages/taro-cli/__tests__/__snapshots__/rn.test.js.snap +++ b/packages/taro-cli/__tests__/__snapshots__/rn.test.js.snap @@ -19,7 +19,7 @@ let App = (_temp = _class = class App extends Component { componentDidMount() {} componentDidShow() {} componentDidHide() {} - componentCatchError() {} + componentDidCatchError() {} render() { return ; } @@ -79,7 +79,7 @@ let App = (_temp = _class = class App extends Component { componentDidHide() {} - componentCatchError() {} + componentDidCatchError() {} render() { return ; @@ -161,7 +161,7 @@ let App = (_temp = _class = class App extends Component { componentDidHide() {} - componentCatchError() {} + componentDidCatchError() {} render() { return @@ -217,7 +217,7 @@ let App = (_temp = _class = class App extends Component { componentDidHide() {} - componentCatchError() {} + componentDidCatchError() {} render() { return ; diff --git a/packages/taro-cli/__tests__/mocks/app.js b/packages/taro-cli/__tests__/mocks/app.js index ce8fdd237823..3c08a22cf045 100644 --- a/packages/taro-cli/__tests__/mocks/app.js +++ b/packages/taro-cli/__tests__/mocks/app.js @@ -51,7 +51,7 @@ class App extends Component { componentDidHide () {} - componentCatchError () {} + componentDidCatchError () {} render () { return ( @@ -88,7 +88,7 @@ class App extends Component { componentDidHide () {} - componentCatchError () {} + componentDidCatchError () {} render () { return ( @@ -133,7 +133,7 @@ class App extends Component { componentDidHide () {} - componentCatchError () {} + componentDidCatchError () {} render () { return ( diff --git a/packages/taro-cli/templates/redux/appjs b/packages/taro-cli/templates/redux/appjs index a8665c9f4299..b803108ce83c 100644 --- a/packages/taro-cli/templates/redux/appjs +++ b/packages/taro-cli/templates/redux/appjs @@ -49,8 +49,6 @@ class App extends Component { componentDidHide () {} - componentCatchError () {} - componentDidCatchError () {} // 在 App 类中的 render() 函数没有实际作用 diff --git a/packages/taroize/src/lifecycle.ts b/packages/taroize/src/lifecycle.ts index 5d34f8cc6b03..808f06854fe3 100644 --- a/packages/taroize/src/lifecycle.ts +++ b/packages/taroize/src/lifecycle.ts @@ -12,7 +12,7 @@ export const enum Lifecycle { componentDidMoved = 'componentDidMoved', shouldComponentUpdate = 'shouldComponentUpdate', componentWillReceiveProps = 'componentWillReceiveProps', - componentCatchError = 'componentCatchError' + componentDidCatchError = 'componentDidCatchError' } export const PageLifecycle = new Map() @@ -22,5 +22,5 @@ PageLifecycle.set('onShow', Lifecycle.componentDidShow) PageLifecycle.set('onReady', Lifecycle.componentDidMount) PageLifecycle.set('onHide', Lifecycle.componentDidHide) PageLifecycle.set('onUnload', Lifecycle.componentWillUnmount) -PageLifecycle.set('onError', Lifecycle.componentCatchError) +PageLifecycle.set('onError', Lifecycle.componentDidCatchError) PageLifecycle.set('onLaunch', Lifecycle.componentWillMount) From c9aaf8ec4c58b22394ac0e724af571715b70a99e Mon Sep 17 00:00:00 2001 From: psaren <18718574603@163.com> Date: Mon, 25 Mar 2019 09:36:50 +0800 Subject: [PATCH 3/8] docs: update docs (#2570) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update event.md 括号包裹多行 JSX 标签 * Update spec-for-taro.md 删除句末的分号 --- docs/event.md | 18 ++++++++++-------- docs/spec-for-taro.md | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/docs/event.md b/docs/event.md index 55274754afea..d94cacf60101 100644 --- a/docs/event.md +++ b/docs/event.md @@ -93,14 +93,16 @@ class Popper extends Component { render () { const name = 'test' - return + return ( + + ) } } ``` diff --git a/docs/spec-for-taro.md b/docs/spec-for-taro.md index 23c8b5e18888..e038a79b7e99 100644 --- a/docs/spec-for-taro.md +++ b/docs/spec-for-taro.md @@ -1104,7 +1104,7 @@ render () { - ); + ) } // good From 76344f025d67f16b97e63855cf2ca049aa89622a Mon Sep 17 00:00:00 2001 From: littly <544028951@qq.com> Date: Mon, 25 Mar 2019 10:22:43 +0800 Subject: [PATCH 4/8] =?UTF-8?q?feat(cli):=20=E5=8E=BB=E9=99=A4=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E9=BB=98=E8=AE=A4=E6=A0=87=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-cli/templates/default/indexhtml | 2 +- packages/taro-cli/templates/mobx/indexhtml | 2 +- packages/taro-cli/templates/redux/indexhtml | 2 +- packages/taro-cli/templates/wxcloud/client/indexhtml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/taro-cli/templates/default/indexhtml b/packages/taro-cli/templates/default/indexhtml index 0291a9882e29..826f423513e9 100644 --- a/packages/taro-cli/templates/default/indexhtml +++ b/packages/taro-cli/templates/default/indexhtml @@ -8,7 +8,7 @@ - Taro + diff --git a/packages/taro-cli/templates/mobx/indexhtml b/packages/taro-cli/templates/mobx/indexhtml index 0291a9882e29..826f423513e9 100644 --- a/packages/taro-cli/templates/mobx/indexhtml +++ b/packages/taro-cli/templates/mobx/indexhtml @@ -8,7 +8,7 @@ - Taro + diff --git a/packages/taro-cli/templates/redux/indexhtml b/packages/taro-cli/templates/redux/indexhtml index 0291a9882e29..826f423513e9 100644 --- a/packages/taro-cli/templates/redux/indexhtml +++ b/packages/taro-cli/templates/redux/indexhtml @@ -8,7 +8,7 @@ - Taro + diff --git a/packages/taro-cli/templates/wxcloud/client/indexhtml b/packages/taro-cli/templates/wxcloud/client/indexhtml index 0291a9882e29..826f423513e9 100644 --- a/packages/taro-cli/templates/wxcloud/client/indexhtml +++ b/packages/taro-cli/templates/wxcloud/client/indexhtml @@ -8,7 +8,7 @@ - Taro + From 2cb97b9518cd68c60c78a25d538b75e28f4cc18a Mon Sep 17 00:00:00 2001 From: yuche Date: Mon, 25 Mar 2019 15:13:34 +0800 Subject: [PATCH 5/8] =?UTF-8?q?fix(transformer):=20idea=20=E7=B3=BB?= =?UTF-8?q?=E5=86=85=E7=BD=AE=E7=BB=88=E7=AB=AF=E6=9F=90=E4=BA=9B=E6=83=85?= =?UTF-8?q?=E5=86=B5=E4=BC=9A=E4=B9=B1=E7=A0=81=EF=BC=8Cclose=20#2530?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-transformer-wx/src/render.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/taro-transformer-wx/src/render.ts b/packages/taro-transformer-wx/src/render.ts index 43e79a14aaec..5833aac60b72 100644 --- a/packages/taro-transformer-wx/src/render.ts +++ b/packages/taro-transformer-wx/src/render.ts @@ -1440,8 +1440,10 @@ export class RenderParser { JSXAttribute: !t.isIdentifier(indexParam) ? noop : (path: NodePath) => { const { value } = path.node if (t.isJSXExpressionContainer(value) && t.isIdentifier(value.expression, { name: indexParam.name })) { - // tslint:disable-next-line:no-console - console.warn(codeFrameError(value.expression, '建议修改:使用循环的 index 变量作为 key 是一种反优化。参考:https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-array-index-key.md').message) + if (process.env.TERM_PROGRAM) { + // tslint:disable-next-line:no-console + console.log(codeFrameError(value.expression, '')) + } } }, JSXExpressionContainer: this.replaceIdWithTemplate(), From 443b1dc459ce960f894d96c462742b06080b014a Mon Sep 17 00:00:00 2001 From: yuche Date: Mon, 25 Mar 2019 16:19:14 +0800 Subject: [PATCH 6/8] =?UTF-8?q?fix(transformer):=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=20jsx=20=E4=B8=AD=E7=9A=84=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E5=90=8D,=20close=20#2077?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/config.md | 5 ++++- packages/taro-cli/src/weapp.js | 18 ++++++++++++------ packages/taro-transformer-wx/src/index.ts | 12 ++++++++++++ packages/taro-transformer-wx/src/options.ts | 3 ++- packages/taro-transformer-wx/src/render.ts | 4 ++-- 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/docs/config.md b/docs/config.md index e5d20a5cc105..da63b54c22d9 100644 --- a/docs/config.md +++ b/docs/config.md @@ -54,7 +54,10 @@ const config = { } } } - } + }, + // 替换 JSX 中的属性名,参考: + // https://github.com/NervJS/taro/issues/2077 + jsxAttributeNameReplace: {} }, // H5 端专用配置 h5: { diff --git a/packages/taro-cli/src/weapp.js b/packages/taro-cli/src/weapp.js index cf5b1cafe0f5..80b2f6283e6d 100644 --- a/packages/taro-cli/src/weapp.js +++ b/packages/taro-cli/src/weapp.js @@ -866,7 +866,8 @@ function isFileToBeTaroComponent (code, sourcePath, outputPath) { isNormal: true, isTyped: Util.REG_TYPESCRIPT.test(sourcePath), adapter: buildAdapter, - env: constantsReplaceList + env: constantsReplaceList, + jsxAttributeNameReplace: weappConf.jsxAttributeNameReplace }) const { ast } = transformResult let isTaroComponent = false @@ -979,7 +980,8 @@ async function compileScriptFile (content, sourceFilePath, outputFilePath, adapt isNormal: true, isTyped: false, adapter, - env: constantsReplaceList + env: constantsReplaceList, + jsxAttributeNameReplace: weappConf.jsxAttributeNameReplace }) const res = parseAst(PARSE_AST_TYPE.NORMAL, transformResult.ast, [], sourceFilePath, outputFilePath) return res.code @@ -1102,7 +1104,8 @@ async function buildEntry () { isApp: true, isTyped: Util.REG_TYPESCRIPT.test(entryFilePath), adapter: buildAdapter, - env: constantsReplaceList + env: constantsReplaceList, + jsxAttributeNameReplace: weappConf.jsxAttributeNameReplace }) // app.js的template忽略 const res = parseAst(PARSE_AST_TYPE.ENTRY, transformResult.ast, [], entryFilePath, outputEntryFilePath) @@ -1337,7 +1340,8 @@ async function buildSinglePage (page) { isRoot: true, isTyped: Util.REG_TYPESCRIPT.test(pageJs), adapter: buildAdapter, - env: constantsReplaceList + env: constantsReplaceList, + jsxAttributeNameReplace: weappConf.jsxAttributeNameReplace }) const pageDepComponents = transformResult.components const compressTemplate = useCompileConf.compressTemplate @@ -1774,7 +1778,8 @@ async function buildSingleComponent (componentObj, buildConfig = {}) { isTyped: Util.REG_TYPESCRIPT.test(component), isNormal: false, adapter: buildAdapter, - env: constantsReplaceList + env: constantsReplaceList, + jsxAttributeNameReplace: weappConf.jsxAttributeNameReplace }) const compressTemplate = useCompileConf.compressTemplate const componentWXMLContent = (isProduction && compressTemplate) ? transformResult.compressedTemplate : transformResult.template @@ -1926,7 +1931,8 @@ function compileDepScripts (scriptFiles) { isNormal: true, isTyped: Util.REG_TYPESCRIPT.test(item), adapter: buildAdapter, - env: constantsReplaceList + env: constantsReplaceList, + jsxAttributeNameReplace: weappConf.jsxAttributeNameReplace }) const ast = transformResult.ast const res = parseAst(PARSE_AST_TYPE.NORMAL, ast, [], item, outputItem) diff --git a/packages/taro-transformer-wx/src/index.ts b/packages/taro-transformer-wx/src/index.ts index 05012bb2935f..674e126b11a3 100644 --- a/packages/taro-transformer-wx/src/index.ts +++ b/packages/taro-transformer-wx/src/index.ts @@ -440,6 +440,18 @@ export default function transform (options: Options): TransformResult { }, JSXAttribute (path) { const { name, value } = path.node + + if (options.jsxAttributeNameReplace) { + for (const r in options.jsxAttributeNameReplace) { + if (options.jsxAttributeNameReplace.hasOwnProperty(r)) { + const element = options.jsxAttributeNameReplace[r] + if (t.isJSXIdentifier(name, { name: r })) { + path.node.name = t.jSXIdentifier(element) + } + } + } + } + if (!t.isJSXIdentifier(name) || value === null || t.isStringLiteral(value) || t.isJSXElement(value)) { return } diff --git a/packages/taro-transformer-wx/src/options.ts b/packages/taro-transformer-wx/src/options.ts index f8aa10c1b427..dd8ce08c43e0 100644 --- a/packages/taro-transformer-wx/src/options.ts +++ b/packages/taro-transformer-wx/src/options.ts @@ -11,7 +11,8 @@ export interface Options { isTyped: boolean, isNormal?: boolean, env?: object, - adapter?: Adapters + adapter?: Adapters, + jsxAttributeNameReplace?: Object } export const transformOptions: Options = {} as any diff --git a/packages/taro-transformer-wx/src/render.ts b/packages/taro-transformer-wx/src/render.ts index 5833aac60b72..2261a8c33ea1 100644 --- a/packages/taro-transformer-wx/src/render.ts +++ b/packages/taro-transformer-wx/src/render.ts @@ -1440,9 +1440,9 @@ export class RenderParser { JSXAttribute: !t.isIdentifier(indexParam) ? noop : (path: NodePath) => { const { value } = path.node if (t.isJSXExpressionContainer(value) && t.isIdentifier(value.expression, { name: indexParam.name })) { - if (process.env.TERM_PROGRAM) { + if (process.env.TERM_PROGRAM) { // 无法找到 cli 名称的工具(例如 idea/webstorm)显示这个报错可能会乱码 // tslint:disable-next-line:no-console - console.log(codeFrameError(value.expression, '')) + console.log(codeFrameError(value.expression, '建议修改:使用循环的 index 变量作为 key 是一种反优化。参考:https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-array-index-key.md').message) } } }, From abbe23ecb52c675d6dfadf6342b142d451fc5e92 Mon Sep 17 00:00:00 2001 From: littly <544028951@qq.com> Date: Mon, 25 Mar 2019 16:45:33 +0800 Subject: [PATCH 7/8] =?UTF-8?q?fix(webpack-runner):=20=E4=BF=AE=E5=A4=8Dh5?= =?UTF-8?q?.imageUrlLoaderOption=E5=A4=B1=E6=95=88=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-webpack-runner/src/util/chain.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/taro-webpack-runner/src/util/chain.ts b/packages/taro-webpack-runner/src/util/chain.ts index 1d791124b33c..0cc9e4294e96 100644 --- a/packages/taro-webpack-runner/src/util/chain.ts +++ b/packages/taro-webpack-runner/src/util/chain.ts @@ -375,10 +375,8 @@ const getModule = ({ test: fontReg, use: { urlLoader: getUrlLoader([defaultFontUrlLoaderOption, { - options: { - name: `${staticDirectory}/fonts/[name].[ext]`, - ...fontUrlLoaderOption - } + name: `${staticDirectory}/fonts/[name].[ext]`, + ...fontUrlLoaderOption }]) } } @@ -386,10 +384,8 @@ const getModule = ({ test: imageReg, use: { urlLoader: getUrlLoader([defaultImageUrlLoaderOption, { - options: { - name: `${staticDirectory}/images/[name].[ext]`, - ...imageUrlLoaderOption - } + name: `${staticDirectory}/images/[name].[ext]`, + ...imageUrlLoaderOption }]) } } From 35896211137dfbbd5a1ee9c0d0bb9de4dee15139 Mon Sep 17 00:00:00 2001 From: jsNewbee Date: Mon, 25 Mar 2019 19:07:35 +0800 Subject: [PATCH 8/8] =?UTF-8?q?refactor(cli):=20=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=B9=E7=BB=9F=E4=B8=80=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=20fs.ensureDirSync=20(#2576)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-cli/src/build.js | 3 +-- packages/taro-cli/src/convertor.js | 2 +- packages/taro-cli/src/util/index.js | 2 +- packages/taro-cli/templates/default/index.js | 8 ++++---- packages/taro-cli/templates/mobx/index.js | 8 ++++---- packages/taro-cli/templates/redux/index.js | 16 ++++++++-------- packages/taro-cli/templates/wxcloud/index.js | 12 ++++++------ 7 files changed, 25 insertions(+), 26 deletions(-) diff --git a/packages/taro-cli/src/build.js b/packages/taro-cli/src/build.js index f2af9fb15762..7eb377843372 100644 --- a/packages/taro-cli/src/build.js +++ b/packages/taro-cli/src/build.js @@ -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) diff --git a/packages/taro-cli/src/convertor.js b/packages/taro-cli/src/convertor.js index 258751e26ea8..ded7251c9dcf 100644 --- a/packages/taro-cli/src/convertor.js +++ b/packages/taro-cli/src/convertor.js @@ -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) } } diff --git a/packages/taro-cli/src/util/index.js b/packages/taro-cli/src/util/index.js index afd0e639b209..54b8f2dd8b13 100644 --- a/packages/taro-cli/src/util/index.js +++ b/packages/taro-cli/src/util/index.js @@ -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 } diff --git a/packages/taro-cli/templates/default/index.js b/packages/taro-cli/templates/default/index.js index 64bee0b4712d..fbd33ac6ba29 100644 --- a/packages/taro-cli/templates/default/index.js +++ b/packages/taro-cli/templates/default/index.js @@ -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, diff --git a/packages/taro-cli/templates/mobx/index.js b/packages/taro-cli/templates/mobx/index.js index 96adeeac7e3e..2ad9207491de 100644 --- a/packages/taro-cli/templates/mobx/index.js +++ b/packages/taro-cli/templates/mobx/index.js @@ -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, diff --git a/packages/taro-cli/templates/redux/index.js b/packages/taro-cli/templates/redux/index.js index 1cc64560eda8..d5e9f484e341 100644 --- a/packages/taro-cli/templates/redux/index.js +++ b/packages/taro-cli/templates/redux/index.js @@ -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, diff --git a/packages/taro-cli/templates/wxcloud/index.js b/packages/taro-cli/templates/wxcloud/index.js index 5c1f8dca7d44..a6eff62324e4 100644 --- a/packages/taro-cli/templates/wxcloud/index.js +++ b/packages/taro-cli/templates/wxcloud/index.js @@ -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,