UNPKG

@hap-toolkit/packager

Version:

@hap-toolkit/packager

3 lines (2 loc) 4.33 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.searchModuleImport=searchModuleImport,exports.updateManifest=updateManifest;var _sharedUtils=require("@hap-toolkit/shared-utils"),_compiler=require("@hap-toolkit/compiler");function frameworkInit(){global.framework={module:{base:"system",ext:"service"},reservedFeatures:[],reservedFeatureExclude:[],supportInCard:[],project:{manifestFilePath:null,featureList:[],module:{usedBaseAll:!1,usedExtAll:!1}}};["alarm","audio","barcode","bluetooth","brightness","calendar","cipher","clipboard","contact","device","fetch","file","geolocation","image","keyguard","media","network","notification","package","prompt","record","request","resident","sensor","share","shortcut","sms","storage","vibrator","volume","websocketfactory","webview","battery","wifi","mediaquery","zip","telecom","decode","screenshot","nfc","uploadtask","downloadtask","requesttask"].forEach((e=>{global.framework.reservedFeatures.push(`${global.framework.module.base}.${e}`)})),["account","alipay","ad","wxaccount","qqaccount","wbaccount","exchange","health","pay","push","qqaccount","share","stats","wbaccount","wxaccount","wxpay","biometriverify","texttoaudio"].forEach((e=>{global.framework.reservedFeatures.push(`${global.framework.module.ext}.${e}`)}));["app","model","router","configuration"].forEach((e=>{global.framework.reservedFeatureExclude.push(`${global.framework.module.base}.${e}`)}));["share","prompt","vibrator","fetch","storage","clipboard","geolocation","network","device","battery","calendar","package","app","router"].forEach((e=>{global.framework.supportInCard.push(`${global.framework.module.base}.${e}`)}))}function searchModuleImport(e,r={}){const o=[],a=new RegExp(`['"]@(${global.framework.module.base}|${global.framework.module.ext}).*?['"]`,"g"),t=new RegExp(`['"]@((${global.framework.module.base}|${global.framework.module.ext}).*?)['"]`);return(e.match(a)||[]).forEach((e=>{const a=(e.match(t)||[])[1];a===`@${global.framework.module.base}`?global.framework.project.module.usedBaseAll=!0:a===`@${global.framework.module.ext}`?global.framework.project.module.usedExtAll=!0:-1!==global.framework.reservedFeatures.indexOf(a)?-1===global.framework.project.featureList.indexOf(a)&&global.framework.project.featureList.push(a):r.uxType===_compiler.ENTRY_TYPE.CARD&&-1===global.framework.supportInCard.indexOf(a)?o.push({reason:`WARN: 您引入了卡片中未识别的 native 模块:${a}`}):-1!==global.framework.reservedFeatureExclude.indexOf(a)||o.push({reason:`WARN: 您引入了未识别的 native 模块:${a}`})})),{fileCont:e,logFeatureList:o}}function checkFeatureInCard(e={}){Object.keys(e).forEach((r=>{e[r].features&&e[r].features.every((e=>{-1===global.framework.supportInCard.indexOf(e.name)&&_sharedUtils.colorconsole.error(`WARN: manifest.json文件中引入了卡片${r}未识别的features:${e.name}`)}))}))}function populateWidgetFields(e){Object.keys(e).forEach((r=>{const o=e[r];o.path||(o.path=`/${r}`,_sharedUtils.colorconsole.warn(`WARN: manifest.json 文件中 widgets 字段 ${r} 缺少 path 属性,默认设置为卡片名 /${r}`)),o.type||(o.type="js",_sharedUtils.colorconsole.warn(`WARN: manifest.json 文件 widgets 字段下 ${r} 缺少 type 属性,默认设置为 js`)),"js"===o.type&&(o.minCardPlatformVersion?o.minPlatformVersion=o.minCardPlatformVersion:o.minPlatformVersion),"lite"!==o.type||o.minCardPlatformVersion||_sharedUtils.colorconsole.throw(`manifest.json 文件 widgets 字段下,轻卡 ${r} 缺少 minCardPlatformVersion 字段`)}))}function updateManifest(e,r){e.config=e.config||{},e.config.debug=r,e.minPlatformVersion&&"number"==typeof e.minPlatformVersion||(e.minPlatformVersion=1070),e.features=e.features||[],checkFeatureInCard(e.router.widgets||{}),populateWidgetFields(e.router.widgets||{});const o=[].concat(global.framework.project.featureList);e.features.forEach((e=>{const r=o.indexOf(e.name);-1!==r&&o.splice(r,1)}));const a=[];if(o.forEach((e=>{-1!==global.framework.reservedFeatures.indexOf(e)&&a.push(e)})),a.length>0){const r=a.map((function(e){return{name:e}}));e.features=e.features.concat(r);const o=a.join(", ");_sharedUtils.colorconsole.warn(`请在 manifest.json 文件里声明项目代码中用到的接口: ${o}\n`)}return e}frameworkInit(); //# sourceMappingURL=shared.js.map