@atomicservice/ascf-toolkit-hvigor-plugin 1.0.11 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(e,o,i,t){return new(i||(i=Promise))(function(r,n){function
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,o,i,t){return new(i||(i=Promise))(function(r,n){function l(e){try{g(t.next(e))}catch(e){n(e)}}function s(e){try{g(t.throw(e))}catch(e){n(e)}}function g(e){var o;e.done?r(e.value):(o=e.value,o instanceof i?o:new i(function(e){e(o)})).then(l,s)}g((t=t.apply(e,o||[])).next())})},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=ascfToolkitHvigorPlugin;const hvigor_ohos_plugin_1=require("@ohos/hvigor-ohos-plugin"),hvigor_1=require("@ohos/hvigor"),ascf_toolkit_1=__importDefault(require("@atomicservice/ascf-toolkit")),child_process_1=require("child_process"),path_1=__importDefault(require("path")),fs_1=__importDefault(require("fs")),common_enum_1=require("../common/common-enum"),common_utils_1=require("../common/common-utils"),modifyShareInfoPlugin_1=require("./modifyShareInfoPlugin"),installAscfHspPlugin_1=require("./installAscfHspPlugin"),logger=hvigor_1.HvigorLogger.getLogger("ascfPlugin"),DEFAULT_OPTIONS={fixSharedHsp:!0,installAscfHsp:!0,debug:!0,compilerOptions:{swc:!1},skipAscfCompile:!1,skipApiValidator:!0};function ascfToolkitHvigorBuildNpm(e){e.registerTask({name:"buildNpm",run(){logger.info("start exec ascf buildNpm");const o=e.getContext(hvigor_ohos_plugin_1.OhosPluginId.OHOS_APP_PLUGIN);ascf_toolkit_1.default.buildNpm(o.getProjectPath()),logger.info("ascf buildNpm completed")}})}function ascfToolkitHvigorCli(e){e.registerTask({name:"ascf",run(){return __awaiter(this,void 0,void 0,function*(){var e,o,i;const t=`${(0,common_utils_1.getNodeExe)()} ${getAscfScript()} ${null!==(i=null===(o=null===(e=hvigor_1.hvigor.getParameter())||void 0===e?void 0:e.getExtParams())||void 0===o?void 0:o.args)&&void 0!==i?i:""}`;logger.info(`start exec ascf cli: ${t}`);try{yield executeCommand(t,logger.getLevel().levelStr.toLowerCase()),logger.info("ascf cli completed")}catch(e){logger.error("ascf cli error",e)}})}})}function initOptions(e){for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&("false"===e[o]&&(e[o]=!1),"true"===e[o]&&(e[o]=!0))}function ascfToolkitHvigorPlugin(e){return{pluginId:"ascfToolkitHvigorPlugin",apply(o){((null==e?void 0:e.hvigor)||hvigor_1.hvigor).nodesEvaluated(i=>__awaiter(this,void 0,void 0,function*(){var t,r;const n=null===(t=i.getParameter())||void 0===t?void 0:t.getExtParams();if((0,common_utils_1.isOhosTest)(i))return void logger.info("skip plugin when test");const l=getProjectConfigJson(o.getContext(hvigor_ohos_plugin_1.OhosPluginId.OHOS_APP_PLUGIN).getProjectPath());let s=(0,common_utils_1.deepMerge)(DEFAULT_OPTIONS,l,e,n);initOptions(s),logger.debug(`ascfToolkitHvigorPlugin options: extParams=${n} ${JSON.stringify(s)}`),yield execPlugin(s,o,i);try{if(i.isCommandEntryTask("GetHvigorDepsCachesDir"))o.registerTask({name:"GetHvigorDepsCachesDir",run(){console.log("ASCF_GET_HVIGOR_DEPS_CACHES_DIR="+ascf_toolkit_1.default.getAscfToolkitDirname())}});else if(i.isCommandEntryTask("buildNpm"))ascfToolkitHvigorBuildNpm(o);else if(i.isCommandEntryTask("ascf"))ascfToolkitHvigorCli(o);else{const e=o.getContext(hvigor_ohos_plugin_1.OhosPluginId.OHOS_APP_PLUGIN),t=path_1.default.join(e.getProjectPath(),"ascf/ascf_src/app.json");if(s.skipAscfCompile||!fs_1.default.existsSync(t))return void logger.debug("skipAscfCompile");(null===(r=i.getCommandEntryTask())||void 0===r?void 0:r.length)||(logger.debug("start exec ascf quickGenSub"),yield ascf_toolkit_1.default.quickGenerateSubpackage(e.getBuildMode(),s),logger.debug("ascf quickGenSub completed")),o.subNodes(o=>{const i=o.getContext(hvigor_ohos_plugin_1.OhosPluginId.OHOS_HAP_PLUGIN);i&&"entry"===i.getModuleType()&&o.registerTask({name:"ascfCompile",run(){return __awaiter(this,void 0,void 0,function*(){yield compileRun(s,e)})},dependencies:["default@PreBuild"],postDependencies:["assembleHap"]})})}}catch(e){logger.errorExit(new Error(String(e)))}}))}}}function compileRun(e,o){return __awaiter(this,void 0,void 0,function*(){var i;logger.debug("start exec ascf compile");const t=o.getBuildMode();let r=`${(0,common_utils_1.getNodeExe)()} ${getAscfScript()} compile -c ${"debug"===t?"-m":""} ${o.getProjectPath()}`;const n=logger.getLevel().levelStr.toLowerCase();e.debug&&n===common_enum_1.LogLevel.DEBUG&&(r+=" --debug"),e.compilerOptions.swc&&(r+=" --swc");const l=null===(i=e.devtool)||void 0===i?void 0:i.toLowerCase();l&&(r+=` --devtool=${l}`);r+=` --logging=${(e.logging?e.logging:n).toLowerCase()}`,e.templateHoist&&(r+=" --templateHoist"),r+=` --skipApiValidator=${e.skipApiValidator}`,r+=` --disableSubpackages=${e.disableSubpackages}`,logger.debug(r);try{yield executeCommand(r,n)}catch(e){logger.errorExit(new Error(String(e)))}logger.debug("ascf compile completed")})}function execPlugin(e,o,i){return __awaiter(this,void 0,void 0,function*(){const t=i.getNodeByName("entry");t&&e.fixSharedHsp&&(yield(0,modifyShareInfoPlugin_1.doModifyShareInfoPlugin)(t).catch(e=>logger.error(e))),o&&e.installAscfHsp&&(yield(0,installAscfHspPlugin_1.doInstallAscfHspPlugin)(o,i).catch(e=>logger.error(e)))})}function getProjectConfigJson(e){const o=path_1.default.join(e,"ascf","ascf_src","ascf.config.json");if(fs_1.default.existsSync(o)){const e=(0,common_utils_1.readJson)(o);return logger.debug(`project json is ${JSON.stringify(e)}`),e}return logger.debug(`${o} is not Exists`),{}}function executeCommand(e,o){return new Promise((i,t)=>{var r,n;const l=(0,child_process_1.exec)(e);null===(r=l.stdout)||void 0===r||r.on("data",e=>{if(/hvigor ERROR:|hvigor FATAL:|COMPILE RESULT:FAIL|FATAL/.test(e))return printLogger(e,common_enum_1.LogLevel.ERROR),void t(e);printLogger(e,o)}),null===(n=l.stderr)||void 0===n||n.on("error",e=>{t(e)}),l.on("close",e=>{i(e)})})}function printLogger(e,o){0!==e.length&&(o===common_enum_1.LogLevel.INFO?logger.info(`ASCF compiler log:\n${e}`):o===common_enum_1.LogLevel.WARN?logger.warn(`ASCF compiler log:\n${e}`):o===common_enum_1.LogLevel.ERROR?logger.error(`ASCF compiler log:\n${e}`):logger.debug(`ASCF compiler log:\n${e}`))}function getAscfScript(){return(0,common_utils_1.adjustPathByPlatform)(path_1.default.join(ascf_toolkit_1.default.getAscfToolkitDirname(),"bin","ascf.js"))}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))(function(i,
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))(function(i,r){function a(e){try{u(t.next(e))}catch(e){r(e)}}function s(e){try{u(t.throw(e))}catch(e){r(e)}}function u(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n(function(e){e(o)})).then(a,s)}u((t=t.apply(e,o||[])).next())})},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.doModifyShareInfoPlugin=doModifyShareInfoPlugin,exports.default=modifyShareInfoPlugin;const hvigor_1=require("@ohos/hvigor"),hvigor_ohos_plugin_1=require("@ohos/hvigor-ohos-plugin"),path_1=__importDefault(require("path")),fs_1=__importDefault(require("fs")),common_utils_1=require("../common/common-utils"),logger=hvigor_1.HvigorLogger.getLogger("modifyShareInfoPlugin"),ASCF_BUNDLENAME="com.huawei.hms.ascfruntime";function fixHspDep(e){null==e||e.forEach(e=>{if("ascf"===e.moduleName&&(e.bundleName||(e.bundleName=ASCF_BUNDLENAME),(0,common_utils_1.isEmulator)())){const o=(0,common_utils_1.getRuntimeVersionCode)(e.bundleName);if(e.versionCode!==o){e.versionCode=o;const n=path_1.default.resolve(__dirname,"../config.json"),t=(0,common_utils_1.parseJsonSafe)(fs_1.default.readFileSync(n).toString(),{});logger.warn(`emulator ASCF versionCode is ${o} not matches @atomicservice/ascfapi dependency versionCode ${e.versionCode}, please upgrade by ${t.emulatorFaq}`)}}})}function updateSharedInfo(e){const o=path_1.default.resolve(e,"build");if(!fs_1.default.existsSync(o))return void logger.debug("buildFilePath:"+o);const n=fs_1.default.readdirSync(o);logger.debug("buildFileNames:"+n),n.filter(e=>e).forEach(e=>{logger.debug("productName: "+e);const n=path_1.default.resolve(o,`${e}/intermediates/res/${e}/module.json`);if(logger.debug("module.json filePath: "+n),fs_1.default.existsSync(n)){const e=(0,common_utils_1.readJson)(n);fixHspDep(e.module.dependencies),(0,common_utils_1.writeJson)(n,e),logger.debug(`final moduleJson ${JSON.stringify(e,null," ")}`)}else logger.debug("module.json filePath: "+n+" is not Exists");const t=path_1.default.resolve(o,`${e}/intermediates/hap_metadata/${e}/output_metadata.json`);if(logger.debug("output_metadata.json filePath: "+t),fs_1.default.existsSync(t)){const e=(0,common_utils_1.readJson)(t);null==e||e.forEach(e=>{var o;const n=null===(o=e.dependRemoteHsps)||void 0===o?void 0:o.findIndex(e=>{var o;return null===(o=e.hspName)||void 0===o?void 0:o.includes("ascf")});e.dependRemoteHsps&&-1!==n&&e.dependRemoteHsps.splice(n,1)}),(0,common_utils_1.writeJson)(t,e),logger.debug(`final metadataJson ${JSON.stringify(e,null," ")}`)}})}function doModifyShareInfoPlugin(e){return __awaiter(this,void 0,void 0,function*(){logger.debug("start exec modify share info plugin");const o=e.getContext(hvigor_ohos_plugin_1.OhosPluginId.OHOS_HAP_PLUGIN);null==o||o.targets(o=>{const n=o.getTargetName();logger.debug(`${e.getNodeName()}:${n}`),e.registerTask({name:"modifyShareInfoTask",run:e=>{logger.debug("moduleName="+e.moduleName+" modulePath="+e.modulePath),updateSharedInfo(e.modulePath)},dependencies:[`${n}@CompileArkTS`],postDependencies:[`${n}@GeneratePkgModuleJson`]})}),logger.debug("exec modify share info plugin completed")})}function modifyShareInfoPlugin(){return{pluginId:"modifyShareInfoPlugin",apply:doModifyShareInfoPlugin}}
|
package/lib/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomicservice/ascf-toolkit-hvigor-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"title": "ASCF toolkit hvigor plugin for atomicservice",
|
|
5
5
|
"description": "ASCF toolkit hvigor plugin for atomicservice",
|
|
6
6
|
"main": "index.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"gulp-terser": "2.1.0"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@atomicservice/ascf-toolkit": "1.0.
|
|
18
|
+
"@atomicservice/ascf-toolkit": "1.0.12",
|
|
19
19
|
"json5": "2.2.3"
|
|
20
20
|
},
|
|
21
21
|
"overrides": {
|