From 778f37ff050ab2f9e6b7d9e07d99e57d28cde855 Mon Sep 17 00:00:00 2001 From: zhongjianfei Date: Sat, 28 Aug 2021 16:48:39 +0800 Subject: [PATCH] lihong67@huawei.com Signed-off-by: lihong Change-Id: Ifcbd1595ac9237d871430e8911ff849a4fc9585e --- .gitignore | 6 ++ BUILD.gn | 42 ++------ build_ets_loader_library.py | 5 +- compiler/build_declarations_file.js | 19 +++- compiler/package-lock.json | 4 +- compiler/package.json | 2 +- {prebuilts => compiler}/uglify-source.js | 0 compiler/webpack.config.js | 3 - prebuilts/babel.config.js | 35 ------- prebuilts/build_declarations_file.js | 128 ----------------------- 10 files changed, 35 insertions(+), 209 deletions(-) create mode 100644 .gitignore rename {prebuilts => compiler}/uglify-source.js (100%) delete mode 100644 prebuilts/babel.config.js delete mode 100644 prebuilts/build_declarations_file.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..d7755f04 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +./vscode +compiler/node_modules/ +compiler/lib/ +compiler/declarations/ +compiler/sample/build/ +compiler/component_config.json diff --git a/BUILD.gn b/BUILD.gn index 20068f1a..ea0dcd1a 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -11,11 +11,9 @@ ets_loader_declarations_dir = get_label_info(":build_ets_loader_library", ets_loader_component_config_file = get_label_info(":build_ets_loader_library", "target_out_dir") + "/component_config.json" -ets_sysResource = get_label_info(":build_ets_sysResource", "target_out_dir") + - "/sysResource.js" action("build_ets_loader_library") { - script = "//foundation/ace/huawei_proprietary/tools/ets-loader/build_ets_loader_library.py" + script = "//developtools/ace-ets2bundle/build_ets_loader_library.py" depfile = "$target_gen_dir/$target_name.d" outputs = [ ets_loader_lib_dir, @@ -23,15 +21,13 @@ action("build_ets_loader_library") { ets_loader_component_config_file, ] - _ets_loader_dir = - "//foundation/ace/huawei_proprietary/tools/ets-loader/compiler" - _ace_toolkit_dir = "//prebuilts/ace-toolkit/ets-loader/compiler" + _ets_loader_dir = "//developtools/ace-ets2bundle/compiler" _declarations_file_dir = "//interface/sdk-js/api/@internal/component/ets" - _babel_js = _ace_toolkit_dir + "/node_modules/@babel/cli/bin/babel.js" - _babel_config_js = _ace_toolkit_dir + "/babel.config.js" - _uglify_source_js = _ace_toolkit_dir + "/uglify-source.js" - _build_declarations_file_js = _ace_toolkit_dir + "/build_declarations_file.js" + _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_declarations_file_js = _ets_loader_dir + "/build_declarations_file.js" inputs = [ _babel_config_js, @@ -43,10 +39,10 @@ action("build_ets_loader_library") { # different host platform nodejs tool directory if (host_os == "linux") { nodejs_path = - "//prebuilts/ace-toolkit/nodejs/node-v12.18.4-linux-x64/bin/node" + "//prebuilts/build-tools/common/nodejs/node-v12.18.4-linux-x64/bin/node" } else if (host_os == "mac") { nodejs_path = - "//prebuilts/ace-toolkit/nodejs/node-v12.18.4-darwin-x64/bin/node" + "//prebuilts/build-tools/common/nodejs/node-v12.18.4-darwin-x64/bin/node" } else { assert(false, "Unsupported host_os: $host_os") } @@ -77,27 +73,8 @@ action("build_ets_loader_library") { ] } -action("build_ets_sysResource") { - script = "//foundation/ace/huawei_proprietary/tools/ets-loader/generateSysResource.py" - outputs = [ ets_sysResource ] - - _id_defined_json = - "//utils/resources/systemres/main/resources/base/element/id_defined.json" - inputs = [ _id_defined_json ] - - args = [ - "--input-json", - rebase_path(_id_defined_json, root_build_dir), - "--output-js", - rebase_path(ets_sysResource, root_build_dir), - ] -} - ohos_copy("ets_loader") { - deps = [ - ":build_ets_loader_library", - ":build_ets_sysResource", - ] + deps = [ ":build_ets_loader_library" ] sources = [ "compiler/main.js", "compiler/npm-install.js", @@ -106,7 +83,6 @@ ohos_copy("ets_loader") { "compiler/tsconfig.json", "compiler/webpack.config.js", ets_loader_component_config_file, - ets_sysResource, ] outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] module_source_dir = target_out_dir + "/$target_name" diff --git a/build_ets_loader_library.py b/build_ets_loader_library.py index 9d79e430..462f7dbe 100644 --- a/build_ets_loader_library.py +++ b/build_ets_loader_library.py @@ -19,9 +19,8 @@ import subprocess import argparse sys.path.append( - os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, - os.pardir, os.pardir, 'build')) -from maple.java.util import build_utils # noqa: E402 + os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, 'build')) +from scripts.util import build_utils # noqa: E402 def parse_args(): diff --git a/compiler/build_declarations_file.js b/compiler/build_declarations_file.js index 22a1f627..3b016b63 100644 --- a/compiler/build_declarations_file.js +++ b/compiler/build_declarations_file.js @@ -17,10 +17,8 @@ const ts = require('typescript') const path = require('path') const fs = require('fs') -generateTargetFile(); -function generateTargetFile() { - const filePath = path.resolve(__dirname, '../../../../../../interface/sdk-js/api/@internal/component/ets'); - const output = path.resolve(__dirname, './declarations'); +generateTargetFile(process.argv[2], process.argv[3]); +function generateTargetFile(filePath, output) { const files = []; const globalTsFile = path.resolve(filePath, '../../global.d.ts'); if (fs.existsSync(globalTsFile)) { @@ -115,3 +113,16 @@ function isVariable(node) { } return false; } + +generateComponentConfig(process.argv[4]); +function generateComponentConfig(dir) { + const configFile = path.resolve(dir, 'component_map.js'); + if (fs.existsSync(configFile)) { + const { COMPONENT_MAP } = require(configFile); + try { + fs.writeFileSync(path.resolve(dir, '../component_config.json'), JSON.stringify(COMPONENT_MAP)); + } catch (error) { + console.error(error); + } + } +} diff --git a/compiler/package-lock.json b/compiler/package-lock.json index 22b091f2..707b1306 100644 --- a/compiler/package-lock.json +++ b/compiler/package-lock.json @@ -2559,8 +2559,8 @@ }, "deccjsunit": { "version": "1.0.3", - "resolved": "http://cmc.centralrepo.rnd.huawei.com/artifactory/api/npm/npm-public/deccjsunit/-/deccjsunit-1.0.3.tgz", - "integrity": "sha512-GER7j7yKoZHFzr9CzWEdTOhR5LuxXV7PkUqL4lcU9+UmutIiDvvBW3rce4nTcbrvCd6DDqOrgqJ/0+GqA2W+Xw==" + "resolved": "https://registry.nlark.com/deccjsunit/download/deccjsunit-1.0.3.tgz", + "integrity": "sha1-AcMxIKje4SsaoQiZGE14pszfiKI=" }, "decode-uri-component": { "version": "0.2.0", diff --git a/compiler/package.json b/compiler/package.json index fab82d88..2cc4470f 100644 --- a/compiler/package.json +++ b/compiler/package.json @@ -14,7 +14,7 @@ "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", + "generateDeclarations": "node ./build_declarations_file.js ../../../interface/sdk-js/api/@internal/component/ets ./declarations ./lib", "postinstall": "node npm-install.js" }, "devDependencies": { diff --git a/prebuilts/uglify-source.js b/compiler/uglify-source.js similarity index 100% rename from prebuilts/uglify-source.js rename to compiler/uglify-source.js diff --git a/compiler/webpack.config.js b/compiler/webpack.config.js index fe85894a..9be4d648 100644 --- a/compiler/webpack.config.js +++ b/compiler/webpack.config.js @@ -36,9 +36,6 @@ function initConfig(config) { const projectPath = path.resolve(projectConfig.projectPath); Object.assign(config, { entry: projectConfig.entryObj, - cache: { - type: 'filesystem' - }, watch: watchMode, watchOptions: { aggregateTimeout: 10, diff --git a/prebuilts/babel.config.js b/prebuilts/babel.config.js deleted file mode 100644 index 1c8aa705..00000000 --- a/prebuilts/babel.config.js +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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. - */ - -module.exports = function(api) { - api.cache(true); - - const presets = ['@babel/preset-env', '@babel/typescript']; - const plugins = [ - '@babel/plugin-transform-modules-commonjs', - '@babel/plugin-proposal-class-properties', - [ - '@babel/plugin-transform-arrow-functions', - { - spec: true - } - ] - ]; - - return { - presets, - plugins - }; -}; diff --git a/prebuilts/build_declarations_file.js b/prebuilts/build_declarations_file.js deleted file mode 100644 index 3b016b63..00000000 --- a/prebuilts/build_declarations_file.js +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2021 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 ts = require('typescript') -const path = require('path') -const fs = require('fs') - -generateTargetFile(process.argv[2], process.argv[3]); -function generateTargetFile(filePath, output) { - const files = []; - const globalTsFile = path.resolve(filePath, '../../global.d.ts'); - if (fs.existsSync(globalTsFile)) { - files.push(globalTsFile); - } - readFile(filePath, files); - if (!fs.existsSync(output)) { - mkDir(output); - } - const license = `/* - * Copyright (c) 2021 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. - */`; - files.forEach((item) => { - const content = fs.readFileSync(item, 'utf8'); - const fileName = path.resolve(output, path.basename(item)); - const newContent = license + '\n\n' + processsFile(content, fileName); - fs.writeFile(fileName, newContent, err => { - if (err) { - console.error(err); - return; - } - }); - }); -} - -function readFile(dir, fileDir) { - const files = fs.readdirSync(dir); - files.forEach((element) => { - const filePath = path.join(dir, element); - const status = fs.statSync(filePath); - if (status.isDirectory()) { - readFile(filePath, fileDir); - } else { - fileDir.push(filePath); - } - }); -} - -function mkDir(filePath) { - const parent = path.join(filePath, '..'); - if (!(fs.existsSync(parent) && !fs.statSync(parent).isFile())) { - mkDir(parent); - } - fs.mkdirSync(filePath); -} - -function processsFile(content, fileName) { - let sourceFile = ts.createSourceFile(fileName, content, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS); - const newStatements = []; - if (sourceFile.statements && sourceFile.statements.length) { - sourceFile.statements.forEach((node) => { - if (!ts.isImportDeclaration(node)) { - if (node.modifiers && node.modifiers.length && node.modifiers[0].kind === ts.SyntaxKind.ExportKeyword) { - node.modifiers.splice(0, 1); - } - if (isVariable(node)) { - const name = node.declarationList.declarations[0].name.getText(); - const type = node.declarationList.declarations[0].type.getText(); - if (name.indexOf(type) !== -1) { - const declarationNode = ts.factory.updateVariableDeclaration(node.declarationList.declarations[0], - ts.factory.createIdentifier(type), node.declarationList.declarations[0].exclamationToken, - node.declarationList.declarations[0].type, node.declarationList.declarations[0].initializer); - node.declarationList = ts.factory.updateVariableDeclarationList(node.declarationList, [declarationNode]); - } - } - newStatements.push(node); - } - }); - } - sourceFile = ts.factory.updateSourceFile(sourceFile, newStatements); - const printer = ts.createPrinter({ removeComments: true, newLine: ts.NewLineKind.LineFeed }); - const result = printer.printNode(ts.EmitHint.Unspecified, sourceFile, sourceFile); - return result; -} - -function isVariable(node) { - if (ts.isVariableStatement(node) && node.declarationList && node.declarationList.declarations && - node.declarationList.declarations.length && ts.isVariableDeclaration(node.declarationList.declarations[0]) && - node.declarationList.declarations[0].name && node.declarationList.declarations[0].type) { - return true; - } - return false; -} - -generateComponentConfig(process.argv[4]); -function generateComponentConfig(dir) { - const configFile = path.resolve(dir, 'component_map.js'); - if (fs.existsSync(configFile)) { - const { COMPONENT_MAP } = require(configFile); - try { - fs.writeFileSync(path.resolve(dir, '../component_config.json'), JSON.stringify(COMPONENT_MAP)); - } catch (error) { - console.error(error); - } - } -}