From 0e32ad1e21e63d254201d2d2ec5ad4836bc0cf4f Mon Sep 17 00:00:00 2001 From: lizhouze Date: Mon, 7 Mar 2022 14:48:45 +0800 Subject: [PATCH] fixed 88bee40 from https://gitee.com/kage1/developtools_ace-js2bundle/pulls/163 lizhouze@huawei.com Signed-off-by: lizhouze --- ace-loader/src/resource-plugin.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/ace-loader/src/resource-plugin.js b/ace-loader/src/resource-plugin.js index 041ff5a..9d7ce5c 100644 --- a/ace-loader/src/resource-plugin.js +++ b/ace-loader/src/resource-plugin.js @@ -122,6 +122,7 @@ class ResourcePlugin { } addPageEntryObj(); entryObj = Object.assign(entryObj, abilityEntryObj); + checkTestRunner(input, entryObj); for (const key in entryObj) { if (!compiler.options.entry[key]) { const singleEntry = new SingleEntryPlugin('', entryObj[key], key); @@ -373,4 +374,29 @@ function setCSSEntry(cssfiles, key) { } } +function checkTestRunner(projectPath, entryObj) { + const testRunnerPath = path.join(path.parse(projectPath).dir, 'TestRunner'); + if ((!fs.existsSync(testRunnerPath)) || !fs.statSync(testRunnerPath).isDirectory()) { + return; + } + const files = []; + walkSync(testRunnerPath, files, entryObj, projectPath); +} + +function walkSync(filePath_, files, entryObj, projectPath) { + fs.readdirSync(filePath_).forEach(function (name) { + const filePath = path.join(filePath_, name); + const stat = fs.statSync(filePath); + if (stat.isFile()) { + const extName = '.js'; + if (path.extname(filePath) === extName) { + const key = filePath.replace(path.parse(projectPath).dir, '').replace(extName, ''); + entryObj[`../${key}`] = filePath; + } else if (stat.isDirectory()) { + walkSync(filePath, files, entryObj, projectPath); + } + } + }) +} + module.exports = ResourcePlugin; \ No newline at end of file