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