Signed-off-by: lizhouze <lizhouze@huawei.com>
This commit is contained in:
lizhouze
2022-01-18 10:35:14 +08:00
parent a0400330aa
commit 1b7f5aa6a4
4 changed files with 115 additions and 3 deletions
+17
View File
@@ -193,6 +193,13 @@ ohos_copy("server") {
module_install_name = ""
}
ohos_copy("codegen") {
sources = [ "compiler/codegen" ]
outputs = [ target_out_dir + "/$target_name" ]
module_source_dir = target_out_dir + "/$target_name"
module_install_name = ""
}
ohos_copy("ets_loader_declaration") {
deps = [ ":build_ets_loader_library" ]
sources = [ ets_loader_declarations_dir ]
@@ -254,9 +261,19 @@ ohos_copy("ets_loader_ark_server") {
outputs = [ target_out_dir + "/ets_loader_ark/server" ]
}
ohos_copy("ets_loader_ark_codegen") {
deps = [
":build_ets_loader_library",
":ets_loader_ark",
]
sources = [ "compiler/codegen" ]
outputs = [ target_out_dir + "/ets_loader_ark/codegen" ]
}
ohos_copy("ets_loader_node_modules") {
deps = [
":ets_loader_ark",
":ets_loader_ark_codegen",
":ets_loader_ark_components",
":ets_loader_ark_declaration",
":ets_loader_ark_lib",
File diff suppressed because one or more lines are too long
+2
View File
@@ -52,6 +52,8 @@ function initProjectConfig(projectConfig) {
path.join(projectConfig.projectPath, 'manifest.json');
projectConfig.aceProfilePath = projectConfig.aceProfilePath || process.env.aceProfilePath;
projectConfig.aceModuleJsonPath = projectConfig.aceModuleJsonPath || process.env.aceModuleJsonPath;
projectConfig.aceSuperVisualPath = projectConfig.aceSuperVisualPath ||
process.env.aceSuperVisualPath
}
function loadEntryObj(projectConfig) {
+80 -3
View File
@@ -13,25 +13,33 @@
* limitations under the License.
*/
import ts from 'typescript';
import fs from 'fs';
import {
ReplaceResult,
sourceReplace,
validateUISyntax,
processSystemApi
processSystemApi,
componentCollection
} from './validate_ui_syntax';
import {
LogType,
LogInfo,
emitLogInfo
} from './utils';
import { BUILD_ON } from './pre_define';
import { projectConfig } from '../main.js';
import { genETS } from '../codegen/codegen_ets.js';
function preProcess(source: string): string {
process.env.compiler = BUILD_ON;
if (/\.ets$/.test(this.resourcePath)) {
const result: ReplaceResult = sourceReplace(source, this.resourcePath);
const newContent: string = result.content;
let newContent: string = result.content;
const log: LogInfo[] = result.log.concat(validateUISyntax(source, newContent,
this.resourcePath, this.resourceQuery));
newContent = parseVisual(this.resourcePath, newContent, log);
if (log.length) {
emitLogInfo(this, log);
}
@@ -41,4 +49,73 @@ function preProcess(source: string): string {
}
}
module.exports = preProcess;
function parseVisual(resourcePath: string, content: string, log: LogInfo[]): string {
if (componentCollection.entryComponent && projectConfig.aceSuperVisualPath) {
const sourceFile: ts.SourceFile = ts.createSourceFile(resourcePath, content,
ts.ScriptTarget.Latest, true, ts.ScrpitKint.TS);
if (sourceFile.statments) {
sourceFile.statments.forEach(statment => {
content = parseStatment(statment, content, log, resourcePath);
});
}
}
return content;
}
function parseStatment(statement: ts.Statement, content: string, log: LogInfo[],
resourcePath: string): string {
if (statement.kind === ts.SyntaxKind.ClassDeclaration &&
statement.name && statement.name.getText() === componentCollection.entryComponent) {
const visualPath: string = findVisualFile(resourcePath);
if (visualPath && fs.existsSync(visualPath) && statement.members) {
statement.members.forEach(member => {
if (member.kind && member === ts.SyntaxKind.MethodDeclaration) {
content = parseMember(member, content, log, visualPath)
}
});
}
}
return content;
}
function parseMember(member: ts.MethodDeclaration, content: string, log: LogInfo[],
visualPath: string): string {
if (member.name && member.name.getText() === 'build') {
const buildBody: string = content.substring(member.pos, member.end);
if (buildBody.replace(/\ +/g, '').replace(/[\r\n]/g, '') === 'build(){}') {
const visualContent: string = getVisualContent(visualPath, log, member.pos);
if (visualContent) {
content = content.replace(buildBody, '\nbuild() {\n' +
visualContent + '}\n');
}
} else {
log.push({
type: LogType.ERROR,
message: `when the corresponding visual file exists,` +
` the build function of the entry component must be empty.`,
pos: member.pos
});
}
}
return content;
}
function findVisualFile(filePath: string): string {
const visualPath: string = filePath.replace(projectConfig.projectPath,
projectConfig.aceSuperVisualPath).replace('.ets', '.visual');
return visualPath;
}
function getVisualContent(visualPath: string, log: LogInfo[], pos: number): string {
const parseContent: any = genETS(fs.readFileSync(visualPath, 'utf-8'));
if (parseContent && parseContent.errorType && parseContent.errorType != '') {
log.push({
type: LogType.ERROR,
message: parseContent.message,
pos: pos
});
}
return parseContent ? parseContent.ets : null;
}
module.exports = preProcess;