From 365323381110a757dd7f87ea09253fafbc26c6d8 Mon Sep 17 00:00:00 2001 From: ctw-ian Date: Mon, 30 Aug 2021 16:45:39 +0800 Subject: [PATCH] fix panda to ark Signed-off-by: ctw-ian --- ace-loader/npm-install.js | 36 +++++++++++++++++++++++---------- ace-loader/src/genAbc-plugin.js | 29 ++++++++++++-------------- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/ace-loader/npm-install.js b/ace-loader/npm-install.js index bceaf4e..4694763 100644 --- a/ace-loader/npm-install.js +++ b/ace-loader/npm-install.js @@ -1,32 +1,46 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + "use strict"; var path = require("path"); var fs = require("fs"); let exec = require('child_process').exec; -if ( !fs.existsSync(path.resolve(path.join(__dirname, 'bin'), "ark"))) return; - -var build_linux = path.join(__dirname, "bin", "ark", "build"); -var build_win = path.join(__dirname, "bin", "ark", "build-win"); -var build_mac = path.join(__dirname, "bin", "ark", "build-mac"); +const arkDir = path.resolve(__dirname, 'bin', "ark"); +if (!fs.existsSync(arkDir)) { + return; +} var isWin = !1; var isMac = !1; -if (fs.existsSync(path.resolve(path.join(__dirname, 'bin'), "ark/build-win"))) { +if (fs.existsSync(path.join(arkDir, "build"))) { isWin = !0; -} else if (fs.existsSync(path.resolve(path.join(__dirname, 'bin'), "ark/build-mac"))) { +} else if (fs.existsSync(path.join(arkDir, "build-win"))) { isMac = !0; -} else if (!fs.existsSync(path.resolve(path.join(__dirname, 'bin'), "ark/build"))) { +} else if (!fs.existsSync(path.join(arkDir, "build-mac"))) { throw Error("Error: find build fail").message; } let cwd; if (isWin) { - cwd = build_win + cwd = path.join(arkDir, "build-win"); } else if (isMac) { - cwd = build_mac + cwd = path.join(arkDir, "build-mac"); } else { - cwd = build_linux + cwd = path.join(arkDir, "build"); } exec("npm install", { cwd: cwd }, function (err, stdout, stderr) { diff --git a/ace-loader/src/genAbc-plugin.js b/ace-loader/src/genAbc-plugin.js index 364cc55..3fe81f3 100644 --- a/ace-loader/src/genAbc-plugin.js +++ b/ace-loader/src/genAbc-plugin.js @@ -16,12 +16,8 @@ const fs = require('fs') const path = require('path') const process = require('child_process') -const js2abc = path.join(__dirname, '..', 'bin', 'panda', 'build', 'src', 'index.js') -const js2abc_win = path.join(__dirname, '..', 'bin', 'panda', 'build-win', 'src', 'index.js') -const js2abc_mac = path.join(__dirname, '..', 'bin', 'panda', 'build-mac', 'src', 'index.js') -const libraryPath = path.join(__dirname, '..', 'bin', 'panda', 'build', 'panda', 'lib') -const libraryJsonPath = path.join(__dirname, '..', 'bin', 'panda', 'build','lib') +const arkDir = path.join(__dirname, '..', 'bin', 'ark'); const forward = '(global.___mainEntry___ = function (globalObjects) {' + '\n' + ' var define = globalObjects.define;' + '\n' + ' var require = globalObjects.require;' + '\n' + @@ -51,13 +47,13 @@ class GenAbcPlugin { isDebug = isDebug_ } apply(compiler) { - if (fs.existsSync(path.resolve(webpackPath, 'panda/build-win'))) { + if (fs.existsSync(path.resolve(webpackPath, 'ark/build-win'))) { isWin = true } else { - if (fs.existsSync(path.resolve(webpackPath, 'panda/build-mac'))) { + if (fs.existsSync(path.resolve(webpackPath, 'ark/build-mac'))) { isMac = true } else { - if (!fs.existsSync(path.resolve(webpackPath, 'panda/build'))) { + if (!fs.existsSync(path.resolve(webpackPath, 'ark/build'))) { console.error('\u001b[31m', `find build fail`, '\u001b[39m') return } @@ -85,8 +81,8 @@ function writeFileSync(inputString, output, jsBundleFile) { mkDir(parent) } fs.writeFileSync(output, inputString) - if (fs.existsSync(output)){ - qjscFirst(output) + if (fs.existsSync(output)) { + js2abcFirst(output) } else { console.error('\u001b[31m', `Failed to convert file ${jsBundleFile} to bin. ${output} is lost`, '\u001b[39m') } @@ -100,19 +96,20 @@ function mkDir(path_) { fs.mkdirSync(path_) } -function qjscFirst(inputPath) { +function js2abcFirst(inputPath) { let param = '-r' if (isDebug) { param += ' --debug' } - let cmd + + let js2abc = path.join(arkDir, 'build', 'src', 'index.js'); if (isWin) { - cmd = `node --expose-gc "${js2abc_win}" "${inputPath}" ${param}` + js2abc = path.join(arkDir, 'build-win', 'src', 'index.js'); } else if (isMac){ - cmd = `node --expose-gc "${js2abc_mac}" "${inputPath}" ${param}` - } else { - cmd = `export LD_LIBRARY_PATH="${libraryPath}":"${libraryJsonPath}":$LD_LIBRARY_PATH;node --expose-gc "${js2abc}" "${inputPath}" ${param}` + js2abc = path.join(arkDir, 'build-mac', 'src', 'index.js'); } + + const cmd = `node --expose-gc "${js2abc}" "${inputPath}" ${param}`; try { process.execSync(cmd) console.info(cmd) -- Gitee