@hap-toolkit/shared-utils
Advanced tools
Comparing version 1.9.9-beta.4 to 1.9.9
@@ -88,5 +88,5 @@ /* | ||
enableServerWatch: false, | ||
//是否处理.9图 | ||
// 是否处理.9图 | ||
trimDotnine: true, | ||
//自定义包名 默认为带版本号的包名 | ||
// 自定义包名 默认为带版本号的包名 | ||
buildNameFormat: compileOptionsMeta.buildNameFormat.DEFAULT, | ||
@@ -93,0 +93,0 @@ // IDE或者命令行传入的参数,用来参与构建IDE预览包 |
@@ -1,2 +0,2 @@ | ||
"use strict";var _fs=_interopRequireDefault(require("fs")),_path=_interopRequireDefault(require("path")),_index=require("../index"),_util=require("./util"),_eventBus=_interopRequireDefault(require("../../event-bus"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const{PACKAGER_BUILD_DONE:PACKAGER_BUILD_DONE}=_eventBus.default;function BuildModeManager(e){(0,_util.initProjectConfig)(e),this.setRoot(e)}BuildModeManager.prototype._read=function(){let e={};try{e=(0,_index.readJson)(this._configFile)}catch(e){console.log("ENOENT"===e.code?e.message:e)}e.modeOptions||(e.modeOptions={current:-1,list:[]});const t=e.modeOptions;return t.list=t.list.filter(e=>null!==e.id&&-1!==e.id),e},BuildModeManager.prototype._write=function(e){const t=e.modeOptions;t.list=t.list.filter(e=>null!==e.id&&-1!==e.id).reduce((e,t)=>(e.find(e=>e.id===t.id)||e.push(t),e),[]),this._configFile&&_fs.default.writeFileSync(this._configFile,JSON.stringify(e,null,2))},BuildModeManager.prototype.getConfig=function(){return this._read().modeOptions},BuildModeManager.prototype.getAllPages=function(){if(!this.root)return[];const e=_path.default.join(this.root,"src/manifest.json");try{const t=(0,_index.readJson)(e).router.pages||{};return Object.keys(t)}catch(e){return console.log("ENOENT"===e.code?e.message:e),[]}},BuildModeManager.prototype._addMode=function(e,t,i){const o=e.modeOptions;let n;return n=o.list.length?Math.max.apply(null,o.list.map(e=>e.id))+1:0,t.id=n,o.list.push(t),o.current=t.id,i||this._write(e),o},BuildModeManager.prototype.addMode=function(e){const t=this._read();return this._addMode(t,e,!1)},BuildModeManager.prototype.addModes=function(e){const t=this._read();return e.forEach(e=>{this._addMode(t,e,!0)}),this._write(t),t.modeOptions},BuildModeManager.prototype.delete=function(e){const t=this._read(),i=t.modeOptions,o=i.list.findIndex(t=>t.id===e);return i.current=-1,-1!==o&&(i.list.splice(o,1),this._write(t)),i},BuildModeManager.prototype.update=function(e){const t=this._read(),i=t.modeOptions,o=i.list.findIndex(t=>t.id===e.id);return-1!==o&&(i.list[o]=e),this._write(t),i},BuildModeManager.prototype.select=function(e){const t=this._read(),i=t.modeOptions;return-1!==i.list.findIndex(t=>t.id===e)&&(i.current=e,this._write(t),_eventBus.default.emit(PACKAGER_BUILD_DONE)),i},BuildModeManager.prototype.setToNormal=function(){const e=this._read(),t=e.modeOptions;return t.current=-1,this._write(e),_eventBus.default.emit(PACKAGER_BUILD_DONE),t},BuildModeManager.prototype.setRoot=function(e){if("string"==typeof e){return this.root=e,this._configFile=_path.default.resolve(e,_util.CONFIG_FILE),this._read().modeOptions}return null},module.exports=BuildModeManager; | ||
"use strict";var _fs=_interopRequireDefault(require("fs")),_path=_interopRequireDefault(require("path")),_index=require("../index"),_util=require("./util"),_eventBus=_interopRequireDefault(require("../../event-bus"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const{PACKAGER_BUILD_DONE:PACKAGER_BUILD_DONE}=_eventBus.default;function BuildModeManager(e){(0,_util.initProjectConfig)(e),this.setRoot(e)}BuildModeManager.prototype._read=function(){let e={};try{e=(0,_index.readJson)(this._configFile)}catch(e){console.log("ENOENT"===e.code?e.message:e)}e.modeOptions||(e.modeOptions={current:-1,list:[]});const t=e.modeOptions;return t.list=t.list.filter((e=>null!==e.id&&-1!==e.id)),e},BuildModeManager.prototype._write=function(e){const t=e.modeOptions;t.list=t.list.filter((e=>null!==e.id&&-1!==e.id)).reduce(((e,t)=>(e.find((e=>e.id===t.id))||e.push(t),e)),[]),this._configFile&&_fs.default.writeFileSync(this._configFile,JSON.stringify(e,null,2))},BuildModeManager.prototype.getConfig=function(){return this._read().modeOptions},BuildModeManager.prototype.getAllPages=function(){if(!this.root)return[];const e=_path.default.join(this.root,"src/manifest.json");try{const t=(0,_index.readJson)(e).router.pages||{};return Object.keys(t)}catch(e){return console.log("ENOENT"===e.code?e.message:e),[]}},BuildModeManager.prototype._addMode=function(e,t,i){const o=e.modeOptions;let n;return n=o.list.length?Math.max.apply(null,o.list.map((e=>e.id)))+1:0,t.id=n,o.list.push(t),o.current=t.id,i||this._write(e),o},BuildModeManager.prototype.addMode=function(e){const t=this._read();return this._addMode(t,e,!1)},BuildModeManager.prototype.addModes=function(e){const t=this._read();return e.forEach((e=>{this._addMode(t,e,!0)})),this._write(t),t.modeOptions},BuildModeManager.prototype.delete=function(e){const t=this._read(),i=t.modeOptions,o=i.list.findIndex((t=>t.id===e));return i.current=-1,-1!==o&&(i.list.splice(o,1),this._write(t)),i},BuildModeManager.prototype.update=function(e){const t=this._read(),i=t.modeOptions,o=i.list.findIndex((t=>t.id===e.id));return-1!==o&&(i.list[o]=e),this._write(t),i},BuildModeManager.prototype.select=function(e){const t=this._read(),i=t.modeOptions;return-1!==i.list.findIndex((t=>t.id===e))&&(i.current=e,this._write(t),_eventBus.default.emit(PACKAGER_BUILD_DONE)),i},BuildModeManager.prototype.setToNormal=function(){const e=this._read(),t=e.modeOptions;return t.current=-1,this._write(e),_eventBus.default.emit(PACKAGER_BUILD_DONE),t},BuildModeManager.prototype.setRoot=function(e){if("string"==typeof e){this.root=e,this._configFile=_path.default.resolve(e,_util.CONFIG_FILE);return this._read().modeOptions}return null},module.exports=BuildModeManager; | ||
//# sourceMappingURL=BuildModeManager.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.readJson=readJson,exports.initProjectConfig=initProjectConfig,exports.getLaunchPage=getLaunchPage,exports.CONFIG_FILE=void 0;var _fs=_interopRequireDefault(require("fs")),_path=_interopRequireDefault(require("path")),_config=_interopRequireDefault(require("../../config"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const CONFIG_FILE=".quickapp.preview.json";function readJson(e){try{return JSON.parse(_fs.default.readFileSync(e).toString())}catch(t){throw t instanceof SyntaxError?new SyntaxError(`解析 ${e} 失败, 格式错误`):t.message.startsWith("ENOENT:")?(t.message=`读取 ${e} 失败, 找不到该文件`,t):(console.error("读取 %s 失败",e),t)}}function initProjectConfig(e){const t=_path.default.join(e,CONFIG_FILE);_fs.default.existsSync(t)||_fs.default.writeFileSync(t,JSON.stringify({},null,2))}function getLaunchPage(){let e="";const t=_path.default.join(_config.default.projectPath,CONFIG_FILE);if(_fs.default.existsSync(t))try{const{modeOptions:r}=readJson(t);if(r&&"number"==typeof r.current&&r.list){const t=r.list.find(e=>e.id===r.current);t&&(e=`${t.pathName}?${t.query}`)}}catch(e){console.log("ENOENT"===e.code?e.message:e)}return e}exports.CONFIG_FILE=CONFIG_FILE; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CONFIG_FILE=void 0,exports.getLaunchPage=getLaunchPage,exports.initProjectConfig=initProjectConfig,exports.readJson=readJson;var _fs=_interopRequireDefault(require("fs")),_path=_interopRequireDefault(require("path")),_config=_interopRequireDefault(require("../../config"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const CONFIG_FILE=".quickapp.preview.json";function readJson(e){try{return JSON.parse(_fs.default.readFileSync(e).toString())}catch(t){throw t instanceof SyntaxError?new SyntaxError(`解析 ${e} 失败, 格式错误`):t.message.startsWith("ENOENT:")?(t.message=`读取 ${e} 失败, 找不到该文件`,t):(console.error("读取 %s 失败",e),t)}}function initProjectConfig(e){const t=_path.default.join(e,CONFIG_FILE);_fs.default.existsSync(t)||_fs.default.writeFileSync(t,JSON.stringify({},null,2))}function getLaunchPage(){let e="";const t=_path.default.join(_config.default.projectPath,CONFIG_FILE);if(_fs.default.existsSync(t))try{const{modeOptions:r}=readJson(t);if(r&&"number"==typeof r.current&&r.list){const t=r.list.find((e=>e.id===r.current));t&&(e=`${t.pathName}?${t.query}`)}}catch(e){console.log("ENOENT"===e.code?e.message:e)}return e}exports.CONFIG_FILE=CONFIG_FILE; | ||
//# sourceMappingURL=util.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.logWarn=logWarn,exports.mkdirsSync=mkdirsSync,exports.getIPv4IPAddress=getIPv4IPAddress,exports.getServerIPAndPort=getServerIPAndPort,exports.getDefaultServerHost=getDefaultServerHost,exports.getClientIPAddress=getClientIPAddress,exports.stripPrefixForIPV4MappedIPV6Address=stripPrefixForIPV4MappedIPV6Address,exports.outputQRCodeOnTerminal=outputQRCodeOnTerminal,exports.relateCwd=relateCwd,exports.equals=equals,exports.extend=extend,exports.renderString=renderString,exports.KnownError=KnownError,exports.setCustomConfig=setCustomConfig,exports.getProjectDslName=getProjectDslName,exports.getDeviceInfo=getDeviceInfo,exports.readJson=readJson,Object.defineProperty(exports,"getLaunchPage",{enumerable:!0,get:function(){return _util.getLaunchPage}}),exports.colorconsole=exports.logger=void 0;var _os=_interopRequireDefault(require("os")),_fs=_interopRequireDefault(require("fs")),_path=_interopRequireDefault(require("path")),_http=_interopRequireDefault(require("http")),_console=require("console"),_chalk=_interopRequireDefault(require("chalk")),_qrcodeTerminal=_interopRequireDefault(require("qrcode-terminal")),_config=_interopRequireDefault(require("../config")),_util=require("./buildMode/util");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const logLevelMap={};function prependLevel(e,r){if(!logLevelMap[e]){const r=e.toUpperCase();logLevelMap[e]=r}"string"==typeof r[0]&&r[0].length>1&&"["!==r[0][0]&&(r[0]=`[${logLevelMap[e]}] ${r[0]}`)}const logger={logs:[],add(e){this.logs.push(e)},clear(){this.logs=[]},get(){return this.logs.join("\n")}};exports.logger=logger;let originConsole=global.console,console=_console.Console?new _console.Console(process.stdout,process.stderr):originConsole;const colorconsole={attach(e){e&&_console.Console&&(console=new _console.Console(e,e))},trace(...e){prependLevel("trace",e),console.trace(...e)},log(...e){prependLevel("log",e),console.log(_chalk.default.green(...e))},info(...e){prependLevel("info",e),console.info(_chalk.default.green(...e))},warn(...e){prependLevel("warn",e),console.warn(_chalk.default.yellow.bold(...e))},error(...e){prependLevel("error",e),console.error(_chalk.default.red.bold(...e))},throw(...e){throw new Error(_chalk.default.red.bold(...e))}};function logWarn(e,r,t){r&&r.length&&r.forEach(r=>{const o=r.line&&r.column?"@"+r.line+":"+r.column:"";t||(r.reason.startsWith("ERROR")?colorconsole.error(e.resourcePath,o,r.reason):colorconsole.warn(e.resourcePath,o,r.reason))})}function mkdirsSync(e){return!!_fs.default.existsSync(e)||(mkdirsSync(_path.default.dirname(e))?(_fs.default.mkdirSync(e),!0):void 0)}function getIPv4IPAddress(){const e=_os.default.networkInterfaces();let r;for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t)){if(e[t].every(e=>!("IPv4"===e.family&&!e.internal&&"127.0.0.1"!==e.address)||(r=e,!1)),void 0!==r)break}return r&&r.address}function getServerIPAndPort(e){return(getIPv4IPAddress()||"127.0.0.1")+""+(80===e?"":":"+e)}function getDefaultServerHost(){return getServerIPAndPort(_config.default.server.port)}function getClientIPAddress(e){return stripPrefixForIPV4MappedIPV6Address(e.headers["x-forwarded-for"]||e.connection&&e.connection.remoteAddress||e.socket&&e.socket.remoteAddress||e.connection&&e.connection.socket&&e.connection.socket.remoteAddress)}function stripPrefixForIPV4MappedIPV6Address(e){return/^::1$/.test(e)&&(e="127.0.0.1"),/^::.{0,4}:(\d{1,3}\.){3}\d{1,3}/.test(e)&&(e=e.replace(/^.*:/,"")),e}function outputQRCodeOnTerminal(e){console.info("\n生成HTTP服务器的二维码: "+e),_qrcodeTerminal.default.generate(e,{small:!0})}function relateCwd(e){const r=_config.default.projectPath;return _path.default.relative(r,e)}function equals(e,r,t,...o){if(t){if(t(e,r,...o))return!0}const n=Object.prototype.toString.call(e);if(n!==Object.prototype.toString.call(r))return!1;if("[object Null]"===n||"[object Undefined]"===n)return!0;if("[object Object]"!==n&&"[object Array]"!==n)return Object(e).toString()===Object(r).toString();const s={};Object.keys(e).forEach(e=>s[e]=!0),Object.keys(r).forEach(e=>s[e]=!0);const l=Object.keys(s);for(let o=0;o<l.length;o++){const n=l[o];if(!equals(e[n],r[n],t,n))return!1}return!0}function extend(e,...r){if("function"==typeof Object.assign)Object.assign(e,...r);else{const t=r.shift();for(const r in t)e[r]=t[r];r.length&&extend(e,...r)}return e}function renderString(e,r){return e.replace(/{{(.*?)}}/gm,(e,t)=>(t=t.trim(),void 0!==r[t]?r[t]:t))}function KnownError(e){const r=new Error(e);return r.name="KnownError",r.__KNOWN=!0,r}function setCustomConfig(e,r){e=_config.default.projectPath=e||_config.default.projectPath;const t=_path.default.join(e,"quickapp.config.js");if(_fs.default.existsSync(t)){let e={};try{e=require(t)}catch(e){colorconsole.error("读取项目自定义配置文件出错: "+e.message)}const r=Object.assign(_config.default.server,e.server);Object.assign(_config.default,e,{server:r})}r&&(_config.default.server.port=r)}exports.colorconsole=colorconsole;const illegalExtsList=[".css",".less",".scss",".styl",".sass",".log",".json",".js"].map(e=>"app"+e);function getProjectDslName(e){const r=_fs.default.readdirSync(_path.default.join(e,_config.default.sourceRoot)).filter(e=>/^app\..*/.test(e)&&!illegalExtsList.includes(e));let t;return r&&r[0]?(t=_path.default.extname(r[0]).slice(1),colorconsole.info("获取到app文件后缀: "+t)):colorconsole.error("无法获取正确的app文件后缀"),"ux"===t?"xvm":t}function getDeviceInfo(e,r){const t=_http.default.request({path:"/deviceinfo",host:e.ip,port:e.port,timeout:3e3},e=>{e.on("data",e=>{r(null,JSON.parse(e))})}).on("error",e=>{r(e)}).on("timeout",(function(){t.abort()}));t.end()}function readJson(e){try{return JSON.parse(_fs.default.readFileSync(e).toString())}catch(r){throw r instanceof SyntaxError?new SyntaxError(`解析 ${e} 失败, 格式错误`):r.message.startsWith("ENOENT:")?(r.message=`读取 ${e} 失败, 找不到该文件`,r):(r.message=`读取 ${e} 失败 ${r.message}`,r)}} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.KnownError=KnownError,exports.colorconsole=void 0,exports.equals=equals,exports.extend=extend,exports.getClientIPAddress=getClientIPAddress,exports.getDefaultServerHost=getDefaultServerHost,exports.getDeviceInfo=getDeviceInfo,exports.getIPv4IPAddress=getIPv4IPAddress,Object.defineProperty(exports,"getLaunchPage",{enumerable:!0,get:function(){return _util.getLaunchPage}}),exports.getProjectDslName=getProjectDslName,exports.getServerIPAndPort=getServerIPAndPort,exports.logWarn=logWarn,exports.logger=void 0,exports.mkdirsSync=mkdirsSync,exports.outputQRCodeOnTerminal=outputQRCodeOnTerminal,exports.readJson=readJson,exports.relateCwd=relateCwd,exports.renderString=renderString,exports.setCustomConfig=setCustomConfig,exports.stripPrefixForIPV4MappedIPV6Address=stripPrefixForIPV4MappedIPV6Address;var _os=_interopRequireDefault(require("os")),_fs=_interopRequireDefault(require("fs")),_path=_interopRequireDefault(require("path")),_http=_interopRequireDefault(require("http")),_console=require("console"),_chalk=_interopRequireDefault(require("chalk")),_qrcodeTerminal=_interopRequireDefault(require("qrcode-terminal")),_config=_interopRequireDefault(require("../config")),_util=require("./buildMode/util");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const logLevelMap={};function prependLevel(e,r){if(!logLevelMap[e]){const r=e.toUpperCase();logLevelMap[e]=r}"string"==typeof r[0]&&r[0].length>1&&"["!==r[0][0]&&(r[0]=`[${logLevelMap[e]}] ${r[0]}`)}const logger={logs:[],add(e){this.logs.push(e)},clear(){this.logs=[]},get(){return this.logs.join("\n")}};exports.logger=logger;let originConsole=global.console,console=_console.Console?new _console.Console(process.stdout,process.stderr):originConsole;const colorconsole={attach(e){e&&_console.Console&&(console=new _console.Console(e,e))},trace(...e){prependLevel("trace",e),console.trace(...e)},log(...e){prependLevel("log",e),console.log(_chalk.default.green(...e))},info(...e){prependLevel("info",e),console.info(_chalk.default.green(...e))},warn(...e){prependLevel("warn",e),console.warn(_chalk.default.yellow.bold(...e))},error(...e){prependLevel("error",e),console.error(_chalk.default.red.bold(...e))},throw(...e){throw new Error(_chalk.default.red.bold(...e))}};function logWarn(e,r,t){r&&r.length&&r.forEach((r=>{const o=r.line&&r.column?"@"+r.line+":"+r.column:"";t||(r.reason.startsWith("ERROR")?colorconsole.error(e.resourcePath,o,r.reason):colorconsole.warn(e.resourcePath,o,r.reason))}))}function mkdirsSync(e){return!!_fs.default.existsSync(e)||(mkdirsSync(_path.default.dirname(e))?(_fs.default.mkdirSync(e),!0):void 0)}function getIPv4IPAddress(){const e=_os.default.networkInterfaces();let r;for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t)){if(e[t].every((e=>!("IPv4"===e.family&&!e.internal&&"127.0.0.1"!==e.address)||(r=e,!1))),void 0!==r)break}return r&&r.address}function getServerIPAndPort(e){return(getIPv4IPAddress()||"127.0.0.1")+""+(80===e?"":":"+e)}function getDefaultServerHost(){return getServerIPAndPort(_config.default.server.port)}function getClientIPAddress(e){return stripPrefixForIPV4MappedIPV6Address(e.headers["x-forwarded-for"]||e.connection&&e.connection.remoteAddress||e.socket&&e.socket.remoteAddress||e.connection&&e.connection.socket&&e.connection.socket.remoteAddress)}function stripPrefixForIPV4MappedIPV6Address(e){return/^::1$/.test(e)&&(e="127.0.0.1"),/^::.{0,4}:(\d{1,3}\.){3}\d{1,3}/.test(e)&&(e=e.replace(/^.*:/,"")),e}function outputQRCodeOnTerminal(e){console.info(`\n生成HTTP服务器的二维码: ${e}`),_qrcodeTerminal.default.generate(e,{small:!0})}function relateCwd(e){const r=_config.default.projectPath;return _path.default.relative(r,e)}function equals(e,r,t,...o){if(t){if(t(e,r,...o))return!0}const n=Object.prototype.toString.call(e);if(n!==Object.prototype.toString.call(r))return!1;if("[object Null]"===n||"[object Undefined]"===n)return!0;if("[object Object]"!==n&&"[object Array]"!==n)return Object(e).toString()===Object(r).toString();const s={};Object.keys(e).forEach((e=>s[e]=!0)),Object.keys(r).forEach((e=>s[e]=!0));const l=Object.keys(s);for(let o=0;o<l.length;o++){const n=l[o];if(!equals(e[n],r[n],t,n))return!1}return!0}function extend(e,...r){if("function"==typeof Object.assign)Object.assign(e,...r);else{const t=r.shift();for(const r in t)e[r]=t[r];r.length&&extend(e,...r)}return e}function renderString(e,r){return e.replace(/{{(.*?)}}/gm,((e,t)=>(t=t.trim(),void 0!==r[t]?r[t]:t)))}function KnownError(e){const r=new Error(e);return r.name="KnownError",r.__KNOWN=!0,r}function setCustomConfig(e,r){e=_config.default.projectPath=e||_config.default.projectPath;const t=_path.default.join(e,"quickapp.config.js");if(_fs.default.existsSync(t)){let e={};try{e=require(t)}catch(e){colorconsole.error(`读取项目自定义配置文件出错: ${e.message}`)}const r=Object.assign(_config.default.server,e.server);Object.assign(_config.default,e,{server:r})}r&&(_config.default.server.port=r)}exports.colorconsole=colorconsole;const illegalExtsList=[".css",".less",".scss",".styl",".sass",".log",".json",".js"].map((e=>"app"+e));function getProjectDslName(e){const r=_fs.default.readdirSync(_path.default.join(e,_config.default.sourceRoot)).filter((e=>/^app\..*/.test(e)&&!illegalExtsList.includes(e)));let t;return r&&r[0]?(t=_path.default.extname(r[0]).slice(1),colorconsole.info(`获取到app文件后缀: ${t}`)):colorconsole.error("无法获取正确的app文件后缀"),"ux"===t?"xvm":t}function getDeviceInfo(e,r){const t=_http.default.request({path:"/deviceinfo",host:e.ip,port:e.port,timeout:3e3},(e=>{e.on("data",(e=>{r(null,JSON.parse(e))}))})).on("error",(e=>{r(e)})).on("timeout",(function(){t.abort()}));t.end()}function readJson(e){try{return JSON.parse(_fs.default.readFileSync(e).toString())}catch(r){throw r instanceof SyntaxError?new SyntaxError(`解析 ${e} 失败, 格式错误`):r.message.startsWith("ENOENT:")?(r.message=`读取 ${e} 失败, 找不到该文件`,r):(r.message=`读取 ${e} 失败 ${r.message}`,r)}} | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getRecords=getRecords,exports.getProjectClients=getProjectClients,exports.recordClient=recordClient,exports.getRecordClient=getRecordClient,exports.clearProjectRecord=clearProjectRecord,exports.removeClientBySn=removeClientBySn;var _fs=_interopRequireDefault(require("fs")),_path=_interopRequireDefault(require("path")),_index=require("./index"),_config=_interopRequireDefault(require("../config"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function getRecords(e){let t={records:{}};try{t=JSON.parse(_fs.default.readFileSync(e).toString())}catch(e){_index.colorconsole.error("读取hap-toolkit-client-records.json文件出错: "+e.message)}return t}function writeRecords(e,t){_fs.default.writeFileSync(e,JSON.stringify(t,null,2))}function getProjectClients(e){const t=_config.default.projectPath;let r=e.records;r=r instanceof Object?r:{};const o=r[t];return o&&o instanceof Array?o:[]}function recordClient(e,t,r){const o=_path.default.dirname(e),i=_config.default.projectPath;let n;if((0,_index.mkdirsSync)(o),_fs.default.existsSync(e)){n=getRecords(e);let o=getProjectClients(n);for(r&&r("writeClientLogFile(): before: "+JSON.stringify(n.records)),o=o.filter(e=>e.ip!==t.ip||e.port!==t.port);o.length>4;)o.shift();n.records[i]=o}else n={records:{}},n.records[i]=[];n.records[i].push(t),writeRecords(e,n),r&&r("writeClientLogFile(): after: "+JSON.stringify(n.records))}function getRecordClient(e,t,r){if(_fs.default.existsSync(e)){return getProjectClients(getRecords(e)).find(e=>e.sn===t&&e.ip===r&&e.port)}}function clearProjectRecord(e){if(_fs.default.existsSync(e)){const t=getRecords(e),r=_config.default.projectPath;t.records[r]=[],writeRecords(e,t),_index.colorconsole.info("### App Server ### 清空调试设备记录")}else _index.colorconsole.info("### App Server ### 没有需要清空的调试设备记录")}function removeClientBySn(e,t,r){if(_fs.default.existsSync(e)){const o=_config.default.projectPath,i=getRecords(e),n=i.records,c=getProjectClients(i);r&&r("_removeItemFromClientLogFile(): before: "+JSON.stringify(n)),n[o]=c.filter(e=>e.sn!==t),writeRecords(e,i),r&&r("_removeItemFromClientLogFile(): after: "+JSON.stringify(n))}} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.clearProjectRecord=clearProjectRecord,exports.getProjectClients=getProjectClients,exports.getRecordClient=getRecordClient,exports.getRecords=getRecords,exports.recordClient=recordClient,exports.removeClientBySn=removeClientBySn;var _fs=_interopRequireDefault(require("fs")),_path=_interopRequireDefault(require("path")),_index=require("./index"),_config=_interopRequireDefault(require("../config"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function getRecords(e){let t={records:{}};try{t=JSON.parse(_fs.default.readFileSync(e).toString())}catch(e){_index.colorconsole.error(`读取hap-toolkit-client-records.json文件出错: ${e.message}`)}return t}function writeRecords(e,t){_fs.default.writeFileSync(e,JSON.stringify(t,null,2))}function getProjectClients(e){const t=_config.default.projectPath;let r=e.records;r=r instanceof Object?r:{};const o=r[t];return o&&o instanceof Array?o:[]}function recordClient(e,t,r){const o=_path.default.dirname(e),i=_config.default.projectPath;let n;if((0,_index.mkdirsSync)(o),_fs.default.existsSync(e)){n=getRecords(e);let o=getProjectClients(n);for(r&&r(`writeClientLogFile(): before: ${JSON.stringify(n.records)}`),o=o.filter((e=>e.ip!==t.ip||e.port!==t.port));o.length>4;)o.shift();n.records[i]=o}else n={records:{}},n.records[i]=[];n.records[i].push(t),writeRecords(e,n),r&&r(`writeClientLogFile(): after: ${JSON.stringify(n.records)}`)}function getRecordClient(e,t,r){if(_fs.default.existsSync(e)){return getProjectClients(getRecords(e)).find((e=>e.sn===t&&e.ip===r&&e.port))}}function clearProjectRecord(e){if(_fs.default.existsSync(e)){const t=getRecords(e),r=_config.default.projectPath;t.records[r]=[],writeRecords(e,t),_index.colorconsole.info("### App Server ### 清空调试设备记录")}else _index.colorconsole.info("### App Server ### 没有需要清空的调试设备记录")}function removeClientBySn(e,t,r){if(_fs.default.existsSync(e)){const o=_config.default.projectPath,i=getRecords(e),n=i.records,c=getProjectClients(i);r&&r(`_removeItemFromClientLogFile(): before: ${JSON.stringify(n)}`),n[o]=c.filter((e=>e.sn!==t)),writeRecords(e,i),r&&r(`_removeItemFromClientLogFile(): after: ${JSON.stringify(n)}`)}} | ||
//# sourceMappingURL=record-client.js.map |
{ | ||
"name": "@hap-toolkit/shared-utils", | ||
"version": "1.9.9-beta.4", | ||
"version": "1.9.9", | ||
"description": "hap shared utils", | ||
@@ -33,3 +33,3 @@ "engines": { | ||
}, | ||
"gitHead": "56921e6b5c3400e979442f5c8af50acdd178e598" | ||
"gitHead": "e0db8383e2b5cb684c0b46b57c7d68070311e31a" | ||
} |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
17032
5