mirror of
https://github.com/openharmony/developtools_ace-ets2bundle.git
synced 2026-07-19 16:43:34 -04:00
Signed-off-by: puyajun <puyajun@huawei.com> Change-Id: I64fc083fb66eadf015c2eb7b29cabc0649313c3c
This commit is contained in:
@@ -13,9 +13,9 @@ const reset: string = '\u001b[39m';
|
||||
|
||||
function js2abcByWorkers(inputPaths: File[], cmd: string): Promise<void> {
|
||||
for (let i = 0; i < inputPaths.length; ++i) {
|
||||
let input = inputPaths[i].path;
|
||||
let singleCmd = `${cmd} "${input}"`;
|
||||
logger.debug("gen abc cmd is: ", singleCmd);
|
||||
const input = inputPaths[i].path;
|
||||
const singleCmd = `${cmd} "${input}"`;
|
||||
logger.debug('gen abc cmd is: ', singleCmd);
|
||||
try {
|
||||
process.execSync(singleCmd);
|
||||
} catch (e) {
|
||||
@@ -37,8 +37,8 @@ function js2abcByWorkers(inputPaths: File[], cmd: string): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("worker data is: ", JSON.stringify(workerData));
|
||||
logger.debug('worker data is: ', JSON.stringify(workerData));
|
||||
if (JSON.stringify(workerData) !== 'null') {
|
||||
logger.debug("==>worker #", threadId, "started!");
|
||||
logger.debug('==>worker #', threadId, 'started!');
|
||||
js2abcByWorkers(workerData.input, workerData.cmd);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ interface File {
|
||||
path: string,
|
||||
size: number
|
||||
}
|
||||
let intermediateJsBundle: Array<File> = [];
|
||||
const intermediateJsBundle: Array<File> = [];
|
||||
|
||||
const red: string = '\u001b[31m';
|
||||
const reset: string = '\u001b[39m';
|
||||
@@ -78,20 +78,20 @@ export class GenAbcPlugin {
|
||||
if (isMainThread) {
|
||||
let js2abc: string = path.join(arkDir, 'build', 'src', 'index.js');
|
||||
if (isWin) {
|
||||
js2abc = path.join(arkDir, 'build-win', 'src', 'index.js');
|
||||
js2abc = path.join(arkDir, 'build-win', 'src', 'index.js');
|
||||
} else if (isMac) {
|
||||
js2abc = path.join(arkDir, 'build-mac', 'src', 'index.js');
|
||||
}
|
||||
let maxWorkerNumber = 3;
|
||||
let splitedBundles = splitJsBundlesBySize(intermediateJsBundle, maxWorkerNumber);
|
||||
let workerNumber = maxWorkerNumber < splitedBundles.length ? maxWorkerNumber : splitedBundles.length;
|
||||
let cmdPrefix: string = `${nodeJs} --expose-gc "${js2abc}" ${param} `;
|
||||
let workers = [];
|
||||
const maxWorkerNumber = 3;
|
||||
const splitedBundles = splitJsBundlesBySize(intermediateJsBundle, maxWorkerNumber);
|
||||
const workerNumber = maxWorkerNumber < splitedBundles.length ? maxWorkerNumber : splitedBundles.length;
|
||||
const cmdPrefix: string = `${nodeJs} --expose-gc "${js2abc}" ${param} `;
|
||||
const workers = [];
|
||||
for (let i = 0; i < workerNumber; ++i) {
|
||||
workers.push(new Worker(path.resolve(__dirname, genAbcScript),
|
||||
{workerData: {input: splitedBundles[i], cmd: cmdPrefix} }));
|
||||
{workerData: {input: splitedBundles[i], cmd: cmdPrefix} }));
|
||||
workers[i].on('exit', () => {
|
||||
logger.debug("worker ", i, "finished!");
|
||||
logger.debug('worker ', i, 'finished!');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -106,7 +106,7 @@ function writeFileSync(inputString: string, output: string, jsBundleFile: string
|
||||
}
|
||||
fs.writeFileSync(output, inputString);
|
||||
if (fs.existsSync(output)) {
|
||||
let fileSize = fs.statSync(output).size;
|
||||
const fileSize = fs.statSync(output).size;
|
||||
intermediateJsBundle.push({path: output, size: fileSize});
|
||||
} else {
|
||||
logger.error(red, `ETS:ERROR Failed to convert file ${jsBundleFile} to bin. ${output} is lost`, reset);
|
||||
@@ -122,15 +122,15 @@ function mkDir(path_: string): void {
|
||||
}
|
||||
|
||||
function getSmallestSizeGroup(groupSize: Map<number, number>) {
|
||||
let groupSizeArray = Array.from(groupSize);
|
||||
const groupSizeArray = Array.from(groupSize);
|
||||
groupSizeArray.sort(function(g1, g2) {
|
||||
return g1[1] - g2[1]; // sort by value
|
||||
});
|
||||
return groupSizeArray[0][0]; // return key
|
||||
}
|
||||
|
||||
function splitJsBundlesBySize(bundleArray: Array<File>, groupNumber: number){
|
||||
let result = [];
|
||||
function splitJsBundlesBySize(bundleArray: Array<File>, groupNumber: number) {
|
||||
const result = [];
|
||||
if (bundleArray.length < groupNumber) {
|
||||
result.push(bundleArray);
|
||||
return result;
|
||||
@@ -139,17 +139,17 @@ function splitJsBundlesBySize(bundleArray: Array<File>, groupNumber: number){
|
||||
bundleArray.sort(function(f1: File, f2: File) {
|
||||
return f2.size - f1.size;
|
||||
});
|
||||
let groupFileSize = new Map();
|
||||
const groupFileSize = new Map();
|
||||
for (let i = 0; i < groupNumber; ++i) {
|
||||
result.push([]);
|
||||
groupFileSize.set(i, 0);
|
||||
}
|
||||
|
||||
let index = 0;
|
||||
while(index < bundleArray.length) {
|
||||
let smallestGroup = getSmallestSizeGroup(groupFileSize);
|
||||
while (index < bundleArray.length) {
|
||||
const smallestGroup = getSmallestSizeGroup(groupFileSize);
|
||||
result[smallestGroup].push(bundleArray[index]);
|
||||
let sizeUpdate = groupFileSize.get(smallestGroup) + bundleArray[index].size;
|
||||
const sizeUpdate = groupFileSize.get(smallestGroup) + bundleArray[index].size;
|
||||
groupFileSize.set(smallestGroup, sizeUpdate);
|
||||
index++;
|
||||
}
|
||||
|
||||
@@ -894,33 +894,35 @@ function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any,
|
||||
validateStateStyleSyntax(temp, log);
|
||||
}
|
||||
}
|
||||
temp = loopEtsComponent(temp, isStylesAttr, isGlobalStyles);
|
||||
temp = loopEtscomponent(temp, isStylesAttr, isGlobalStyles);
|
||||
statements.push(ts.factory.createExpressionStatement(
|
||||
createFunction(identifierNode, node, temp.arguments)));
|
||||
lastStatement.kind = true;
|
||||
}
|
||||
}
|
||||
|
||||
function loopEtsComponent(temp: any, isStylesAttr: boolean, isGlobalStyles: boolean): ts.Node {
|
||||
temp.arguments.forEach((item: ts.Node, index: number) => {
|
||||
function loopEtscomponent(node: any, isStylesAttr: boolean, isGlobalStyles: boolean): ts.Node {
|
||||
node.arguments.forEach((item: ts.Node, index: number) => {
|
||||
if (isStylesAttr && isGlobalStyles) {
|
||||
temp.arguments[index] = traverseStylesAttr(item);
|
||||
node.arguments[index] = traverseStylesAttr(item);
|
||||
}
|
||||
if (ts.isNewExpression(item) && item.expression && ts.isEtsComponentExpression(
|
||||
item.expression)) {
|
||||
temp.arguments[index] = ts.factory.updateNewExpression(item, item.expression.expression,
|
||||
undefined, item.expression.arguments);
|
||||
} else if (ts.isEtsComponentExpression(item)) {
|
||||
temp.arguments[index] = ts.factory.createCallExpression(item.expression,
|
||||
undefined, item.arguments);
|
||||
} else if ((ts.isCallExpression(item) || ts.isNewExpression(item)) && item.expression &&
|
||||
ts.isPropertyAccessExpression(item.expression) && item.expression.expression &&
|
||||
ts.isEtsComponentExpression(item.expression.expression)) {
|
||||
temp.arguments[index].expression.expression = ts.factory.createCallExpression(
|
||||
item.expression.expression.expression, undefined, item.expression.expression.arguments);
|
||||
if (ts.isEtsComponentExpression(item)) {
|
||||
node.arguments[index] = ts.factory.createCallExpression(
|
||||
item.expression, undefined, item.arguments);
|
||||
} else if (ts.isCallExpression(item) || ts.isNewExpression(item)) {
|
||||
node.arguments[index] = ts.visitEachChild(item,
|
||||
changeEtsComponentKind, contextGlobal);
|
||||
}
|
||||
});
|
||||
return temp;
|
||||
return node;
|
||||
}
|
||||
|
||||
function changeEtsComponentKind(node: ts.Node): ts.Node {
|
||||
if (ts.isEtsComponentExpression(node)) {
|
||||
node.kind = 204;
|
||||
return node;
|
||||
}
|
||||
return ts.visitEachChild(node, changeEtsComponentKind, contextGlobal);
|
||||
}
|
||||
|
||||
function classifyArgumentsNum(args: any, argumentsArr: ts.Expression[], propName: string,
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
"Ellipse",
|
||||
"Flex",
|
||||
"FormComponent",
|
||||
"FrictionMotion",
|
||||
"Gauge",
|
||||
"GeometryView",
|
||||
"Grid",
|
||||
@@ -68,7 +67,6 @@
|
||||
"RichText",
|
||||
"Scroll",
|
||||
"ScrollBar",
|
||||
"ScrollMotion",
|
||||
"Search",
|
||||
"Section",
|
||||
"Select",
|
||||
@@ -212,11 +210,6 @@
|
||||
"type": "FormComponentAttribute",
|
||||
"instance": "FormComponentInstance"
|
||||
},
|
||||
{
|
||||
"name": "FrictionMotion",
|
||||
"type": "FrictionMotionAttribute",
|
||||
"instance": "FrictionMotionInstance"
|
||||
},
|
||||
{
|
||||
"name": "Gauge",
|
||||
"type": "GaugeAttribute",
|
||||
@@ -402,11 +395,6 @@
|
||||
"type": "ScrollBarAttribute",
|
||||
"instance": "ScrollBarInstance"
|
||||
},
|
||||
{
|
||||
"name": "ScrollMotion",
|
||||
"type": "ScrollMotionAttribute",
|
||||
"instance": "ScrollMotionInstance"
|
||||
},
|
||||
{
|
||||
"name": "Search",
|
||||
"type": "SearchAttribute",
|
||||
|
||||
Reference in New Issue
Block a user