diff --git a/compiler/main.js b/compiler/main.js index 505c8ea..8e9d8cb 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -159,6 +159,7 @@ function setAbilityPages(projectConfig) { const moduleJson = JSON.parse(fs.readFileSync(projectConfig.aceModuleJsonPath).toString()); abilityPages = readAbilityEntrance(moduleJson); setAbilityFile(projectConfig, abilityPages); + setBundleModuleInfo(projectConfig, moduleJson); } } @@ -194,6 +195,15 @@ function setStageTestRunnerFile(projectConfig) { } } +function setBundleModuleInfo(projectConfig, moduleJson) { + if (moduleJson.module) { + projectConfig.moduleName = moduleJson.module.name; + } + if (moduleJson.app) { + projectConfig.bundleName = moduleJson.app.bundleName; + } +} + function setAbilityFile(projectConfig, abilityPages) { abilityPages.forEach(abilityPath => { const projectAbilityPath = path.resolve(projectConfig.projectPath, '../', abilityPath); diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index ecb8e05..1449851 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -162,6 +162,8 @@ export const RESOURCE_RAWFILE: string = '$rawfile'; export const RESOURCE_NAME_ID: string = 'id'; export const RESOURCE_NAME_TYPE: string = 'type'; export const RESOURCE_NAME_PARAMS: string = 'params'; +export const RESOURCE_NAME_BUNDLE: string = 'bundle'; +export const RESOURCE_NAME_MODULE: string = 'mdoule'; export const RESOURCE_TYPE = { color: 10001, float: 10002, diff --git a/compiler/src/process_ui_syntax.ts b/compiler/src/process_ui_syntax.ts index 945bad7..04fb029 100644 --- a/compiler/src/process_ui_syntax.ts +++ b/compiler/src/process_ui_syntax.ts @@ -33,6 +33,8 @@ import { RESOURCE_NAME_TYPE, RESOURCE_NAME_PARAMS, RESOURCE_RAWFILE, + RESOURCE_NAME_BUNDLE, + RESOURCE_NAME_MODULE, ATTRIBUTE_ANIMATETO, GLOBAL_CONTEXT, CHECK_COMPONENT_EXTEND_DECORATOR, @@ -65,7 +67,7 @@ import { localStorageLinkCollection, localStoragePropCollection } from './validate_ui_syntax'; -import { resources } from '../main'; +import { projectConfig, resources } from '../main'; import { createCustomComponentNewExpression, createViewCreate } from './process_component_member'; export const transformLog: FileLog = new FileLog(); @@ -293,26 +295,37 @@ function processResourceData(node: ts.CallExpression): ts.Node { function createResourceParam(resourceValue: number, resourceType: number, argsArr: ts.Expression[]): ts.ObjectLiteralExpression { + const propertyArray: Array[ts.PropertyAssignment] = [ + ts.factory.createPropertyAssignment( + ts.factory.createStringLiteral(RESOURCE_NAME_ID), + ts.factory.createNumericLiteral(resourceValue) + ), + ts.factory.createPropertyAssignment( + ts.factory.createStringLiteral(RESOURCE_NAME_TYPE), + ts.factory.createNumericLiteral(resourceType) + ), + ts.factory.createPropertyAssignment( + ts.factory.createIdentifier(RESOURCE_NAME_PARAMS), + ts.factory.createArrayLiteralExpression(argsArr, false) + ) + ]; + + if (projectConfig.bundleName) { + propertyArray.push(ts.factory.createPropertyAssignment( + ts.factory.createStringLiteral(RESOURCE_NAME_BUNDLE), + ts.factory.createStringLiteral(projectConfig.bundleName) + )); + } + + if (projectConfig.moduleName) { + propertyArray.push(ts.factory.createPropertyAssignment( + ts.factory.createStringLiteral(RESOURCE_NAME_MODULE), + ts.factory.createStringLiteral(projectConfig.moduleName) + )); + } + const resourceParams: ts.ObjectLiteralExpression = ts.factory.createObjectLiteralExpression( - [ - ts.factory.createPropertyAssignment( - ts.factory.createStringLiteral(RESOURCE_NAME_ID), - ts.factory.createNumericLiteral(resourceValue) - ), - ts.factory.createPropertyAssignment( - ts.factory.createStringLiteral(RESOURCE_NAME_TYPE), - ts.factory.createNumericLiteral(resourceType) - ), - ts.factory.createPropertyAssignment( - ts.factory.createIdentifier(RESOURCE_NAME_PARAMS), - ts.factory.createArrayLiteralExpression( - argsArr, - false - ) - ) - ], - false - ); + propertyArray, false); return resourceParams; }