Signed-off-by: zhongjianfei <zhongjianfei@huawei.com>
Change-Id: I16ef4178e3c6dfb4d5c4e15ac0313ad841dfe126
This commit is contained in:
zhongjianfei
2021-09-02 11:38:28 +08:00
parent a7d27fefa8
commit 1dec1fc36a
6 changed files with 92 additions and 46 deletions
+19 -9
View File
@@ -46,16 +46,26 @@ function readManifest(manifestFilePath) {
return manifest;
}
function loadEntryObj(manifest, projectPath, device_level) {
function loadEntryObj(projectPath, device_level, abilityType, manifestFilePath) {
let entryObj = {}
const appJSPath = path.resolve(projectPath, 'app.js');
if (device_level === 'card') {
entryObj = addPageEntryObj(manifest, projectPath);
} else {
if (!fs.existsSync(appJSPath)) {
throw Error(red + 'ERROR: missing app.js' + reset).message;
}
entryObj['./app'] = projectPath + '/app.js?entry';
switch (abilityType) {
case 'page':
const appJSPath = path.resolve(projectPath, 'app.js');
if (device_level === 'card') {
entryObj = addPageEntryObj(readManifest(manifestFilePath), projectPath);
} else {
if (!fs.existsSync(appJSPath)) {
throw Error(red + 'ERROR: missing app.js' + reset).message;
}
entryObj['./app'] = projectPath + '/app.js?entry';
}
break;
case 'data':
entryObj['./data'] = projectPath + '/data.js?entry';
break
case 'service':
entryObj['./service'] = projectPath + '/service.js?entry';
break
}
return entryObj;
}
+5
View File
@@ -0,0 +1,5 @@
export default {
onInitialize(abilityInfo) {
console.info('DataAbility onInitialize');
}
};
@@ -0,0 +1,24 @@
export default {
onStart(want) {
console.info('ServiceAbility onStart');
},
onStop() {
console.info('ServiceAbility onStop');
},
onConnect(want) {
console.info('ServiceAbility onConnect');
},
onReconnect(want) {
console.info('ServiceAbility onReconnect');
},
onDisconnect() {
console.info('ServiceAbility onDisconnect');
},
onCommand(want, restart, startId) {
console.info('ServiceAbility onCommand');
},
onRemoteRequest(code, data, reply) {
console.info('ServiceAbility onRemoteRequest');
return true;
}
};
+27 -25
View File
@@ -142,32 +142,34 @@ let entryObj = {};
function addPageEntryObj() {
entryObj = {};
if (!fs.existsSync(manifestFilePath)) {
throw Error('ERROR: missing manifest').message;
}
const jsonString = fs.readFileSync(manifestFilePath).toString();
const obj = JSON.parse(jsonString);
const pages = obj.pages;
if (pages === undefined) {
throw Error('ERROR: missing pages').message;
}
pages.forEach((element) => {
const sourcePath = element;
const hmlPath = path.join(input, sourcePath + '.hml')
const aceSuperVisualPath = process.env.aceSuperVisualPath || ''
const visualPath = path.join(aceSuperVisualPath, sourcePath + '.visual')
const isHml = fs.existsSync(hmlPath)
const isVisual = fs.existsSync(visualPath)
if (isHml && isVisual) {
logWarn(this, [{
reason: 'ERROR: ' + sourcePath + ' cannot both have hml && visual'
}])
} else if (isHml) {
entryObj['./' + element] = hmlPath + '?entry';
} else if (isVisual){
entryObj['./' + element] = visualPath + '?entry';
if (process.env.abilityType === 'page') {
if (!fs.existsSync(manifestFilePath)) {
throw Error('ERROR: missing manifest').message;
}
});
const jsonString = fs.readFileSync(manifestFilePath).toString();
const obj = JSON.parse(jsonString);
const pages = obj.pages;
if (pages === undefined) {
throw Error('ERROR: missing pages').message;
}
pages.forEach((element) => {
const sourcePath = element;
const hmlPath = path.join(input, sourcePath + '.hml')
const aceSuperVisualPath = process.env.aceSuperVisualPath || ''
const visualPath = path.join(aceSuperVisualPath, sourcePath + '.visual')
const isHml = fs.existsSync(hmlPath)
const isVisual = fs.existsSync(visualPath)
if (isHml && isVisual) {
logWarn(this, [{
reason: 'ERROR: ' + sourcePath + ' cannot both have hml && visual'
}])
} else if (isHml) {
entryObj['./' + element] = hmlPath + '?entry';
} else if (isVisual){
entryObj['./' + element] = visualPath + '?entry';
}
});
}
if (process.env.isPreview !== 'true' && process.env.DEVICE_LEVEL === 'rich') {
loadWorker(entryObj);
}
+2 -1
View File
@@ -122,6 +122,7 @@ function setConfigs(env) {
process.env.projectPath = env.aceModuleRoot || process.env.aceModuleRoot || process.cwd();
process.env.buildPath = env.aceModuleBuild || process.env.aceModuleBuild || path.resolve(process.env.projectPath, 'build');
process.env.aceManifestPath = process.env.aceManifestPath || path.resolve(process.env.projectPath, 'manifest.json');
process.env.abilityType = 'page';
const manifest = readManifest(process.env.aceManifestPath)
process.env.PLATFORM_VERSION = PLATFORM.VERSION6;
const version = parseInt(manifest.minPlatformVersion);
@@ -136,7 +137,7 @@ function setConfigs(env) {
module.exports = (env) => {
setConfigs(env)
deleteFolderRecursive(process.env.buildPath);
webpackConfig.entry = loadEntryObj(readManifest(process.env.aceManifestPath), process.env.projectPath, process.env.DEVICE_LEVEL)
webpackConfig.entry = loadEntryObj(process.env.projectPath, process.env.DEVICE_LEVEL, process.env.abilityType, process.env.aceManifestPath)
webpackConfig.output.path = path.resolve(__dirname, process.env.buildPath)
webpackConfig.plugins = [
new ResourcePlugin(process.env.projectPath, process.env.buildPath, process.env.aceManifestPath),
+15 -11
View File
@@ -39,7 +39,7 @@ const richModule = {
}]
},
{
test: /(\.hml|app\.js)(\?[^?]+)?$/,
test: /(\.hml|app\.js|data\.js|service\.js)(\?[^?]+)?$/,
use: [{
loader: path.resolve(__dirname, './index.js')
}]
@@ -156,15 +156,19 @@ function setConfigs(env) {
process.env.projectPath = env.aceModuleRoot || process.env.aceModuleRoot || process.cwd();
process.env.buildPath = env.aceModuleBuild || process.env.aceModuleBuild || path.resolve(process.env.projectPath, 'build');
process.env.aceManifestPath = process.env.aceManifestPath || path.resolve(process.env.projectPath, 'manifest.json');
const manifest = readManifest(process.env.aceManifestPath)
process.env.DEVICE_LEVEL = manifest.type === 'form' ? 'card' : 'rich'
process.env.PLATFORM_VERSION = PLATFORM.VERSION6;
const version = parseInt(manifest.minPlatformVersion);
if (version == 5) {
process.env.PLATFORM_VERSION = PLATFORM.VERSION5;
}
if (version <= 4) {
process.env.PLATFORM_VERSION = PLATFORM.VERSION3;
process.env.abilityType = process.env.abilityType || 'page'
process.env.DEVICE_LEVEL = process.env.DEVICE_LEVEL || 'rich'
if (process.env.abilityType === 'page') {
const manifest = readManifest(process.env.aceManifestPath)
process.env.DEVICE_LEVEL = manifest.type === 'form' ? 'card' : 'rich'
process.env.PLATFORM_VERSION = PLATFORM.VERSION6;
const version = parseInt(manifest.minPlatformVersion);
if (version == 5) {
process.env.PLATFORM_VERSION = PLATFORM.VERSION5;
}
if (version <= 4) {
process.env.PLATFORM_VERSION = PLATFORM.VERSION3;
}
}
}
@@ -172,7 +176,7 @@ function setConfigs(env) {
module.exports = (env) => {
setConfigs(env)
deleteFolderRecursive(process.env.buildPath);
config.entry = loadEntryObj(readManifest(process.env.aceManifestPath), process.env.projectPath, process.env.DEVICE_LEVEL)
config.entry = loadEntryObj(process.env.projectPath, process.env.DEVICE_LEVEL, process.env.abilityType, process.env.aceManifestPath)
config.output.path = path.resolve(__dirname, process.env.buildPath)
config.plugins = [
new ResourcePlugin(process.env.projectPath, process.env.buildPath, process.env.aceManifestPath),