@aiot-toolkit/packager
Version:
@aiot-toolkit/packager
3 lines (2 loc) • 1.33 kB
JavaScript
;var _fs=_interopRequireDefault(require("fs")),_path=_interopRequireDefault(require("path")),_sharedUtils=require("@aiot-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()),r=t.deviceTypeList||[];r.length>0&&r.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),r=(0,_utils.mergeDeep)({},t,o),n=JSON.stringify(r,null,2),a=_path.default.join(s,`manifest-${e}.json`);_fs.default.writeFileSync(a,n)}}else _sharedUtils.colorconsole.warn(`"config-${e}.json" does not exist in the src directory, please check whether your project code and the deviceTypeList array of manifest.json are correct`)}))}}catch(e){_sharedUtils.colorconsole.error(`An error occurred when compiling the config.json file of the device,error message: ${e.message}`)}}))}}module.exports=DeviceTypePlugin;
//# sourceMappingURL=device-type-plugin.js.map