mirror of
https://github.com/openharmony/developtools_ace-js2bundle.git
synced 2026-07-19 10:15:08 -04:00
fix conflict Signed-off-by: houhaoyu <houhaoyu@huawei.com> Change-Id: I4986b8c65edd312e005fef8e9e318e8ed44158a8
This commit is contained in:
@@ -126,9 +126,8 @@ ohos_copy("previewer_copy") {
|
||||
module_install_name = ""
|
||||
}
|
||||
|
||||
ace_loader_dir =
|
||||
ace_loader_ark_dir =
|
||||
get_label_info(":ace_loader", "target_out_dir") + "/ace_loader_ark"
|
||||
|
||||
ohos_copy("ace_loader_ark") {
|
||||
sources = ace_loader_sources
|
||||
outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ]
|
||||
@@ -142,13 +141,13 @@ ohos_copy("ace_loader_ark_hap") {
|
||||
":build_ace_loader_library",
|
||||
]
|
||||
sources = [ ace_loader_lib_dir ]
|
||||
outputs = [ ace_loader_dir + "/lib" ]
|
||||
outputs = [ ace_loader_ark_dir + "/lib" ]
|
||||
license_file = "//third_party/parse5/LICENSE"
|
||||
}
|
||||
|
||||
ohos_copy("ace_loader_node_modules") {
|
||||
deps = [ ":ace_loader_ark_hap" ]
|
||||
sources = [ "//developtools/ace-js2bundle/ace-loader/node_modules" ]
|
||||
outputs = [ ace_loader_dir + "/node_modules" ]
|
||||
outputs = [ ace_loader_ark_dir + "/node_modules" ]
|
||||
license_file = "//third_party/parse5/LICENSE"
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const process = require('child_process')
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const process = require('child_process');
|
||||
|
||||
const forward = '(global.___mainEntry___ = function (globalObjects) {' + '\n' +
|
||||
' var define = globalObjects.define;' + '\n' +
|
||||
@@ -30,52 +30,47 @@ const forward = '(global.___mainEntry___ = function (globalObjects) {' + '\n' +
|
||||
' var Image = globalObjects.Image;' + '\n' +
|
||||
' var OffscreenCanvas = globalObjects.OffscreenCanvas;' + '\n' +
|
||||
' (function(global) {' + '\n' +
|
||||
' "use strict";' + '\n'
|
||||
const last = '\n' + '})(this.__appProto__);' + '\n' + '})'
|
||||
const firstFileEXT = '_.js'
|
||||
let output
|
||||
let isWin = false
|
||||
let isMac = false
|
||||
let isDebug = false
|
||||
let arkDir
|
||||
let nodeJs
|
||||
' "use strict";' + '\n';
|
||||
const last = '\n' + '})(this.__appProto__);' + '\n' + '})';
|
||||
const firstFileEXT = '_.js';
|
||||
let output;
|
||||
let isWin = false;
|
||||
let isMac = false;
|
||||
let isDebug = false;
|
||||
let arkDir;
|
||||
let nodeJs;
|
||||
|
||||
class GenAbcPlugin {
|
||||
constructor(output_, arkDir_, nodeJs_, isDebug_) {
|
||||
output = output_
|
||||
arkDir = arkDir_
|
||||
nodeJs = nodeJs_
|
||||
isDebug = isDebug_
|
||||
output = output_;
|
||||
arkDir = arkDir_;
|
||||
nodeJs = nodeJs_;
|
||||
isDebug = isDebug_;
|
||||
}
|
||||
apply(compiler) {
|
||||
if (fs.existsSync(path.resolve(arkDir, 'build-win'))) {
|
||||
isWin = true
|
||||
} else {
|
||||
if (fs.existsSync(path.resolve(arkDir, 'build-mac'))) {
|
||||
isMac = true
|
||||
} else {
|
||||
if (!fs.existsSync(path.resolve(arkDir, 'build'))) {
|
||||
console.error('\u001b[31m', `find build fail`, '\u001b[39m')
|
||||
return
|
||||
}
|
||||
}
|
||||
isWin = true;
|
||||
} else if (fs.existsSync(path.resolve(arkDir, 'build-mac'))) {
|
||||
isMac = true;
|
||||
} else if (!fs.existsSync(path.resolve(arkDir, 'build'))) {
|
||||
return;
|
||||
}
|
||||
|
||||
compiler.hooks.emit.tap('GenAbcPlugin', (compilation) => {
|
||||
const assets = compilation.assets
|
||||
const keys = Object.keys(assets)
|
||||
const assets = compilation.assets;
|
||||
const keys = Object.keys(assets);
|
||||
keys.forEach(key => {
|
||||
// choice *.js
|
||||
if (output && path.extname(key) === '.js') {
|
||||
let newContent = assets[key].source()
|
||||
let newContent = assets[key].source();
|
||||
if (key.search('./workers/') !== 0 && key !== 'commons.js' && key !== 'vendors.js') {
|
||||
newContent = forward + newContent + last
|
||||
newContent = forward + newContent + last;
|
||||
}
|
||||
if (key === 'commons.js' || key === 'vendors.js') {
|
||||
newContent = `\n\n\n\n\n\n\n\n\n\n\n\n\n\n` + newContent
|
||||
newContent = `\n\n\n\n\n\n\n\n\n\n\n\n\n\n` + newContent;
|
||||
}
|
||||
const keyPath = key.replace(/\.js$/, firstFileEXT)
|
||||
writeFileSync(newContent, path.resolve(output, keyPath), key)
|
||||
writeFileSync(newContent, path.resolve(output, keyPath), key);
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -83,58 +78,49 @@ class GenAbcPlugin {
|
||||
}
|
||||
|
||||
function writeFileSync(inputString, output, jsBundleFile) {
|
||||
const parent = path.join(output, '..')
|
||||
if (!(fs.existsSync(parent) && fs.statSync(parent).isDirectory())) {
|
||||
mkDir(parent)
|
||||
}
|
||||
fs.writeFileSync(output, inputString)
|
||||
if (fs.existsSync(output)) {
|
||||
js2abcFirst(output)
|
||||
} else {
|
||||
console.error('\u001b[31m', `Failed to convert file ${jsBundleFile} to bin. ${output} is lost`, '\u001b[39m')
|
||||
}
|
||||
const parent = path.join(output, '..');
|
||||
if (!(fs.existsSync(parent) && fs.statSync(parent).isDirectory())) {
|
||||
mkDir(parent);
|
||||
}
|
||||
fs.writeFileSync(output, inputString);
|
||||
if (fs.existsSync(output)) {
|
||||
js2abcFirst(output);
|
||||
}
|
||||
}
|
||||
|
||||
function mkDir(path_) {
|
||||
const parent = path.join(path_, '..')
|
||||
if (!(fs.existsSync(parent) && !fs.statSync(parent).isFile())) {
|
||||
mkDir(parent)
|
||||
}
|
||||
fs.mkdirSync(path_)
|
||||
const parent = path.join(path_, '..');
|
||||
if (!(fs.existsSync(parent) && !fs.statSync(parent).isFile())) {
|
||||
mkDir(parent);
|
||||
}
|
||||
fs.mkdirSync(path_);
|
||||
}
|
||||
|
||||
function js2abcFirst(inputPath) {
|
||||
let param = '-r'
|
||||
if (isDebug) {
|
||||
param += ' --debug'
|
||||
}
|
||||
let param = '-r';
|
||||
if (isDebug) {
|
||||
param += ' --debug';
|
||||
}
|
||||
|
||||
let js2abc = path.join(arkDir, 'build', 'src', 'index.js');
|
||||
if (isWin) {
|
||||
js2abc = path.join(arkDir, 'build-win', 'src', 'index.js');
|
||||
} else if (isMac){
|
||||
js2abc = path.join(arkDir, 'build-mac', 'src', 'index.js');
|
||||
}
|
||||
let js2abc = path.join(arkDir, 'build', 'src', 'index.js');
|
||||
if (isWin) {
|
||||
js2abc = path.join(arkDir, 'build-win', 'src', 'index.js');
|
||||
} else if (isMac) {
|
||||
js2abc = path.join(arkDir, 'build-mac', 'src', 'index.js');
|
||||
}
|
||||
|
||||
const cmd = `${nodeJs} --expose-gc "${js2abc}" "${inputPath}" ${param}`;
|
||||
try {
|
||||
process.execSync(cmd)
|
||||
console.info(cmd)
|
||||
} catch (e) {
|
||||
console.error('\u001b[31m', `Failed to convert file ${inputPath} to abc`, '\u001b[39m')
|
||||
}
|
||||
if (fs.existsSync(inputPath)) {
|
||||
fs.unlinkSync(inputPath)
|
||||
} else {
|
||||
console.error('\u001b[31m', `Failed to convert file ${inputPath} to abc. ${inputPath} is lost`, '\u001b[39m')
|
||||
}
|
||||
let abcFile = inputPath.replace(/\.js$/, '.abc');
|
||||
if (fs.existsSync(abcFile)) {
|
||||
let abcFileNew = abcFile.replace(/\_.abc$/, '.abc');
|
||||
fs.renameSync(abcFile, abcFileNew)
|
||||
} else {
|
||||
console.error('\u001b[31m', `${abcFile} is lost`, '\u001b[39m')
|
||||
}
|
||||
const cmd = `${nodeJs} --expose-gc "${js2abc}" "${inputPath}" ${param}`;
|
||||
process.execSync(cmd);
|
||||
|
||||
if (fs.existsSync(inputPath)) {
|
||||
fs.unlinkSync(inputPath);
|
||||
}
|
||||
|
||||
let abcFile = inputPath.replace(/\.js$/, '.abc');
|
||||
if (fs.existsSync(abcFile)) {
|
||||
let abcFileNew = abcFile.replace(/\_.abc$/, '.abc');
|
||||
fs.renameSync(abcFile, abcFileNew);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GenAbcPlugin
|
||||
module.exports = GenAbcPlugin;
|
||||
|
||||
@@ -254,11 +254,11 @@ module.exports = (env) => {
|
||||
if (env.compilerType && env.compilerType === 'ark') {
|
||||
let arkDir = path.join(__dirname, 'bin', 'ark');
|
||||
if (env.arkFrontendDir) {
|
||||
arkDir = env.arkFrontendDir;
|
||||
arkDir = env.arkFrontendDir;
|
||||
}
|
||||
let nodeJs = 'node';
|
||||
if (env.nodeJs) {
|
||||
nodeJs = env.nodeJs
|
||||
nodeJs = env.nodeJs;
|
||||
}
|
||||
config.plugins.push(new GenAbcPlugin(process.env.buildPath, arkDir, nodeJs,
|
||||
env.buildMode === 'debug'))
|
||||
|
||||
Reference in New Issue
Block a user