@atomicservice/ascf-toolkit-hvigor-plugin 1.0.3 → 1.0.5-beta.4
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.
- package/gulpfile.mjs +34 -0
- package/index.ts +4 -4
- package/lib/common/common-enum.js +1 -0
- package/lib/common/common-utils.js +1 -0
- package/lib/plugin/ascf-toolkit-hvigor-plugin.js +1 -0
- package/lib/plugin/installAscfHspPlugin.js +1 -0
- package/lib/plugin/modifyShareInfoPlugin.js +1 -0
- package/lib/plugin/sign-by-build-mode-plugin.js +1 -0
- package/package.json +12 -5
- package/src/common/common-enum.ts +0 -33
- package/src/common/common-utils.ts +0 -26
- package/src/plugin/ascf-toolkit-hvigor-plugin.ts +0 -165
- package/src/plugin/installAscfHspPlugin.ts +0 -112
- package/src/plugin/modifyShareInfoPlugin.ts +0 -138
- package/src/plugin/sign-by-build-mode-plugin.ts +0 -27
- /package/{src → lib}/config.json +0 -0
package/gulpfile.mjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import gulp from 'gulp';
|
|
2
|
+
import ts from 'gulp-typescript';
|
|
3
|
+
import terser from 'gulp-terser';
|
|
4
|
+
import del from 'del';
|
|
5
|
+
|
|
6
|
+
const tsProject = ts.createProject('tsconfig.json');
|
|
7
|
+
|
|
8
|
+
function clean() {
|
|
9
|
+
return del(["./*ascf-toolkit*.tgz", "./lib"]);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function dev() {
|
|
13
|
+
return gulp
|
|
14
|
+
.src("src/**/*.ts")
|
|
15
|
+
.pipe(gulp.dest("./lib"));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function releaseTs() {
|
|
19
|
+
return gulp.src('src/**/*.ts')
|
|
20
|
+
.pipe(tsProject())
|
|
21
|
+
.pipe(terser())
|
|
22
|
+
.pipe(gulp.dest('./lib'));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function addResourse() {
|
|
26
|
+
return gulp.src("src/**/*.{png,jpg,jpeg,json,json5,ets,txt}").pipe(gulp.dest("./lib"));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
gulp.task("dev", gulp.series(clean, dev, addResourse));
|
|
30
|
+
|
|
31
|
+
gulp.task(
|
|
32
|
+
"release",
|
|
33
|
+
gulp.series(clean, releaseTs, addResourse),
|
|
34
|
+
);
|
package/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { default as ascfPlugin } from './
|
|
1
|
+
import { default as ascfPlugin } from './lib/plugin/ascf-toolkit-hvigor-plugin';
|
|
2
2
|
|
|
3
|
-
export { default as signByBuildModePlugin } from './
|
|
4
|
-
export { default as modifyShareInfoPlugin } from './
|
|
5
|
-
export { default as installAscfHspPlugin } from './
|
|
3
|
+
export { default as signByBuildModePlugin } from './lib/plugin/sign-by-build-mode-plugin';
|
|
4
|
+
export { default as modifyShareInfoPlugin } from './lib/plugin/modifyShareInfoPlugin';
|
|
5
|
+
export { default as installAscfHspPlugin } from './lib/plugin/installAscfHspPlugin';
|
|
6
6
|
export { ascfPlugin };
|
|
7
7
|
export default ascfPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var LogLevel,DevtoolEnum;Object.defineProperty(exports,"__esModule",{value:!0}),exports.DevtoolEnum=exports.LogLevel=void 0,function(e){e.DEBUG="debug",e.INFO="info",e.WARN="warn",e.ERROR="error"}(LogLevel||(exports.LogLevel=LogLevel={})),function(e){e.EVAL="eval",e.EVAL_CHEAP_SOURCE_MAP="eval-cheap-source-map",e.EVAL_CHEAP_MODULE_SOURCE_MAP="eval-cheap-module-source-map",e.EVAL_SOURCE_MAP="eval-source-map",e.CHEAP_SOURCE_MAP="cheap-source-map",e.CHEAP_MODULE_SOURCE_MAP="cheap-module-source-map",e.SOURCE_MAP="source-map",e.INLINE_CHEAP_SOURCE_MAP="inline-cheap-source-map",e.INLINE_CHEAP_MODULE_SOURCE_MAP="inline-cheap-module-source-map",e.INLINE_SOURCE_MAP="inline-source-map",e.EVAL_NOSOURCES_CHEAP_SOURCE_MAP="eval-nosources-cheap-source-map",e.EVAL_NOSOURCES_CHEAP_MODULE_SOURCE_MAP="eval-nosources-cheap-module-source-map",e.EVAL_NOSOURCES_SOURCE_MAP="eval-nosources-source-map",e.INLINE_NOSOURCES_CHEAP_SOURCE_MAP="inline-nosources-cheap-source-map",e.INLINE_NOSOURCES_CHEAP_MODULE_SOURCE_MAP="inline-nosources-cheap-module-source-map",e.INLINE_NOSOURCES_SOURCE_MAP="inline-nosources-source-map",e.NOSOURCES_CHEAP_SOURCE_MAP="nosources-cheap-source-map",e.NOSOURCES_CHEAP_MODULE_SOURCE_MAP="nosources-cheap-module-source-map",e.NOSOURCES_SOURCE_MAP="nosources-source-map",e.HIDDEN_NOSOURCES_CHEAP_SOURCE_MAP="hidden-nosources-cheap-source-map",e.HIDDEN_NOSOURCES_CHEAP_MODULE_SOURCE_MAP="hidden-nosources-cheap-module-source-map",e.HIDDEN_NOSOURCES_SOURCE_MAP="hidden-nosources-source-map",e.HIDDEN_CHEAP_SOURCE_MAP="hidden-cheap-source-map",e.HIDDEN_CHEAP_MODULE_SOURCE_MAP="hidden-cheap-module-source-map",e.HIDDEN_SOURCE_MAP="hidden-source-map"}(DevtoolEnum||(exports.DevtoolEnum=DevtoolEnum={}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.writeJson=exports.readJson=void 0,exports.deepMerge=deepMerge;const fs_1=__importDefault(require("fs"));function deepMerge(e,...t){if(!t.length)return e;const r=t.shift();if(!r)return deepMerge(e,...t);for(const t of Object.keys(r)){const s=r[t],o=e[t];isObject(s)&&t in e&&isObject(o)?deepMerge(o,s):e[t]=s}return deepMerge(e,...t)}function isObject(e){return"[object Object]"===Object.prototype.toString.call(e)}const readJson=e=>JSON.parse(fs_1.default.readFileSync(e,"utf-8"));exports.readJson=readJson;const writeJson=(e,t)=>fs_1.default.writeFileSync(e,JSON.stringify(t),"utf-8");exports.writeJson=writeJson;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,o,t,i){return new(t||(t=Promise))((function(r,n){function s(e){try{g(i.next(e))}catch(e){n(e)}}function l(e){try{g(i.throw(e))}catch(e){n(e)}}function g(e){var o;e.done?r(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(s,l)}g((i=i.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"),property_get_1=require("@ohos/hvigor-ohos-plugin/src/sdk/lib/property-get"),property_const_1=require("@ohos/hvigor-ohos-plugin/src/const/property-const"),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")),os_1=__importDefault(require("os")),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,t;const i=`${getNodeExe()} ${getAscfScript()} ${null!==(t=null===(o=null===(e=hvigor_1.hvigor.getParameter())||void 0===e?void 0:e.getExtParams())||void 0===o?void 0:o.args)&&void 0!==t?t:""}`;logger.info(`start exec ascf cli: ${i}`);try{yield executeCommand(i,logger.getLevel().levelStr.toLowerCase()),logger.info("ascf cli completed")}catch(e){logger.error("ascf cli error",e)}}))}})}function ascfToolkitHvigorPlugin(e){return{pluginId:"ascfToolkitHvigorPlugin",apply(o){const t=hvigor_1.hvigor.getParameter(),i=null==t?void 0:t.getExtParams(),r=getProjectConfigJson(o.getContext(hvigor_ohos_plugin_1.OhosPluginId.OHOS_APP_PLUGIN).getProjectPath()),n=(0,common_utils_1.deepMerge)(DEFAULT_OPTIONS,r,e,i);logger.debug(`ascfToolkitHvigorPlugin options: ${JSON.stringify(n)}`),hvigor_1.hvigor.nodesEvaluated((()=>__awaiter(this,void 0,void 0,(function*(){var e;yield execPlugin(n,o);try{if(hvigor_1.hvigor.isCommandEntryTask("GetHvigorDepsCachesDir"))o.registerTask({name:"GetHvigorDepsCachesDir",run(){console.log("ASCF_GET_HVIGOR_DEPS_CACHES_DIR="+ascf_toolkit_1.default.getAscfToolkitDirname())}});else if(hvigor_1.hvigor.isCommandEntryTask("buildNpm"))ascfToolkitHvigorBuildNpm(o);else if(hvigor_1.hvigor.isCommandEntryTask("ascf"))ascfToolkitHvigorCli(o);else{if(n.skipAscfCompile)return void logger.debug("skipAscfCompile");(null===(e=hvigor_1.hvigor.getCommandEntryTask())||void 0===e?void 0:e.length)||(logger.debug("start exec ascf quickGenSub"),yield ascf_toolkit_1.default.quickGenerateSubpackage(),logger.debug("ascf quickGenSub completed"));const t=o.getContext(hvigor_ohos_plugin_1.OhosPluginId.OHOS_APP_PLUGIN);o.subNodes((e=>{const o=e.getContext(hvigor_ohos_plugin_1.OhosPluginId.OHOS_HAP_PLUGIN);o&&"entry"===o.getModuleType()&&e.registerTask({name:"ascfCompile",run(){return __awaiter(this,void 0,void 0,(function*(){var e;logger.debug("start exec ascf compile");const o=t.getBuildMode();let i=`${getNodeExe()} ${getAscfScript()} compile -c ${"debug"===o?"-m":""} ${t.getProjectPath()}`;const r=logger.getLevel().levelStr.toLowerCase();n.debug&&r===common_enum_1.LogLevel.DEBUG&&(i+=" --debug"),n.compilerOptions.swc&&(i+=" --swc");const s=null===(e=n.devtool)||void 0===e?void 0:e.toLowerCase();s&&(i+=` --devtool=${s}`);i+=` --logging=${(n.logging?n.logging:r).toLowerCase()}`,n.templateHoist&&(i+=" --templateHoist"),i+=` --skipApiValidator=${n.skipApiValidator}`,i+=` --disableSubpackages=${n.disableSubpackages}`,logger.debug(i),yield executeCommand(i,r),logger.debug("ascf compile completed")}))},dependencies:["default@PreBuild"],postDependencies:["assembleHap"]})}))}}catch(e){logger.errorExit(new Error(String(e)))}}))))}}}function execPlugin(e,o){return __awaiter(this,void 0,void 0,(function*(){const t=hvigor_1.hvigor.getNodeByName("entry");t&&e.fixSharedHsp&&(yield(0,modifyShareInfoPlugin_1.doModifyShareInfoPlugin)(t).catch((e=>logger.error(e)))),t&&e.installAscfHsp&&(yield(0,installAscfHspPlugin_1.doInstallAscfHspPlugin)(o).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(((t,i)=>{var r,n;const s=(0,child_process_1.exec)(e);null===(r=s.stdout)||void 0===r||r.on("data",(e=>{printLogger(e,o)})),null===(n=s.stderr)||void 0===n||n.on("error",(e=>{i(e)})),s.on("close",(e=>{t(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 getNodeExe(){const e=(new property_get_1.Property).getProperty(property_const_1.PropertyConst.NPM_DIR),o=os_1.default.platform();let t="node";return"win32"===o?t=path_1.default.join(e,"node.exe"):"darwin"!==o&&"linux"!==o||(t=path_1.default.join(e,"node")),fs_1.default.existsSync(t)?adjustPathByPlatform(t):"node"}function getAscfScript(){return adjustPathByPlatform(path_1.default.join(ascf_toolkit_1.default.getAscfToolkitDirname(),"bin","ascf.js"))}function adjustPathByPlatform(e){return"win32"===os_1.default.platform()?`"${e}"`:e}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,t,n,o){return new(n||(n=Promise))((function(s,r){function l(e){try{a(o.next(e))}catch(e){r(e)}}function i(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,i)}a((o=o.apply(e,t||[])).next())}))},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.doInstallAscfHspPlugin=doInstallAscfHspPlugin,exports.default=installAscfHspPlugin;const hvigor_1=require("@ohos/hvigor"),hvigor_ohos_plugin_1=require("@ohos/hvigor-ohos-plugin"),child_process_1=require("child_process"),path_1=__importDefault(require("path")),fs_1=__importDefault(require("fs")),logger=hvigor_1.HvigorLogger.getLogger("installAscfHspPlugin");function execSafe(e){var t;try{return null===(t=(0,child_process_1.execSync)(e))||void 0===t?void 0:t.toString("utf8")}catch(e){logger.warn("exec cmd error",e)}}function checkProjectAscfVer(){var e;logger.debug("Check project ascf dependency version.");const t=hvigor_1.hvigor.getNodeByName("entry");let n=path_1.default.resolve(null==t?void 0:t.getNodePath(),"./oh-package.json");if(!fs_1.default.existsSync(n)&&(n+="5",!fs_1.default.existsSync(n)))return logger.warn(`Check oh-package failed. Not found ${n}.`),!1;const o=null===(e=JSON.parse(fs_1.default.readFileSync(n).toString()))||void 0===e?void 0:e.dependencies;return logger.debug(`ohPkgDeps: ${JSON.stringify(o)}`),!!Object.prototype.hasOwnProperty.call(o,"@atomicservice/ascf")}function checkAscfHsp(e){var t;logger.debug(`Check and install ${e} for local development`);const n=null!==(t=execSafe("hdc shell bm dump-shared -a"))&&void 0!==t?t:"";if(new RegExp(`${e}(\\r?\\n|$)`).test(n)){const t=execSafe(`hdc shell "bm dump-shared -n ${e} | grep versionName"`);return logger.debug(`found ${e} ${t}`),!0}return!1}function doInstallAscfHsp(e,t){const n=checkProjectAscfVer(),o=n?"com.huawei.hms.ascf":"com.huawei.hms.ascfruntime",s=`${o} install failed, please open helloUniapp manually.`;if(checkAscfHsp(o))return void e();logger.debug(`trying to install ${o}`);const r=path_1.default.resolve(__dirname,"../config.json"),l=JSON.parse(fs_1.default.readFileSync(r).toString()),i=execSafe(`hdc shell aa start -b com.huawei.hmos.browser -a MainAbility -A ohos.want.action.viewData -U "${n?l.ascfHspUrl:l.ascfRuntimeHspUrl}"`);if(!(null==i?void 0:i.includes("successfully")))return logger.warn(`${s} errorInfo=${i}`),void t(s);logger.debug("begin to wait install hsp");let a=0,c=setInterval((()=>{const n=checkAscfHsp(o);if(a++,n||a>5)return clearInterval(c),void(n?e():(logger.warn(s),t(s)))}),1e3)}function doInstallAscfHspPlugin(e){return __awaiter(this,void 0,void 0,(function*(){logger.debug("start exec install ascf hsp plugin");const t=e.getContext(hvigor_ohos_plugin_1.OhosPluginId.OHOS_APP_PLUGIN),n=hvigor_1.hvigor.getNodeByName("entry"),o=n.getContext(hvigor_ohos_plugin_1.OhosPluginId.OHOS_HAP_PLUGIN);"debug"===(null==t?void 0:t.getBuildMode())&&(null==o||o.targets((e=>{const t=e.getTargetName();logger.debug(`installAscfHspPlugin targetName:${t}`),n.registerTask({name:"installAscfHspTask",run:()=>new Promise(doInstallAscfHsp).catch((e=>logger.error(e))),dependencies:[`${t}@CompileArkTS`],postDependencies:[`${t}@PackageHap`]})})),logger.debug("exec install ascf hsp plugin completed"))}))}function installAscfHspPlugin(){return{pluginId:"installAscfHspPlugin",apply:doInstallAscfHspPlugin}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(l,d){function i(e){try{a(t.next(e))}catch(e){d(e)}}function u(e){try{a(t.throw(e))}catch(e){d(e)}}function a(e){var o;e.done?l(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(i,u)}a((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");function addShareInfo(e,o){var n,t,l,d,i,u,a,r;logger.debug(`addShareInfo srcPath ${o}`);let s=path_1.default.resolve(o,"src/main/module.json");if(!fs_1.default.existsSync(s)&&(s+="5",!fs_1.default.existsSync(s)))return;logger.debug(`addShareInfo modulePath ${s}`);const f=(0,common_utils_1.readJson)(s);logger.debug(`addShareInfo srcModuleJson ${JSON.stringify(f,null," ")}`);const g=null!==(t=null===(n=null==f?void 0:f.app)||void 0===n?void 0:n.bundleName)&&void 0!==t?t:"",m=null!==(d=null===(l=null==f?void 0:f.app)||void 0===l?void 0:l.versionCode)&&void 0!==d?d:0,h=null!==(u=null===(i=null==f?void 0:f.module)||void 0===i?void 0:i.name)&&void 0!==u?u:"",c=null!==(r=null===(a=null==f?void 0:f.module)||void 0===a?void 0:a.type)&&void 0!==r?r:"";if("shared"===c&&g&&0!==m&&h){const o={bundleName:g,moduleName:h,versionCode:m};e.push(o)}else if("shared"===c&&!g&&0===m&&h){const o={moduleName:h};e.push(o)}}function getSharedInfos(e){const o=[],n=path_1.default.resolve(e,"oh_modules"),t=fs_1.default.readdirSync(n);return logger.debug(`moduleFileNames=${t}`),t.filter((e=>e&&!e.startsWith("."))).forEach((t=>{if(logger.debug(`moduleFileName=${t}`),t.startsWith("@")){const n=path_1.default.resolve(e,`oh_modules/${t}`),l=fs_1.default.readdirSync(n);logger.debug(`cloudModuleFileNames=${l}`),l.forEach((e=>{logger.debug(`cloudModuleFileName=${e}`),addShareInfo(o,path_1.default.resolve(n,`${e}`))}))}else addShareInfo(o,path_1.default.resolve(n,`${t}`))})),o}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=getSharedInfos(e);if(!(null==n?void 0:n.length))return void logger.debug("dependencies is empty");const t=fs_1.default.readdirSync(o);logger.debug("buildFileNames:"+t),t.filter((e=>e)).forEach((e=>{logger.debug("productName: "+e);const t=path_1.default.resolve(o,`${e}/intermediates/res/${e}/module.json`);if(logger.debug("module.json filePath: "+t),fs_1.default.existsSync(t)){const e=(0,common_utils_1.readJson)(t);e.module.dependencies=n,(0,common_utils_1.writeJson)(t,e),logger.debug(`final moduleJson ${JSON.stringify(e,null," ")}`)}else logger.debug("module.json filePath: "+t+" is not Exists");const l=path_1.default.resolve(o,`${e}/intermediates/hap_metadata/${e}/output_metadata.json`);if(logger.debug("output_metadata.json filePath: "+l),fs_1.default.existsSync(l)){const e=(0,common_utils_1.readJson)(l);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)(l,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(`targetName:${n}`),e.registerTask({name:"modifyShareInfoTask",run:e=>{logger.debug("moduleName="+e.moduleName+" modulePath="+e.modulePath),updateSharedInfo(e.modulePath)},dependencies:[`${n}@CompileArkTS`],postDependencies:[`${n}@PackageHap`]})})),logger.debug("exec modify share info plugin completed")}))}function modifyShareInfoPlugin(){return{pluginId:"modifyShareInfoPlugin",apply:doModifyShareInfoPlugin}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const hvigor_1=require("@ohos/hvigor"),hvigor_ohos_plugin_1=require("@ohos/hvigor-ohos-plugin"),logger=hvigor_1.HvigorLogger.getLogger("signByBuildModePlugin");function signByBuildMode(e,g){return{pluginId:"signByBuildMode",apply(o){try{logger.debug("start exec sign by build mode");const i=o.getContext(hvigor_ohos_plugin_1.OhosPluginId.OHOS_APP_PLUGIN),r="debug"===i.getBuildMode()?e:g;logger.debug("signByBuildMode change signingConfig="+r);const n=i.getBuildProfileOpt();n.app.products[0].signingConfig=r,i.setBuildProfileOpt(n),logger.debug("sign by build mode completed")}catch(e){logger.errorExit(new Error(String(e)))}}}}exports.default=signByBuildMode;
|
package/package.json
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomicservice/ascf-toolkit-hvigor-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5-beta.4",
|
|
4
4
|
"title": "ASCF toolkit hvigor plugin for atomicservice",
|
|
5
5
|
"description": "ASCF toolkit hvigor plugin for atomicservice",
|
|
6
6
|
"main": "index.ts",
|
|
7
7
|
"author": "atomicservice",
|
|
8
|
-
"type": "
|
|
8
|
+
"type": "commonjs",
|
|
9
9
|
"devDependencies": {
|
|
10
10
|
"@ohos/hvigor": "5.8.9",
|
|
11
|
-
"@ohos/hvigor-ohos-plugin": "5.8.9"
|
|
11
|
+
"@ohos/hvigor-ohos-plugin": "5.8.9",
|
|
12
|
+
"del": "6.1.0",
|
|
13
|
+
"gulp": "4.0.0",
|
|
14
|
+
"gulp-typescript": "5.0.1",
|
|
15
|
+
"gulp-terser": "2.1.0"
|
|
12
16
|
},
|
|
13
17
|
"dependencies": {
|
|
14
|
-
"@atomicservice/ascf-toolkit": "1.0.
|
|
18
|
+
"@atomicservice/ascf-toolkit": "1.0.5-beta.4"
|
|
15
19
|
},
|
|
16
20
|
"scripts": {
|
|
17
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
21
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
22
|
+
"dev": "gulp dev",
|
|
23
|
+
"build": "gulp release",
|
|
24
|
+
"release": "gulp release && npm pack"
|
|
18
25
|
},
|
|
19
26
|
"overrides": {
|
|
20
27
|
"minipass": "3.3.6",
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export enum LogLevel {
|
|
2
|
-
DEBUG = 'debug',
|
|
3
|
-
INFO = 'info',
|
|
4
|
-
WARN = 'warn',
|
|
5
|
-
ERROR = 'error'
|
|
6
|
-
}
|
|
7
|
-
export enum DevtoolEnum {
|
|
8
|
-
EVAL = 'eval',
|
|
9
|
-
EVAL_CHEAP_SOURCE_MAP = 'eval-cheap-source-map',
|
|
10
|
-
EVAL_CHEAP_MODULE_SOURCE_MAP = 'eval-cheap-module-source-map',
|
|
11
|
-
EVAL_SOURCE_MAP = 'eval-source-map',
|
|
12
|
-
CHEAP_SOURCE_MAP = 'cheap-source-map',
|
|
13
|
-
CHEAP_MODULE_SOURCE_MAP = 'cheap-module-source-map',
|
|
14
|
-
SOURCE_MAP = 'source-map',
|
|
15
|
-
INLINE_CHEAP_SOURCE_MAP = 'inline-cheap-source-map',
|
|
16
|
-
INLINE_CHEAP_MODULE_SOURCE_MAP = 'inline-cheap-module-source-map',
|
|
17
|
-
INLINE_SOURCE_MAP = 'inline-source-map',
|
|
18
|
-
EVAL_NOSOURCES_CHEAP_SOURCE_MAP = 'eval-nosources-cheap-source-map',
|
|
19
|
-
EVAL_NOSOURCES_CHEAP_MODULE_SOURCE_MAP = 'eval-nosources-cheap-module-source-map',
|
|
20
|
-
EVAL_NOSOURCES_SOURCE_MAP = 'eval-nosources-source-map',
|
|
21
|
-
INLINE_NOSOURCES_CHEAP_SOURCE_MAP = 'inline-nosources-cheap-source-map',
|
|
22
|
-
INLINE_NOSOURCES_CHEAP_MODULE_SOURCE_MAP = 'inline-nosources-cheap-module-source-map',
|
|
23
|
-
INLINE_NOSOURCES_SOURCE_MAP = 'inline-nosources-source-map',
|
|
24
|
-
NOSOURCES_CHEAP_SOURCE_MAP = 'nosources-cheap-source-map',
|
|
25
|
-
NOSOURCES_CHEAP_MODULE_SOURCE_MAP = 'nosources-cheap-module-source-map',
|
|
26
|
-
NOSOURCES_SOURCE_MAP = 'nosources-source-map',
|
|
27
|
-
HIDDEN_NOSOURCES_CHEAP_SOURCE_MAP = 'hidden-nosources-cheap-source-map',
|
|
28
|
-
HIDDEN_NOSOURCES_CHEAP_MODULE_SOURCE_MAP = 'hidden-nosources-cheap-module-source-map',
|
|
29
|
-
HIDDEN_NOSOURCES_SOURCE_MAP = 'hidden-nosources-source-map',
|
|
30
|
-
HIDDEN_CHEAP_SOURCE_MAP = 'hidden-cheap-source-map',
|
|
31
|
-
HIDDEN_CHEAP_MODULE_SOURCE_MAP = 'hidden-cheap-module-source-map',
|
|
32
|
-
HIDDEN_SOURCE_MAP = 'hidden-source-map',
|
|
33
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
type DeepPartial<T> = {
|
|
2
|
-
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
3
|
-
};
|
|
4
|
-
|
|
5
|
-
function deepMerge<T extends object>(target: T, source?: DeepPartial<T>): T {
|
|
6
|
-
if (!source) {
|
|
7
|
-
return target;
|
|
8
|
-
}
|
|
9
|
-
for (const key of Object.keys(source) as Array<keyof T>) {
|
|
10
|
-
const sourceValue = source[key];
|
|
11
|
-
const targetValue = target[key];
|
|
12
|
-
|
|
13
|
-
if (isObject(sourceValue) && key in target && isObject(targetValue)) {
|
|
14
|
-
deepMerge(targetValue as Object, sourceValue as DeepPartial<typeof targetValue>);
|
|
15
|
-
} else {
|
|
16
|
-
target[key] = sourceValue as T[keyof T];
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return target;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function isObject(target: any) {
|
|
23
|
-
return Object.prototype.toString.call(target) === '[object Object]';
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export { deepMerge };
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import {OhosAppContext, OhosHapContext, OhosPluginId} from '@ohos/hvigor-ohos-plugin';
|
|
2
|
-
import { Property } from '@ohos/hvigor-ohos-plugin/src/sdk/lib/property-get';
|
|
3
|
-
import { PropertyConst } from '@ohos/hvigor-ohos-plugin/src/const/property-const';
|
|
4
|
-
import { hvigor, HvigorLogger, HvigorNode, HvigorPlugin, Level } from '@ohos/hvigor';
|
|
5
|
-
import ascf from '@atomicservice/ascf-toolkit';
|
|
6
|
-
import { exec } from 'child_process';
|
|
7
|
-
import path from 'path';
|
|
8
|
-
import fs from 'fs';
|
|
9
|
-
import os from 'os';
|
|
10
|
-
import { DevtoolEnum, LogLevel } from '../common/common-enum';
|
|
11
|
-
import { deepMerge } from '../common/common-utils';
|
|
12
|
-
|
|
13
|
-
import { doModifyShareInfoPlugin } from './modifyShareInfoPlugin';
|
|
14
|
-
import { doInstallAscfHspPlugin } from './installAscfHspPlugin';
|
|
15
|
-
|
|
16
|
-
const logger = HvigorLogger.getLogger('ascfPlugin');
|
|
17
|
-
|
|
18
|
-
export interface AscfPluginOptions {
|
|
19
|
-
fixSharedHsp: boolean,
|
|
20
|
-
installAscfHsp: boolean,
|
|
21
|
-
debug: boolean,
|
|
22
|
-
logging?: LogLevel,
|
|
23
|
-
devtool?: DevtoolEnum,
|
|
24
|
-
compilerOptions: {
|
|
25
|
-
swc: boolean,
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const DEFAULT_OPTIONS: AscfPluginOptions = {
|
|
30
|
-
fixSharedHsp: true,
|
|
31
|
-
installAscfHsp: true,
|
|
32
|
-
debug: true,
|
|
33
|
-
compilerOptions: {
|
|
34
|
-
swc: false,
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export default function ascfToolkitHvigorPlugin(options?: AscfPluginOptions): HvigorPlugin {
|
|
39
|
-
return {
|
|
40
|
-
pluginId: 'ascfToolkitHvigorPlugin',
|
|
41
|
-
apply(node: HvigorNode) {
|
|
42
|
-
const opts = deepMerge(DEFAULT_OPTIONS, options);
|
|
43
|
-
hvigor.nodesEvaluated(async () => {
|
|
44
|
-
await execPlugin(opts, node);
|
|
45
|
-
|
|
46
|
-
try {
|
|
47
|
-
if (hvigor.isCommandEntryTask('GetHvigorDepsCachesDir')) {
|
|
48
|
-
node.registerTask({
|
|
49
|
-
name: 'GetHvigorDepsCachesDir',
|
|
50
|
-
run() {
|
|
51
|
-
console.log('ASCF_GET_HVIGOR_DEPS_CACHES_DIR=' + ascf.getAscfToolkitDirname());
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
} else {
|
|
55
|
-
logger.debug('start exec ascf quickGenSub');
|
|
56
|
-
await ascf.quickGenerateSubpackage();
|
|
57
|
-
logger.debug('ascf quickGenSub completed');
|
|
58
|
-
const appContext = node.getContext(OhosPluginId.OHOS_APP_PLUGIN) as OhosAppContext;
|
|
59
|
-
node.subNodes((subNode: HvigorNode) => {
|
|
60
|
-
const hapContext = subNode.getContext(OhosPluginId.OHOS_HAP_PLUGIN) as OhosHapContext;
|
|
61
|
-
if(hapContext && hapContext.getModuleType() === 'entry') {
|
|
62
|
-
subNode.registerTask({
|
|
63
|
-
// 任务名称
|
|
64
|
-
name: 'quickGenerateSubpackage',
|
|
65
|
-
// 任务执行逻辑主体函数
|
|
66
|
-
async run() {
|
|
67
|
-
logger.debug('start exec ascf compile');
|
|
68
|
-
const buildMode = appContext.getBuildMode();
|
|
69
|
-
const nodeExe = getNodeExe();
|
|
70
|
-
const ascfScript = getAscfScript();
|
|
71
|
-
let cmd = `${nodeExe} ${ascfScript} compile -c ${buildMode === 'debug' ? '-m' : ''} ${appContext.getProjectPath()}`;
|
|
72
|
-
|
|
73
|
-
const hvigorLevelStr = (logger.getLevel() as Level).levelStr.toLowerCase();
|
|
74
|
-
if (opts.debug && hvigorLevelStr === LogLevel.DEBUG) {
|
|
75
|
-
cmd += ' --debug';
|
|
76
|
-
}
|
|
77
|
-
if (opts.compilerOptions.swc) {
|
|
78
|
-
cmd += ' --swc';
|
|
79
|
-
}
|
|
80
|
-
const devtool = opts.devtool?.toLowerCase();
|
|
81
|
-
if (devtool) {
|
|
82
|
-
cmd += ` --devtool=${devtool}`;
|
|
83
|
-
}
|
|
84
|
-
const logLevel = (opts.logging ? opts.logging : hvigorLevelStr).toLowerCase();
|
|
85
|
-
cmd += ` --logging=${logLevel}`;
|
|
86
|
-
logger.debug(cmd);
|
|
87
|
-
await executeCommand(cmd, hvigorLevelStr);
|
|
88
|
-
logger.debug('ascf compile completed');
|
|
89
|
-
},
|
|
90
|
-
// 配置前置任务依赖
|
|
91
|
-
dependencies: ['default@PreBuild'],
|
|
92
|
-
// 配置任务的后置任务依赖
|
|
93
|
-
postDependencies: ['assembleHap']
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
} catch (err: any) {
|
|
99
|
-
logger.errorExit(new Error(err));
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async function execPlugin(opts: AscfPluginOptions, node: HvigorNode) {
|
|
107
|
-
const entryNode = hvigor.getNodeByName('entry');
|
|
108
|
-
if (entryNode && opts.fixSharedHsp) {
|
|
109
|
-
await doModifyShareInfoPlugin(entryNode).catch(err => logger.error(err));
|
|
110
|
-
}
|
|
111
|
-
if (entryNode && opts.installAscfHsp) {
|
|
112
|
-
await doInstallAscfHspPlugin(node).catch(err => logger.error(err));
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function executeCommand(command: string, levelStr: string) {
|
|
117
|
-
return new Promise((resolve, reject) => {
|
|
118
|
-
exec(command, (error: any, stdout: string, stderr: string) => {
|
|
119
|
-
printLogger(stdout, levelStr);
|
|
120
|
-
if (error) {
|
|
121
|
-
reject(error);
|
|
122
|
-
} else {
|
|
123
|
-
resolve(stdout);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function printLogger(stdout: string, levelStr: string) {
|
|
130
|
-
if (stdout.length === 0) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
if (levelStr === LogLevel.INFO) {
|
|
134
|
-
logger.info(stdout);
|
|
135
|
-
} else if (levelStr === LogLevel.WARN) {
|
|
136
|
-
logger.warn(stdout);
|
|
137
|
-
} else if (levelStr === LogLevel.ERROR) {
|
|
138
|
-
logger.error(stdout);
|
|
139
|
-
} else {
|
|
140
|
-
logger.debug(stdout);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function getNodeExe() {
|
|
145
|
-
const property: Property = new Property();
|
|
146
|
-
const nodeDir = property.getProperty(PropertyConst.NPM_DIR);
|
|
147
|
-
const platform = os.platform();
|
|
148
|
-
let got = 'node';
|
|
149
|
-
|
|
150
|
-
if (platform === 'win32') {
|
|
151
|
-
got = path.join(nodeDir, 'node.exe');
|
|
152
|
-
} else if (platform === 'darwin' || platform === 'linux') {
|
|
153
|
-
got = path.join(nodeDir, 'node');
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return fs.existsSync(got) ? adjustPathByPlatform(got) : 'node';
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function getAscfScript() {
|
|
160
|
-
return adjustPathByPlatform(path.join(ascf.getAscfToolkitDirname(), 'bin', 'ascf.js'));
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function adjustPathByPlatform(path: string) {
|
|
164
|
-
return os.platform() === 'win32' ? `\"${path}\"` : path;
|
|
165
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import type { HvigorNode, HvigorPlugin } from '@ohos/hvigor';
|
|
2
|
-
import { hvigor, HvigorLogger } from '@ohos/hvigor';
|
|
3
|
-
import { OhosAppContext, OhosHapContext, OhosPluginId, Target } from '@ohos/hvigor-ohos-plugin';
|
|
4
|
-
import { execSync } from 'child_process';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import fs from 'fs';
|
|
7
|
-
|
|
8
|
-
const logger = HvigorLogger.getLogger('installAscfHspPlugin');
|
|
9
|
-
|
|
10
|
-
function execSafe(cmd: string) {
|
|
11
|
-
try {
|
|
12
|
-
return execSync(cmd)?.toString('utf8');
|
|
13
|
-
} catch (e) {
|
|
14
|
-
logger.warn('exec cmd error', e);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function checkProjectAscfVer() {
|
|
19
|
-
logger.debug(`Check project ascf dependency version.`);
|
|
20
|
-
const node = hvigor.getNodeByName('entry');
|
|
21
|
-
let ohPkgFile = path.resolve(node?.getNodePath(), './oh-package.json');
|
|
22
|
-
if (!fs.existsSync(ohPkgFile)) {
|
|
23
|
-
ohPkgFile += '5'; // trying module.json5
|
|
24
|
-
if (!fs.existsSync(ohPkgFile)) {
|
|
25
|
-
logger.warn(`Check oh-package failed. Not found ${ohPkgFile}.`);
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
const ohPkgDeps = JSON.parse(fs.readFileSync(ohPkgFile).toString())?.dependencies;
|
|
30
|
-
logger.debug(`ohPkgDeps: ${JSON.stringify(ohPkgDeps)}`);
|
|
31
|
-
return !!Object.prototype.hasOwnProperty.call(ohPkgDeps, '@atomicservice/ascf');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function checkAscfHsp(ascfBundleName: string) {
|
|
35
|
-
logger.debug(`Check and install ${ascfBundleName} for local development`);
|
|
36
|
-
const sharedInfo: string = execSafe(`hdc shell bm dump-shared -a`) ?? '';
|
|
37
|
-
if (new RegExp(`${ascfBundleName}(\\r?\\n|$)`).test(sharedInfo)) {
|
|
38
|
-
const verInfo = execSafe(`hdc shell "bm dump-shared -n ${ascfBundleName} | grep versionName"`);
|
|
39
|
-
logger.debug(`found ${ascfBundleName} ${verInfo}`);
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function doInstallAscfHsp(resolve: any, reject: any) {
|
|
46
|
-
const isDepOldAscf: boolean = checkProjectAscfVer();
|
|
47
|
-
const ascfBundleName: string = isDepOldAscf ? 'com.huawei.hms.ascf' : 'com.huawei.hms.ascfruntime';
|
|
48
|
-
const errMsg: string = `${ascfBundleName} install failed, please open helloUniapp manually.`;
|
|
49
|
-
|
|
50
|
-
if (checkAscfHsp(ascfBundleName)) {
|
|
51
|
-
resolve();
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
logger.debug(`trying to install ${ascfBundleName}`);
|
|
56
|
-
const configJsonPath = path.resolve(__dirname, '../config.json');
|
|
57
|
-
const configJson = JSON.parse(fs.readFileSync(configJsonPath).toString());
|
|
58
|
-
const hspUrl = isDepOldAscf ? configJson.ascfHspUrl : configJson.ascfRuntimeHspUrl;
|
|
59
|
-
const startInfo = execSafe(`hdc shell aa start -b com.huawei.hmos.browser -a MainAbility -A ohos.want.action.viewData -U "${hspUrl}"`);
|
|
60
|
-
if (!startInfo?.includes('successfully')) {
|
|
61
|
-
logger.warn(`${errMsg} errorInfo=${startInfo}`);
|
|
62
|
-
reject(errMsg);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
logger.debug(`begin to wait install hsp`);
|
|
67
|
-
let needWait = 0;
|
|
68
|
-
let timer = setInterval(() => {
|
|
69
|
-
const found = checkAscfHsp(ascfBundleName);
|
|
70
|
-
needWait++;
|
|
71
|
-
|
|
72
|
-
if (found || needWait > 5) {
|
|
73
|
-
clearInterval(timer);
|
|
74
|
-
if (found) {
|
|
75
|
-
resolve();
|
|
76
|
-
} else {
|
|
77
|
-
logger.warn(errMsg);
|
|
78
|
-
reject(errMsg);
|
|
79
|
-
}
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
}, 1000);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export async function doInstallAscfHspPlugin(rootNode: HvigorNode): Promise<void> {
|
|
86
|
-
logger.debug('start exec install ascf hsp plugin');
|
|
87
|
-
const appContext = rootNode.getContext(OhosPluginId.OHOS_APP_PLUGIN) as OhosAppContext;
|
|
88
|
-
const currentNode = hvigor.getNodeByName('entry')!;
|
|
89
|
-
const hapContext = currentNode.getContext(OhosPluginId.OHOS_HAP_PLUGIN) as OhosHapContext;
|
|
90
|
-
if (appContext?.getBuildMode() !== 'debug') {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
hapContext?.targets((target: Target) => {
|
|
95
|
-
const targetName = target.getTargetName();
|
|
96
|
-
logger.debug(`installAscfHspPlugin targetName:${targetName}`);
|
|
97
|
-
currentNode.registerTask({
|
|
98
|
-
name: 'installAscfHspTask',
|
|
99
|
-
run: () => new Promise<void>(doInstallAscfHsp).catch((err) => logger.error(err)),
|
|
100
|
-
dependencies: [`${targetName}@CompileArkTS`],
|
|
101
|
-
postDependencies: [`${targetName}@PackageHap`]
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
logger.debug('exec install ascf hsp plugin completed');
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export default function installAscfHspPlugin(): HvigorPlugin {
|
|
108
|
-
return {
|
|
109
|
-
pluginId: 'installAscfHspPlugin',
|
|
110
|
-
apply: doInstallAscfHspPlugin,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import type { HvigorNode, HvigorPlugin, HvigorTaskContext } from '@ohos/hvigor';
|
|
2
|
-
import { HvigorLogger } from '@ohos/hvigor';
|
|
3
|
-
import { OhosHapContext, OhosPluginId, Target } from '@ohos/hvigor-ohos-plugin';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import fs from 'fs';
|
|
6
|
-
|
|
7
|
-
const logger = HvigorLogger.getLogger('modifyShareInfoPlugin');
|
|
8
|
-
|
|
9
|
-
const readJson = (filepath: string) => JSON.parse(fs.readFileSync(filepath, 'utf-8'));
|
|
10
|
-
const writeJson = (filepath: string, str: any) => fs.writeFileSync(filepath, JSON.stringify(str), 'utf-8');
|
|
11
|
-
|
|
12
|
-
function addShareInfo(sharedInfos: any, srcPath: string) {
|
|
13
|
-
logger.debug(`addShareInfo srcPath ${srcPath}`);
|
|
14
|
-
let modulePath = path.resolve(srcPath, 'src/main/module.json');
|
|
15
|
-
if (!fs.existsSync(modulePath)) {
|
|
16
|
-
modulePath += '5'; // trying module.json5
|
|
17
|
-
if (!fs.existsSync(modulePath)) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
logger.debug(`addShareInfo modulePath ${modulePath}`);
|
|
22
|
-
const srcModuleJson = readJson(modulePath);
|
|
23
|
-
logger.debug(`addShareInfo srcModuleJson ${JSON.stringify(srcModuleJson, null, ' ')}`);
|
|
24
|
-
const srcBundleName = srcModuleJson?.app?.bundleName ?? '';
|
|
25
|
-
const srcVersionCode = srcModuleJson?.app?.versionCode ?? 0;
|
|
26
|
-
const srcModuleName = srcModuleJson?.module?.name ?? '';
|
|
27
|
-
const srcModuleType = srcModuleJson?.module?.type ?? '';
|
|
28
|
-
if (srcModuleType === 'shared' && srcBundleName && srcVersionCode !== 0 && srcModuleName) {
|
|
29
|
-
const shareInfo = {
|
|
30
|
-
'bundleName': srcBundleName,
|
|
31
|
-
'moduleName': srcModuleName,
|
|
32
|
-
'versionCode': srcVersionCode
|
|
33
|
-
};
|
|
34
|
-
sharedInfos.push(shareInfo);
|
|
35
|
-
} else if (srcModuleType === 'shared' && !srcBundleName && srcVersionCode === 0 && srcModuleName) {
|
|
36
|
-
const shareInfo = {
|
|
37
|
-
'moduleName': srcModuleName,
|
|
38
|
-
};
|
|
39
|
-
sharedInfos.push(shareInfo);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
function getSharedInfos(modulePath: string): Array<object> {
|
|
44
|
-
const sharedInfos: any = [];
|
|
45
|
-
const moduleFilePath = path.resolve(modulePath, `oh_modules`);
|
|
46
|
-
const moduleFileNames = fs.readdirSync(moduleFilePath);
|
|
47
|
-
logger.debug(`moduleFileNames=${moduleFileNames}`);
|
|
48
|
-
|
|
49
|
-
moduleFileNames.filter(v => v && !v.startsWith('.')).forEach((moduleFileName) => {
|
|
50
|
-
logger.debug(`moduleFileName=${moduleFileName}`);
|
|
51
|
-
|
|
52
|
-
if (moduleFileName.startsWith('@')) {
|
|
53
|
-
const cloudModuleFilePath = path.resolve(modulePath, `oh_modules/${moduleFileName}`);
|
|
54
|
-
const cloudModuleFileNames = fs.readdirSync(cloudModuleFilePath);
|
|
55
|
-
logger.debug(`cloudModuleFileNames=${cloudModuleFileNames}`);
|
|
56
|
-
|
|
57
|
-
cloudModuleFileNames.forEach((cloudModuleFileName) => {
|
|
58
|
-
logger.debug(`cloudModuleFileName=${cloudModuleFileName}`);
|
|
59
|
-
addShareInfo(sharedInfos, path.resolve(cloudModuleFilePath, `${cloudModuleFileName}`));
|
|
60
|
-
});
|
|
61
|
-
} else {
|
|
62
|
-
addShareInfo(sharedInfos, path.resolve(moduleFilePath, `${moduleFileName}`));
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
return sharedInfos;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function updateSharedInfo(modulePath: string): void {
|
|
69
|
-
const buildFilePath = path.resolve(modulePath, `build`);
|
|
70
|
-
if (!fs.existsSync(buildFilePath)) {
|
|
71
|
-
logger.debug('buildFilePath:' + buildFilePath);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const dependencies = getSharedInfos(modulePath);
|
|
76
|
-
if (!dependencies?.length) {
|
|
77
|
-
logger.debug('dependencies is empty');
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const buildFileNames = fs.readdirSync(buildFilePath);
|
|
82
|
-
logger.debug('buildFileNames:' + buildFileNames);
|
|
83
|
-
buildFileNames.filter(v => v).forEach((productName) => {
|
|
84
|
-
logger.debug('productName: ' + productName);
|
|
85
|
-
const filePath = path.resolve(buildFilePath, `${productName}/intermediates/res/${productName}/module.json`);
|
|
86
|
-
logger.debug('module.json filePath: ' + filePath);
|
|
87
|
-
if (fs.existsSync(filePath)) {
|
|
88
|
-
const moduleJson = readJson(filePath);
|
|
89
|
-
moduleJson.module.dependencies = dependencies;
|
|
90
|
-
writeJson(filePath, moduleJson);
|
|
91
|
-
logger.debug(`final moduleJson ${JSON.stringify(moduleJson, null, ' ')}`);
|
|
92
|
-
} else {
|
|
93
|
-
logger.debug('module.json filePath: ' + filePath + ' is not Exists');
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const metadataPath = path.resolve(buildFilePath,
|
|
97
|
-
`${productName}/intermediates/hap_metadata/${productName}/output_metadata.json`);
|
|
98
|
-
logger.debug('output_metadata.json filePath: ' + metadataPath);
|
|
99
|
-
if (fs.existsSync(metadataPath)) {
|
|
100
|
-
const metadataJson = readJson(metadataPath);
|
|
101
|
-
metadataJson?.forEach((v: any) => {
|
|
102
|
-
const found = v.dependRemoteHsps?.findIndex((x: any) => x.hspName?.includes('ascf'));
|
|
103
|
-
if (v.dependRemoteHsps && found !== -1) {
|
|
104
|
-
v.dependRemoteHsps.splice(found, 1);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
writeJson(metadataPath, metadataJson);
|
|
108
|
-
logger.debug(`final metadataJson ${JSON.stringify(metadataJson, null, ' ')}`);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export async function doModifyShareInfoPlugin(currentNode: HvigorNode): Promise<void> {
|
|
114
|
-
logger.debug('start exec modify share info plugin');
|
|
115
|
-
const hapContext = currentNode.getContext(OhosPluginId.OHOS_HAP_PLUGIN) as OhosHapContext;
|
|
116
|
-
|
|
117
|
-
hapContext?.targets((target: Target) => {
|
|
118
|
-
const targetName = target.getTargetName();
|
|
119
|
-
logger.debug(`targetName:${targetName}`);
|
|
120
|
-
currentNode.registerTask({
|
|
121
|
-
name: 'modifyShareInfoTask',
|
|
122
|
-
run: (taskContext: HvigorTaskContext) => {
|
|
123
|
-
logger.debug('moduleName=' + taskContext.moduleName + ' modulePath=' + taskContext.modulePath);
|
|
124
|
-
updateSharedInfo(taskContext.modulePath);
|
|
125
|
-
},
|
|
126
|
-
dependencies: [`${targetName}@CompileArkTS`],
|
|
127
|
-
postDependencies: [`${targetName}@PackageHap`]
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
logger.debug('exec modify share info plugin completed');
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export default function modifyShareInfoPlugin(): HvigorPlugin {
|
|
134
|
-
return {
|
|
135
|
-
pluginId: 'modifyShareInfoPlugin',
|
|
136
|
-
apply: doModifyShareInfoPlugin,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { HvigorLogger, HvigorNode, HvigorPlugin } from '@ohos/hvigor';
|
|
2
|
-
import { OhosAppContext, OhosPluginId } from '@ohos/hvigor-ohos-plugin';
|
|
3
|
-
|
|
4
|
-
const logger = HvigorLogger.getLogger('signByBuildModePlugin');
|
|
5
|
-
|
|
6
|
-
function signByBuildMode(debugSignName: string, releaseSignName: string): HvigorPlugin {
|
|
7
|
-
return {
|
|
8
|
-
pluginId: 'signByBuildMode',
|
|
9
|
-
apply(node: HvigorNode) {
|
|
10
|
-
try {
|
|
11
|
-
logger.debug('start exec sign by build mode');
|
|
12
|
-
const appContext = node.getContext(OhosPluginId.OHOS_APP_PLUGIN) as OhosAppContext;
|
|
13
|
-
const signingConfig = appContext.getBuildMode() === 'debug' ? debugSignName : releaseSignName;
|
|
14
|
-
logger.debug('signByBuildMode change signingConfig=' + signingConfig);
|
|
15
|
-
|
|
16
|
-
const bpOpt = appContext.getBuildProfileOpt();
|
|
17
|
-
bpOpt.app.products![0].signingConfig = signingConfig;
|
|
18
|
-
appContext.setBuildProfileOpt(bpOpt);
|
|
19
|
-
logger.debug('sign by build mode completed');
|
|
20
|
-
} catch (err: any) {
|
|
21
|
-
logger.errorExit(new Error(err));
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export default signByBuildMode;
|
/package/{src → lib}/config.json
RENAMED
|
File without changes
|