mirror of
https://gitee.com/openharmony/third_party_weex-loader
synced 2024-11-26 17:10:58 +00:00
Signed-off-by: houhaoyu <houhaoyu@huawei.com> Change-Id: I46d78210b5d5d41801718d77842fa9c9164cac25
This commit is contained in:
parent
6ebc80ef6e
commit
9d66841530
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
node_modules
|
87
BUILD.gn
Normal file
87
BUILD.gn
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
# Copyright (c) 2023 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.
|
||||||
|
|
||||||
|
import("//build/ohos.gni")
|
||||||
|
import("//build/ohos/ace/ace.gni")
|
||||||
|
import("//foundation/arkui/ace_engine/ace_config.gni")
|
||||||
|
|
||||||
|
weex_loader_lib_dir =
|
||||||
|
get_label_info(":build_weex_loader_library", "target_out_dir") + "/lib"
|
||||||
|
|
||||||
|
weex_loader_files_set = [
|
||||||
|
weex_loader_lib_dir + "/element.js",
|
||||||
|
weex_loader_lib_dir + "/json.js",
|
||||||
|
weex_loader_lib_dir + "/legacy.js",
|
||||||
|
weex_loader_lib_dir + "/loader.js",
|
||||||
|
weex_loader_lib_dir + "/parser.js",
|
||||||
|
weex_loader_lib_dir + "/script.js",
|
||||||
|
weex_loader_lib_dir + "/style.js",
|
||||||
|
weex_loader_lib_dir + "/template.js",
|
||||||
|
weex_loader_lib_dir + "/util.js",
|
||||||
|
]
|
||||||
|
|
||||||
|
action("build_weex_loader_library") {
|
||||||
|
script = "build_weex_loader_library.py"
|
||||||
|
depfile = "$target_gen_dir/$target_name.d"
|
||||||
|
outputs = weex_loader_files_set
|
||||||
|
|
||||||
|
_babel_js = "//third_party/weex-loader/node_modules/@babel/cli/bin/babel.js"
|
||||||
|
_babel_config_js = "//third_party/weex-loader/babel.config.js"
|
||||||
|
_uglify_source_js = "//third_party/weex-loader/uglify-source.js"
|
||||||
|
|
||||||
|
inputs = [
|
||||||
|
_babel_config_js,
|
||||||
|
_babel_js,
|
||||||
|
_uglify_source_js,
|
||||||
|
]
|
||||||
|
|
||||||
|
nodejs_path = "//prebuilts/build-tools/common/nodejs/current/bin/node"
|
||||||
|
|
||||||
|
args = [
|
||||||
|
"--depfile",
|
||||||
|
rebase_path(depfile, root_build_dir),
|
||||||
|
"--node",
|
||||||
|
rebase_path(nodejs_path, root_build_dir),
|
||||||
|
"--babel-js",
|
||||||
|
rebase_path(_babel_js, root_build_dir),
|
||||||
|
"--weex-loader-src-dir",
|
||||||
|
rebase_path("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),
|
||||||
|
"--output-dir",
|
||||||
|
rebase_path(weex_loader_lib_dir, root_build_dir),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
ohos_copy("weex_loader") {
|
||||||
|
deps = [ ":build_weex_loader_library" ]
|
||||||
|
sources = weex_loader_files_set
|
||||||
|
outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ]
|
||||||
|
module_source_dir = target_out_dir + "/$target_name/"
|
||||||
|
module_install_name = ""
|
||||||
|
license_file = "//third_party/weex-loader/LICENSE"
|
||||||
|
}
|
||||||
|
|
||||||
|
ace_loader_ark_dir = get_label_info("//developtools/ace_js2bundle:ace_loader",
|
||||||
|
"target_out_dir") + "/ace_loader_ark"
|
||||||
|
|
||||||
|
ohos_copy("weex_loader_ark_hap") {
|
||||||
|
deps = [
|
||||||
|
":build_weex_loader_library",
|
||||||
|
":weex_loader",
|
||||||
|
]
|
||||||
|
sources = weex_loader_files_set
|
||||||
|
outputs = [ ace_loader_ark_dir + "/lib/{{source_file_part}}" ]
|
||||||
|
}
|
43
babel.config.js
Normal file
43
babel.config.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = function(api) {
|
||||||
|
api.cache(true);
|
||||||
|
|
||||||
|
const presets = ['@babel/preset-env'];
|
||||||
|
const plugins = [
|
||||||
|
[
|
||||||
|
'@babel/plugin-transform-modules-commonjs',
|
||||||
|
{'allowTopLevelThis': true}
|
||||||
|
],
|
||||||
|
'@babel/plugin-proposal-class-properties',
|
||||||
|
'@babel/plugin-transform-runtime'
|
||||||
|
];
|
||||||
|
if (process.env.DEVICE_LEVEL === 'lite') {
|
||||||
|
const liteArray = [
|
||||||
|
[
|
||||||
|
'@babel/plugin-transform-arrow-functions',
|
||||||
|
{spec: true},
|
||||||
|
]
|
||||||
|
]
|
||||||
|
plugins.push(...liteArray);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
presets,
|
||||||
|
plugins,
|
||||||
|
comments: false
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
78
build_weex_loader_library.py
Executable file
78
build_weex_loader_library.py
Executable file
@ -0,0 +1,78 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2023 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.
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import subprocess
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
standard_system_build_dir = os.path.join(os.path.dirname(__file__), os.pardir,
|
||||||
|
os.pardir, 'build', 'scripts', 'util')
|
||||||
|
build_dir = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir,
|
||||||
|
os.pardir, os.pardir, os.pardir, 'build', 'maple', 'java', 'util')
|
||||||
|
if os.path.exists(standard_system_build_dir):
|
||||||
|
sys.path.append(
|
||||||
|
os.path.join(standard_system_build_dir, os.pardir, os.pardir))
|
||||||
|
from scripts.util import build_utils # noqa: E402
|
||||||
|
if os.path.exists(build_dir):
|
||||||
|
sys.path.append(os.path.join(build_dir, os.pardir, os.pardir, os.pardir))
|
||||||
|
from maple.java.util import build_utils # noqa: E402
|
||||||
|
|
||||||
|
|
||||||
|
def parse_args():
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
build_utils.add_depfile_option(parser)
|
||||||
|
|
||||||
|
parser.add_argument('--node', help='path to nodejs exetuable')
|
||||||
|
parser.add_argument('--babel-js', help='path to babel.js')
|
||||||
|
parser.add_argument("--weex-loader-src-dir",
|
||||||
|
help='path to weex-loader/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('--output-dir', help='path to output')
|
||||||
|
|
||||||
|
options = parser.parse_args()
|
||||||
|
return options
|
||||||
|
|
||||||
|
|
||||||
|
def do_build(build_cmd, uglify_cmd):
|
||||||
|
for cmd in [build_cmd, uglify_cmd]:
|
||||||
|
build_utils.check_output(cmd)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
options = parse_args()
|
||||||
|
build_cmd = [
|
||||||
|
options.node, options.babel_js, options.weex_loader_src_dir
|
||||||
|
]
|
||||||
|
build_cmd.extend(['--out-dir', options.output_dir])
|
||||||
|
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.weex_loader_src_dir))
|
||||||
|
|
||||||
|
uglify_cmd = [options.node, options.uglify_source_js, options.output_dir]
|
||||||
|
depfile_deps.append(options.uglify_source_js)
|
||||||
|
|
||||||
|
build_utils.call_and_write_depfile_if_stale(
|
||||||
|
lambda: do_build(build_cmd, uglify_cmd),
|
||||||
|
options,
|
||||||
|
depfile_deps=depfile_deps,
|
||||||
|
input_paths=depfile_deps,
|
||||||
|
output_paths=([options.output_dir]))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.exit(main())
|
40
package.json
40
package.json
@ -29,40 +29,14 @@
|
|||||||
"ace:build": "webpack --config ./webpack.config.js",
|
"ace:build": "webpack --config ./webpack.config.js",
|
||||||
"ace": "npm run lint && npm run build && npm run ace:build"
|
"ace": "npm run lint && npm run build && npm run ace:build"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
|
||||||
"babel-cli": "^6.10.1",
|
|
||||||
"babel-core": "^6.10.4",
|
|
||||||
"chai": "^3.5.0",
|
|
||||||
"coffee-loader": "^0.7.2",
|
|
||||||
"coffee-script": "^1.10.0",
|
|
||||||
"eslint": "^2.13.1",
|
|
||||||
"gazeer": "^0.1.1",
|
|
||||||
"jade": "^1.11.0",
|
|
||||||
"jade-html-loader": "0.0.3",
|
|
||||||
"js-base64": "^2.1.9",
|
|
||||||
"mocha": "^2.4.5",
|
|
||||||
"postcss-cssnext": "^2.7.0",
|
|
||||||
"postcss-loader": "^0.9.1",
|
|
||||||
"sinon": "^1.17.3",
|
|
||||||
"sinon-chai": "^2.8.0",
|
|
||||||
"webpack": "~1.13.0",
|
|
||||||
"weex-components": "^0.2.0"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"babel-loader": "^6.2.4",
|
"@babel/cli": "7.20.7",
|
||||||
"babel-plugin-transform-runtime": "^6.9.0",
|
"@babel/core": "7.20.12",
|
||||||
"babel-preset-es2015": "^6.9.0",
|
"@babel/plugin-proposal-class-properties": "7.18.6",
|
||||||
"babel-runtime": "^6.9.2",
|
"@babel/plugin-transform-runtime": "7.19.6",
|
||||||
"hash-sum": "^1.0.2",
|
"@babel/preset-env": "7.20.2",
|
||||||
"loader-utils": "^1.1.0",
|
"@babel/runtime": "7.20.13",
|
||||||
"md5": "^2.1.0",
|
"uglify-js": "3.17.4"
|
||||||
"parse5": "^2.1.5",
|
|
||||||
"source-map": "^0.5.6",
|
|
||||||
"weex-scripter": "^0.1.6",
|
|
||||||
"weex-styler": "^0.3.1",
|
|
||||||
"weex-templater": "^0.3.5",
|
|
||||||
"weex-transformer": "^0.4.6",
|
|
||||||
"weex-vue-loader": "^0.7.0"
|
|
||||||
},
|
},
|
||||||
"babel": {
|
"babel": {
|
||||||
"presets": [
|
"presets": [
|
||||||
|
44
uglify-source.js
Normal file
44
uglify-source.js
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
const uglifyJS = require('uglify-js')
|
||||||
|
|
||||||
|
readCode(process.argv[2])
|
||||||
|
|
||||||
|
function readCode(inputPath) {
|
||||||
|
if (fs.existsSync(inputPath)) {
|
||||||
|
const files = fs.readdirSync(inputPath)
|
||||||
|
files.forEach(function(file) {
|
||||||
|
const filePath = path.join(inputPath, file)
|
||||||
|
if (fs.existsSync(filePath)) {
|
||||||
|
const fileStat = fs.statSync(filePath)
|
||||||
|
if (fileStat.isFile()) {
|
||||||
|
const code = fs.readFileSync(filePath, 'utf-8')
|
||||||
|
uglifyCode(code,filePath)
|
||||||
|
}
|
||||||
|
if (fileStat.isDirectory()) {
|
||||||
|
readCode(filePath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function uglifyCode(code, outPath) {
|
||||||
|
const uglifyCode = uglifyJS.minify(code).code
|
||||||
|
fs.writeFileSync(outPath, uglifyCode)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user