UNPKG

@hap-toolkit/packager

Version:

@hap-toolkit/packager

3 lines (2 loc) 1.36 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DeviceTypePlugin=void 0;var _fs=_interopRequireDefault(require("fs")),_path=_interopRequireDefault(require("path")),_sharedUtils=require("@hap-toolkit/shared-utils"),_utils=require("../common/utils");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}class DeviceTypePlugin{constructor(e={}){this.options=e||{}}apply(e){const{options:t}=this,{srcPath:i,buildPath:s}=t,o=_path.default.join(i,"manifest.json");e.hooks.emit.tap("device type plugin",(()=>{try{if(_fs.default.existsSync(o)){const e=_fs.default.readFileSync(o,"utf-8"),t=JSON.parse(e.toString()),n=t.deviceTypeList||[];n.length>0&&n.map((e=>{const o=_path.default.join(i,`config-${e}.json`);if(_fs.default.existsSync(o)){const i=_fs.default.readFileSync(o,"utf-8");if(i.length>0){const o=JSON.parse(i),n=(0,_utils.mergeDeep)({},t,o),r=JSON.stringify(n,null,2),l=_path.default.join(s,`manifest-${e}.json`);_fs.default.writeFileSync(l,r)}}else _sharedUtils.colorconsole.warn(`"config-${e}.json"在src目录下不存在, 请检查你的项目代码与manifest.json的deviceTypeList数组是否正确`)}))}}catch(e){_sharedUtils.colorconsole.error(`编译设备config.json出现错误,错误信息: ${e.message}`)}}))}}exports.DeviceTypePlugin=DeviceTypePlugin; //# sourceMappingURL=device-type-plugin.js.map