From 188a32fd5dab79410d3e819e8e260ee9b01222be Mon Sep 17 00:00:00 2001 From: lizhouze Date: Sun, 13 Mar 2022 13:30:35 +0800 Subject: [PATCH] fixed dfd8daa from https://gitee.com/kage1/developtools_ace-js2bundle/pulls/172 lizhouze@huawei.com Signed-off-by: lizhouze --- ace-loader/src/compile-plugin.js | 23 +++++++++++++------ ace-loader/src/resource-plugin.js | 38 ++++++++++++++++++++----------- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/ace-loader/src/compile-plugin.js b/ace-loader/src/compile-plugin.js index 1ca73f0..2ad8ed4 100644 --- a/ace-loader/src/compile-plugin.js +++ b/ace-loader/src/compile-plugin.js @@ -49,7 +49,8 @@ class ResultStates { apply(compiler) { const buildPath = this.options.build; - const modulePaths = new Set(); + const commonPaths = new Set(); + const i18nPaths = new Set(); compiler.hooks.compilation.tap('toFindModule', (compilation) => { compilation.hooks.buildModule.tap("findModule", (module) => { @@ -58,18 +59,26 @@ class ResultStates { const afterNodeModules = module.context.replace(beforNodeModules, '').replace('node_modules' + path.sep, ''); const src = afterNodeModules.substr(0, afterNodeModules.indexOf(path.sep)); - const modulePath = - path.resolve(beforNodeModules, 'node_modules', src, 'src', 'js', 'share'); - if (fs.existsSync(modulePath)) { - modulePaths.add(modulePath) + const commonPath = + path.resolve(beforNodeModules, 'node_modules', src, 'src', 'js', 'common'); + if (fs.existsSync(commonPath)) { + commonPaths.add(commonPath) + } + const i18nPath = + path.resolve(beforNodeModules, 'node_modules', src, 'src', 'js', 'i18n'); + if (fs.existsSync(i18nPath)) { + i18nPaths.add(i18nPath) } } }); }); compiler.hooks.afterCompile.tap('copyFindModule', () => { - for (let modulePath of modulePaths) { - circularFile(modulePath, path.resolve(buildPath, '../share')); + for (let commonPath of commonPaths) { + circularFile(commonPath, path.resolve(buildPath, '../share/common')); + } + for (let i18nPath of i18nPaths) { + circularFile(i18nPath, path.resolve(buildPath, '../share/i18n')); } }); diff --git a/ace-loader/src/resource-plugin.js b/ace-loader/src/resource-plugin.js index de513ec..5806844 100644 --- a/ace-loader/src/resource-plugin.js +++ b/ace-loader/src/resource-plugin.js @@ -67,8 +67,7 @@ function copyFile(input, output) { function circularFile(inputPath, outputPath, ext) { const realPath = path.join(inputPath, ext); - const localI18n = path.join(input, 'i18n'); - if (!fs.existsSync(realPath) || realPath === output || realPath === localI18n) { + if (!fs.existsSync(realPath) || realPath === output) { return; } fs.readdirSync(realPath).forEach(function(file_) { @@ -77,18 +76,20 @@ function circularFile(inputPath, outputPath, ext) { if (fileStat.isFile()) { const baseName = path.basename(file); const extName = path.extname(file); + const outputFile = path.join(outputPath, ext, path.basename(file_)); + if (outputFile === path.join(output, 'manifest.json')) { + return; + } if (FILE_EXT_NAME.indexOf(extName) < 0 && baseName !== '.DS_Store') { - const outputFile = path.join(outputPath, ext, path.basename(file_)); - if (outputFile === path.join(output, 'manifest.json')) { - return; - } - if (fs.existsSync(outputFile)) { - const outputFileStat = fs.statSync(outputFile); - if (outputFileStat.isFile() && fileStat.size !== outputFileStat.size) { - copyFile(file, outputFile); - } - } else { - copyFile(file, outputFile); + toCopyFile(file, outputFile, fileStat) + } else if (extName === '.json') { + const parent = path.join(file, '..'); + const parent_ = path.join(parent, '..'); + if (path.parse(parent).name === 'i18n' && path.parse(parent_).name === 'share') { + toCopyFile(file, outputFile, fileStat) + } else if (path.parse(parent).name === 'styles' && + path.parse(parent_).name === 'resources') { + toCopyFile(file, outputFile, fileStat) } } } else if (fileStat.isDirectory()) { @@ -97,6 +98,17 @@ function circularFile(inputPath, outputPath, ext) { }); } +function toCopyFile(file, outputFile, fileStat) { + if (fs.existsSync(outputFile)) { + const outputFileStat = fs.statSync(outputFile); + if (outputFileStat.isFile() && fileStat.size !== outputFileStat.size) { + copyFile(file, outputFile); + } + } else { + copyFile(file, outputFile); + } +} + class ResourcePlugin { constructor(input_, output_, manifestFilePath_, watchCSSFiles_) { input = input_; -- Gitee