mirror of
https://github.com/openharmony/developtools_ace-ets2bundle.git
synced 2026-07-18 16:04:32 -04:00
update ets-loader Signed-off-by: houhaoyu <houhaoyu@huawei.com> Change-Id: I2ab4a9e2deee71557fed9d5defde6e60f91dfdc3
This commit is contained in:
@@ -28,7 +28,10 @@ ets_sysResource = get_label_info(":build_ets_sysResource", "target_out_dir") +
|
||||
"/sysResource.js"
|
||||
|
||||
action("build_ets_loader_library") {
|
||||
deps = [ ":components", ":server" ]
|
||||
deps = [
|
||||
":components",
|
||||
":server",
|
||||
]
|
||||
script = "build_ets_loader_library.py"
|
||||
depfile = "$target_gen_dir/$target_name.d"
|
||||
outputs = [
|
||||
@@ -142,8 +145,10 @@ ohos_copy("ets_loader") {
|
||||
"compiler/webpack.config.js",
|
||||
ets_loader_component_config_file,
|
||||
]
|
||||
deps += [ ":build_ets_sysResource" ]
|
||||
sources += [ ets_sysResource ]
|
||||
if (!is_standard_system) {
|
||||
deps += [ ":build_ets_sysResource" ]
|
||||
sources += [ ets_sysResource ]
|
||||
}
|
||||
|
||||
outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ]
|
||||
module_source_dir = target_out_dir + "/$target_name"
|
||||
|
||||
@@ -49,7 +49,6 @@ function generateTargetFile(filePath, output) {
|
||||
fs.writeFile(fileName, newContent, err => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Generated
+1041
-2405
File diff suppressed because it is too large
Load Diff
@@ -10,7 +10,7 @@
|
||||
],
|
||||
"scripts": {
|
||||
"lint": "eslint --fix ./src --ext .ts",
|
||||
"build": "npm run generateSyntaxParser && npm run generateDeclarations && ./node_modules/.bin/babel ./src --out-dir lib --extensions .ts",
|
||||
"build": "npm run generateSyntaxParser && npm run generateDeclarations && ./node_modules/.bin/babel ./src --out-dir lib --extensions .ts && node uglify-source.js lib",
|
||||
"create": "node ./lib/create.js --env projectName",
|
||||
"compile": "webpack --config webpack.config.js --env buildMode=debug projectName",
|
||||
"test": "npm run build && mocha -r mocha-context/register test/test.js",
|
||||
@@ -31,7 +31,7 @@
|
||||
"mocha": "^8.2.1",
|
||||
"mocha-context": "^0.1.5",
|
||||
"ts-node": "^9.1.1",
|
||||
"uglify-es": "^3.3.10",
|
||||
"uglify-js": "^3.13.0",
|
||||
"pegjs": "^0.10.0"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -49,27 +49,27 @@ function handlePluginCommand(jsonData) {
|
||||
}
|
||||
|
||||
function handlePluginDefault() {
|
||||
console.error('Failed to recognize command');
|
||||
return;
|
||||
}
|
||||
|
||||
function handlePluginCompileComponent(jsonData) {
|
||||
const received_msg = jsonData;
|
||||
const receivedMsg = jsonData;
|
||||
const sourceNode = ts.createSourceFile
|
||||
('preview.ts', received_msg.data.script, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
||||
('preview.ts', receivedMsg.data.script, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
||||
const previewStatements = [];
|
||||
processComponentChild(sourceNode, previewStatements, []);
|
||||
const newSource = ts.factory.updateSourceFile(sourceNode, previewStatements);
|
||||
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
||||
const result = printer.printNode(ts.EmitHint.Unspecified, newSource, newSource);
|
||||
received_msg.data.script = result;
|
||||
receivedMsg.data.script = result;
|
||||
if (pluginSocket.readyState === WebSocket.OPEN){
|
||||
responseToPlugin(received_msg);
|
||||
responseToPlugin(receivedMsg);
|
||||
}
|
||||
}
|
||||
|
||||
function responseToPlugin(jsonData) {
|
||||
pluginSocket.send(JSON.stringify(jsonData), (err) => {
|
||||
console.error('Failed to send data through websocket');
|
||||
return;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const uglifyJS = require('uglify-es')
|
||||
const uglifyJS = require('uglify-js')
|
||||
|
||||
readCode(process.argv[2])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user