diff --git a/BUILD.gn b/BUILD.gn index 0535ce60da5f4a838483b6f64b57ef30be3d1522..e40496cc321bdcfeadcb597c088302aa13905529 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -126,17 +126,19 @@ action("build_ets_sysResource") { ] } +ets_loader_sources = [ + "compiler/main.js", + "compiler/npm-install.js", + "compiler/package-lock.json", + "compiler/package.json", + "compiler/tsconfig.json", + "compiler/webpack.config.js", + ets_loader_component_config_file, +] + ohos_copy("ets_loader") { deps = [ ":build_ets_loader_library" ] - sources = [ - "compiler/main.js", - "compiler/npm-install.js", - "compiler/package-lock.json", - "compiler/package.json", - "compiler/tsconfig.json", - "compiler/webpack.config.js", - ets_loader_component_config_file, - ] + sources = ets_loader_sources if (!is_standard_system) { deps += [ ":build_ets_sysResource" ] sources += [ ets_sysResource ] @@ -169,3 +171,51 @@ ohos_copy("ets_loader_declaration") { module_source_dir = target_out_dir + "/$target_name" module_install_name = "" } + +ohos_copy("ets_loader_ark") { + deps = [ ":build_ets_loader_library" ] + sources = ets_loader_sources + if (!is_standard_system) { + deps += [ ":build_ets_sysResource" ] + sources += [ ets_sysResource ] + } + outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] +} + +ohos_copy("ets_loader_ark_lib") { + deps = [ + ":build_ets_loader_library", + ":ets_loader_ark", + ] + sources = [ ets_loader_lib_dir ] + outputs = [ target_out_dir + "/ets_loader_ark/lib" ] +} + +ohos_copy("ets_loader_ark_declaration") { + deps = [ + ":build_ets_loader_library", + ":ets_loader_ark", + ] + sources = [ ets_loader_declarations_dir ] + outputs = [ target_out_dir + "/ets_loader_ark/declarations" ] +} + +ohos_copy("ets_loader_ark_syntax") { + deps = [ + ":build_ets_loader_library", + ":ets_loader_ark", + ] + sources = [ ets_loader_syntax_dir ] + outputs = [ target_out_dir + "/ets_loader_ark/syntax_parser/dist" ] +} + +ohos_copy("ets_loader_node_modules") { + deps = [ + ":ets_loader_ark", + ":ets_loader_ark_declaration", + ":ets_loader_ark_lib", + ":ets_loader_ark_syntax", + ] + sources = [ "//developtools/ace-ets2bundle/compiler/node_modules" ] + outputs = [ target_out_dir + "/ets_loader_ark/node_modules" ] +} diff --git a/compiler/src/gen_abc_plugin.ts b/compiler/src/gen_abc_plugin.ts index e645bdf4f98e94d34021b6e1c253621ced469823..9725841cd007a7d92fa9295504631072d35fd4ba 100644 --- a/compiler/src/gen_abc_plugin.ts +++ b/compiler/src/gen_abc_plugin.ts @@ -20,33 +20,32 @@ import * as path from 'path'; import Compiler from 'webpack/lib/Compiler'; import { logger } from './compile_info'; -const arkDir: string = path.join(__dirname, '..', 'bin', 'ark'); - const firstFileEXT: string = '_.js'; let output: string; -let webpackPath: string; let isWin: boolean = false; let isMac: boolean = false; let isDebug: boolean = false; +let arkDir: string; +let nodeJs: string; const red: string = '\u001b[31m'; -const blue: string = '\u001b[34m'; const reset: string = '\u001b[39m'; export class GenAbcPlugin { - constructor(output_, webpackPath_, isDebug_) { + constructor(output_, arkDir_, nodeJs_, isDebug_) { output = output_; - webpackPath = webpackPath_; + arkDir = arkDir_; + nodeJs = nodeJs_; isDebug = isDebug_; } apply(compiler: Compiler) { - if (fs.existsSync(path.resolve(webpackPath, 'ark/build-win'))) { + if (fs.existsSync(path.resolve(arkDir, 'build-win'))) { isWin = true; } else { - if (fs.existsSync(path.resolve(webpackPath, 'ark/build-mac'))) { + if (fs.existsSync(path.resolve(arkDir, 'build-mac'))) { isMac = true; } else { - if (!fs.existsSync(path.resolve(webpackPath, 'ark/build'))) { + if (!fs.existsSync(path.resolve(arkDir, 'build'))) { logger.error(red, 'ETS:ERROR find build fail', reset); return; } @@ -56,7 +55,7 @@ export class GenAbcPlugin { compiler.hooks.emit.tap('GenAbcPlugin', (compilation) => { Object.keys(compilation.assets).forEach(key => { // choice *.js - if (output && webpackPath && path.extname(key) === '.js') { + if (output && path.extname(key) === '.js') { const newContent: string = compilation.assets[key].source(); const keyPath: string = key.replace(/\.js$/, firstFileEXT); writeFileSync(newContent, path.resolve(output, keyPath), key); @@ -100,9 +99,10 @@ function js2abcFirst(inputPath: string): void { js2abc = path.join(arkDir, 'build-mac', 'src', 'index.js'); } - const cmd: string = `node --expose-gc "${js2abc}" "${inputPath}" ${param}`; + const cmd: string = `${nodeJs} --expose-gc "${js2abc}" "${inputPath}" ${param}`; try { + logger.error(red, cmd, reset); process.execSync(cmd); } catch (e) { logger.error(red, `ETS:ERROR Failed to convert file ${inputPath} to abc `, reset); diff --git a/compiler/webpack.config.js b/compiler/webpack.config.js index 8e0ab7b80bd504cc5a73d3651806336551bda779..6b9367dd530a346c97b267312f84aa2afc3e2a5c 100644 --- a/compiler/webpack.config.js +++ b/compiler/webpack.config.js @@ -86,7 +86,7 @@ function initConfig(config) { global: false }, resolve: { - extensions:['.js', '.ets', '.ts'], + extensions: ['.js', '.ets', '.ts'], modules: [ projectPath, path.join(projectPath, '../../../../../'), @@ -100,11 +100,12 @@ function initConfig(config) { paths: [ /\.js$/, /\.d\.ts$/ - ]}), + ] + }), new CleanWebpackPlugin(), new ResultStates() ] - }) + }); } function setProjectConfig(envArgs) { @@ -125,14 +126,14 @@ function setProjectConfig(envArgs) { function setReleaseConfig(config) { const TerserPlugin = require('terser-webpack-plugin'); - config.mode = 'production'; - config.optimization = { - emitOnErrors: true, - usedExports: false, - minimize: true, - minimizer: [ new TerserPlugin() ] - }; - config.output.sourceMapFilename = '_releaseMap/[name].js.map'; + config.mode = 'production'; + config.optimization = { + emitOnErrors: true, + usedExports: false, + minimize: true, + minimizer: [new TerserPlugin()] + }; + config.output.sourceMapFilename = '_releaseMap/[name].js.map'; } function setCopyPluginConfig(config) { @@ -166,7 +167,16 @@ module.exports = (env, argv) => { if (env.isPreview !== "true") { loadWorker(projectConfig); if (env.compilerType && env.compilerType === 'ark') { - config.plugins.push(new GenAbcPlugin(projectConfig.buildPath, path.join(__dirname, 'bin'), env.buildMode === 'debug')); + let arkDir = path.join(__dirname, 'bin', 'ark'); + if (env.arkFrontendDir) { + arkDir = env.arkFrontendDir; + } + let nodeJs = 'node'; + if (env.nodeJs) { + nodeJs = env.nodeJs; + } + config.plugins.push(new GenAbcPlugin(projectConfig.buildPath, arkDir, nodeJs, + env.buildMode === 'debug')); } } else { projectConfig.isPreview = true;