Signed-off-by: lihong <lihong67@huawei.com>
Change-Id: Ifcbd1595ac9237d871430e8911ff849a4fc9585e
This commit is contained in:
zhongjianfei 2021-08-28 16:48:39 +08:00 committed by lihong
parent d9baa21ffd
commit 778f37ff05
10 changed files with 35 additions and 209 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
./vscode
compiler/node_modules/
compiler/lib/
compiler/declarations/
compiler/sample/build/
compiler/component_config.json

View File

@ -11,11 +11,9 @@ ets_loader_declarations_dir = get_label_info(":build_ets_loader_library",
ets_loader_component_config_file = ets_loader_component_config_file =
get_label_info(":build_ets_loader_library", "target_out_dir") + get_label_info(":build_ets_loader_library", "target_out_dir") +
"/component_config.json" "/component_config.json"
ets_sysResource = get_label_info(":build_ets_sysResource", "target_out_dir") +
"/sysResource.js"
action("build_ets_loader_library") { 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" depfile = "$target_gen_dir/$target_name.d"
outputs = [ outputs = [
ets_loader_lib_dir, ets_loader_lib_dir,
@ -23,15 +21,13 @@ action("build_ets_loader_library") {
ets_loader_component_config_file, ets_loader_component_config_file,
] ]
_ets_loader_dir = _ets_loader_dir = "//developtools/ace-ets2bundle/compiler"
"//foundation/ace/huawei_proprietary/tools/ets-loader/compiler"
_ace_toolkit_dir = "//prebuilts/ace-toolkit/ets-loader/compiler"
_declarations_file_dir = "//interface/sdk-js/api/@internal/component/ets" _declarations_file_dir = "//interface/sdk-js/api/@internal/component/ets"
_babel_js = _ace_toolkit_dir + "/node_modules/@babel/cli/bin/babel.js" _babel_js = _ets_loader_dir + "/node_modules/@babel/cli/bin/babel.js"
_babel_config_js = _ace_toolkit_dir + "/babel.config.js" _babel_config_js = _ets_loader_dir + "/babel.config.js"
_uglify_source_js = _ace_toolkit_dir + "/uglify-source.js" _uglify_source_js = _ets_loader_dir + "/uglify-source.js"
_build_declarations_file_js = _ace_toolkit_dir + "/build_declarations_file.js" _build_declarations_file_js = _ets_loader_dir + "/build_declarations_file.js"
inputs = [ inputs = [
_babel_config_js, _babel_config_js,
@ -43,10 +39,10 @@ action("build_ets_loader_library") {
# different host platform nodejs tool directory # different host platform nodejs tool directory
if (host_os == "linux") { if (host_os == "linux") {
nodejs_path = 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") { } else if (host_os == "mac") {
nodejs_path = 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 { } else {
assert(false, "Unsupported host_os: $host_os") 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") { ohos_copy("ets_loader") {
deps = [ deps = [ ":build_ets_loader_library" ]
":build_ets_loader_library",
":build_ets_sysResource",
]
sources = [ sources = [
"compiler/main.js", "compiler/main.js",
"compiler/npm-install.js", "compiler/npm-install.js",
@ -106,7 +83,6 @@ ohos_copy("ets_loader") {
"compiler/tsconfig.json", "compiler/tsconfig.json",
"compiler/webpack.config.js", "compiler/webpack.config.js",
ets_loader_component_config_file, ets_loader_component_config_file,
ets_sysResource,
] ]
outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ]
module_source_dir = target_out_dir + "/$target_name" module_source_dir = target_out_dir + "/$target_name"

View File

@ -19,9 +19,8 @@ import subprocess
import argparse import argparse
sys.path.append( sys.path.append(
os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, 'build'))
os.pardir, os.pardir, 'build')) from scripts.util import build_utils # noqa: E402
from maple.java.util import build_utils # noqa: E402
def parse_args(): def parse_args():

View File

@ -17,10 +17,8 @@ const ts = require('typescript')
const path = require('path') const path = require('path')
const fs = require('fs') const fs = require('fs')
generateTargetFile(); generateTargetFile(process.argv[2], process.argv[3]);
function generateTargetFile() { function generateTargetFile(filePath, output) {
const filePath = path.resolve(__dirname, '../../../../../../interface/sdk-js/api/@internal/component/ets');
const output = path.resolve(__dirname, './declarations');
const files = []; const files = [];
const globalTsFile = path.resolve(filePath, '../../global.d.ts'); const globalTsFile = path.resolve(filePath, '../../global.d.ts');
if (fs.existsSync(globalTsFile)) { if (fs.existsSync(globalTsFile)) {
@ -115,3 +113,16 @@ function isVariable(node) {
} }
return false; 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);
}
}
}

View File

@ -2559,8 +2559,8 @@
}, },
"deccjsunit": { "deccjsunit": {
"version": "1.0.3", "version": "1.0.3",
"resolved": "http://cmc.centralrepo.rnd.huawei.com/artifactory/api/npm/npm-public/deccjsunit/-/deccjsunit-1.0.3.tgz", "resolved": "https://registry.nlark.com/deccjsunit/download/deccjsunit-1.0.3.tgz",
"integrity": "sha512-GER7j7yKoZHFzr9CzWEdTOhR5LuxXV7PkUqL4lcU9+UmutIiDvvBW3rce4nTcbrvCd6DDqOrgqJ/0+GqA2W+Xw==" "integrity": "sha1-AcMxIKje4SsaoQiZGE14pszfiKI="
}, },
"decode-uri-component": { "decode-uri-component": {
"version": "0.2.0", "version": "0.2.0",

View File

@ -14,7 +14,7 @@
"create": "node ./lib/create.js --env projectName", "create": "node ./lib/create.js --env projectName",
"compile": "webpack --config webpack.config.js --env buildMode=debug projectName", "compile": "webpack --config webpack.config.js --env buildMode=debug projectName",
"test": "npm run build && mocha -r ts-node/register test/test.ts", "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" "postinstall": "node npm-install.js"
}, },
"devDependencies": { "devDependencies": {

View File

@ -36,9 +36,6 @@ function initConfig(config) {
const projectPath = path.resolve(projectConfig.projectPath); const projectPath = path.resolve(projectConfig.projectPath);
Object.assign(config, { Object.assign(config, {
entry: projectConfig.entryObj, entry: projectConfig.entryObj,
cache: {
type: 'filesystem'
},
watch: watchMode, watch: watchMode,
watchOptions: { watchOptions: {
aggregateTimeout: 10, aggregateTimeout: 10,

View File

@ -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
};
};

View File

@ -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);
}
}
}