mirror of
https://github.com/openharmony/developtools_ace-ets2bundle.git
synced 2026-07-20 00:54:09 -04:00
Signed-off-by: houhaoyu <houhaoyu@huawei.com> Change-Id: I85b8d52735994822082b14544e9139b8b9598579
This commit is contained in:
@@ -6,6 +6,8 @@ import("//foundation/ace/ace_engine/ace_config.gni")
|
||||
|
||||
ets_loader_lib_dir =
|
||||
get_label_info(":build_ets_loader_library", "target_out_dir") + "/lib"
|
||||
ets_loader_peg_dir =
|
||||
get_label_info(":build_ets_loader_library", "target_out_dir") + "/peg_parser/dist"
|
||||
ets_loader_declarations_dir = get_label_info(":build_ets_loader_library",
|
||||
"target_out_dir") + "/declarations"
|
||||
ets_loader_component_config_file =
|
||||
@@ -17,6 +19,7 @@ action("build_ets_loader_library") {
|
||||
depfile = "$target_gen_dir/$target_name.d"
|
||||
outputs = [
|
||||
ets_loader_lib_dir,
|
||||
ets_loader_peg_dir,
|
||||
ets_loader_declarations_dir,
|
||||
ets_loader_component_config_file,
|
||||
]
|
||||
@@ -27,12 +30,14 @@ action("build_ets_loader_library") {
|
||||
_babel_js = _ets_loader_dir + "/node_modules/@babel/cli/bin/babel.js"
|
||||
_babel_config_js = _ets_loader_dir + "/babel.config.js"
|
||||
_uglify_source_js = _ets_loader_dir + "/uglify-source.js"
|
||||
_build_peg_js = _ets_loader_dir + "/build_peg.js"
|
||||
_build_declarations_file_js = _ets_loader_dir + "/build_declarations_file.js"
|
||||
|
||||
inputs = [
|
||||
_babel_config_js,
|
||||
_babel_js,
|
||||
_uglify_source_js,
|
||||
_build_peg_js,
|
||||
_build_declarations_file_js,
|
||||
]
|
||||
|
||||
@@ -56,12 +61,18 @@ action("build_ets_loader_library") {
|
||||
rebase_path(_babel_js, root_build_dir),
|
||||
"--ets-loader-src-dir",
|
||||
rebase_path(_ets_loader_dir + "/src", root_build_dir),
|
||||
"--ets-loader-peg-src-dir",
|
||||
rebase_path(_ets_loader_dir + "/peg_parser/src", root_build_dir),
|
||||
"--babel-config-js",
|
||||
rebase_path(_babel_config_js, root_build_dir),
|
||||
"--uglify-source-js",
|
||||
rebase_path(_uglify_source_js, root_build_dir),
|
||||
"--build-peg-js",
|
||||
rebase_path(_build_peg_js, root_build_dir),
|
||||
"--output-dir",
|
||||
rebase_path(ets_loader_lib_dir, root_build_dir),
|
||||
"--output-peg-dir",
|
||||
rebase_path(ets_loader_peg_dir, root_build_dir),
|
||||
"--declarations-file-dir",
|
||||
rebase_path(_declarations_file_dir, root_build_dir),
|
||||
"--build-declarations-file-js",
|
||||
@@ -97,6 +108,14 @@ ohos_copy("ets_loader_library") {
|
||||
module_install_name = ""
|
||||
}
|
||||
|
||||
ohos_copy("ets_loader_peg") {
|
||||
deps = [ ":build_ets_loader_library" ]
|
||||
sources = [ ets_loader_peg_dir ]
|
||||
outputs = [ target_out_dir + "/$target_name" ]
|
||||
module_source_dir = target_out_dir + "/$target_name"
|
||||
module_install_name = ""
|
||||
}
|
||||
|
||||
ohos_copy("ets_loader_declaration") {
|
||||
deps = [ ":build_ets_loader_library" ]
|
||||
sources = [ ets_loader_declarations_dir ]
|
||||
|
||||
@@ -31,9 +31,12 @@ def parse_args():
|
||||
parser.add_argument('--node', help='path to nodejs exetuable')
|
||||
parser.add_argument('--babel-js', help='path to babel.js')
|
||||
parser.add_argument('--ets-loader-src-dir', help='path to compiler/src')
|
||||
parser.add_argument('--ets-loader-peg-src-dir', help='path to compiler/peg_parser/src')
|
||||
parser.add_argument('--babel-config-js', help='path babel.config.js')
|
||||
parser.add_argument('--uglify-source-js', help='path uglify-source.js')
|
||||
parser.add_argument('--build-peg-js', help='path build_peg.js')
|
||||
parser.add_argument('--output-dir', help='path to output')
|
||||
parser.add_argument('--output-peg-dir', help='path peg file to output')
|
||||
parser.add_argument('--declarations-file-dir',
|
||||
help='path declarations file')
|
||||
parser.add_argument('--build-declarations-file-js',
|
||||
@@ -47,8 +50,8 @@ def parse_args():
|
||||
return options
|
||||
|
||||
|
||||
def do_build(build_cmd, uglify_cmd, build_declarations_file_cmd):
|
||||
for cmd in [build_cmd, uglify_cmd, build_declarations_file_cmd]:
|
||||
def do_build(build_cmd, uglify_cmd, peg_cmd, build_declarations_file_cmd):
|
||||
for cmd in [build_cmd, uglify_cmd, peg_cmd, build_declarations_file_cmd]:
|
||||
build_utils.check_output(cmd)
|
||||
|
||||
|
||||
@@ -62,10 +65,14 @@ def main():
|
||||
build_cmd.extend(['--config-file', options.babel_config_js])
|
||||
depfile_deps = [options.node, options.babel_js, options.babel_config_js]
|
||||
depfile_deps.extend(build_utils.get_all_files(options.ets_loader_src_dir))
|
||||
depfile_deps.extend(build_utils.get_all_files(options.ets_loader_peg_src_dir))
|
||||
|
||||
uglify_cmd = [options.node, options.uglify_source_js, options.output_dir]
|
||||
depfile_deps.append(options.uglify_source_js)
|
||||
|
||||
peg_cmd = [options.node, options.build_peg_js, options.output_peg_dir]
|
||||
depfile_deps.append(options.build_peg_js)
|
||||
|
||||
build_declarations_file_cmd = [options.node,
|
||||
options.build_declarations_file_js,
|
||||
options.declarations_file_dir,
|
||||
@@ -74,12 +81,13 @@ def main():
|
||||
depfile_deps.append(options.build_declarations_file_js)
|
||||
|
||||
build_utils.call_and_write_depfile_if_stale(
|
||||
lambda: do_build(build_cmd, uglify_cmd, build_declarations_file_cmd),
|
||||
lambda: do_build(build_cmd, uglify_cmd, peg_cmd, build_declarations_file_cmd),
|
||||
options,
|
||||
depfile_deps=depfile_deps,
|
||||
input_paths=depfile_deps,
|
||||
output_paths=([
|
||||
options.output_dir,
|
||||
options.output_peg_dir,
|
||||
options.output_declarations_dir,
|
||||
options.output_component_config_file]))
|
||||
|
||||
|
||||
+20
-14
@@ -19,20 +19,26 @@ const exec = util.promisify(childProcess.exec);
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const readDir = fs.readdirSync('./peg_parser/src/');
|
||||
const catalog = fs.readdirSync('./peg_parser/');
|
||||
function generatePeg(inputFile) {
|
||||
const readDirPath = path.resolve(__dirname, './peg_parser/src/');
|
||||
const readDirSubFiles = fs.readdirSync(readDirPath);
|
||||
const catalogPath = path.resolve(inputFile, '..');
|
||||
const catalogSubFiles = fs.readdirSync(catalogPath)
|
||||
|
||||
if (catalogSubFiles.includes('dist')) {
|
||||
exec('rm -rf ' + catalogPath + '/dist/*.js');
|
||||
} else {
|
||||
exec('mkdir ' + catalogPath + '/dist');
|
||||
}
|
||||
|
||||
if (catalog.includes('dist')) {
|
||||
exec('rm -rf peg_parser/dist');
|
||||
(async function pegTransJs () {
|
||||
if (readDirSubFiles.length) {
|
||||
for (let item of readDirSubFiles) {
|
||||
let name = path.basename(item, '.peg');
|
||||
await exec('pegjs -o ' + catalogPath + '/dist/' + name + '.js ' + readDirPath + '/' + item);
|
||||
}
|
||||
}
|
||||
})()
|
||||
}
|
||||
|
||||
exec('mkdir peg_parser/dist');
|
||||
|
||||
(async function pegTransJs () {
|
||||
if (readDir.length) {
|
||||
for (let item of readDir) {
|
||||
let name = path.basename(item, '.peg');
|
||||
await exec('pegjs -o peg_parser/dist/' + name + '.js peg_parser/src/' + item);
|
||||
}
|
||||
}
|
||||
})()
|
||||
generatePeg(process.argv[2]);
|
||||
|
||||
@@ -10,11 +10,12 @@
|
||||
],
|
||||
"scripts": {
|
||||
"lint": "eslint --fix ./src --ext .ts",
|
||||
"build": "node build_peg.js && npm run generateDeclarations && ./node_modules/.bin/babel ./src --out-dir lib --extensions .ts",
|
||||
"build": "npm run generatePeg && npm run generateDeclarations && ./node_modules/.bin/babel ./src --out-dir lib --extensions .ts",
|
||||
"create": "node ./lib/create.js --env projectName",
|
||||
"compile": "webpack --config webpack.config.js --env buildMode=debug projectName",
|
||||
"test": "npm run build && mocha -r ts-node/register test/test.ts",
|
||||
"generateDeclarations": "node ./build_declarations_file.js ../../../interface/sdk-js/api/@internal/component/ets ./declarations ./lib",
|
||||
"generatePeg": "node build_peg.js ./peg_parser/dist",
|
||||
"postinstall": "node npm-install.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
Reference in New Issue
Block a user