@hap-toolkit/shared-utils
Advanced tools
Comparing version 1.9.12 to 1.9.13-beta
@@ -1,2 +0,2 @@ | ||
"use strict";var _fs=_interopRequireDefault(require("fs")),_path=_interopRequireDefault(require("@jayfate/path")),_index=require("../index"),_util=require("./util"),_eventBus=_interopRequireDefault(require("../../event-bus"));function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}const{PACKAGER_BUILD_DONE:PACKAGER_BUILD_DONE}=_eventBus.default;function BuildModeManager(t){(0,_util.initProjectConfig)(t),this.setRoot(t)}BuildModeManager.prototype._read=function(){let t={};try{t=(0,_index.readJson)(this._configFile)}catch(t){console.log("ENOENT"===t.code?t.message:t)}t.modeOptions||(t.modeOptions={current:-1,list:[]});const e=t.modeOptions;return e.list=e.list.filter((t=>null!==t.id&&-1!==t.id)),t},BuildModeManager.prototype._write=function(t){const e=t.modeOptions;e.list=e.list.filter((t=>null!==t.id&&-1!==t.id)).reduce(((t,e)=>(t.find((t=>t.id===e.id))||t.push(e),t)),[]),this._configFile&&_fs.default.writeFileSync(this._configFile,JSON.stringify(t,null,2))},BuildModeManager.prototype.getConfig=function(){return this._read().modeOptions},BuildModeManager.prototype.getAllPages=function(){if(!this.root)return[];const t=_path.default.join(this.root,"src/manifest.json");try{const e=(0,_index.readJson)(t).router.pages||{};return Object.keys(e)}catch(t){return console.log("ENOENT"===t.code?t.message:t),[]}},BuildModeManager.prototype.getAllCards=function(){if(!this.root)return[];const t=_path.default.join(this.root,"src/manifest.json");try{const e=(0,_index.readJson)(t).router.widgets||{};return Object.keys(e)}catch(t){return console.log("ENOENT"===t.code?t.message:t),[]}},BuildModeManager.prototype._addMode=function(t,e,i){const o=t.modeOptions;let n;return n=o.list.length?Math.max.apply(null,o.list.map((t=>t.id)))+1:0,e.id=n,o.list.push(e),o.current=e.id,i||this._write(t),o},BuildModeManager.prototype.addMode=function(t){const e=this._read();return this._addMode(e,t,!1)},BuildModeManager.prototype.addModes=function(t){const e=this._read(),i=e.modeOptions.current;return t.forEach((t=>{this._addMode(e,t,!0)})),e.modeOptions.current=i,this._write(e),e.modeOptions},BuildModeManager.prototype.delete=function(t){const e=this._read(),i=e.modeOptions,o=i.list.findIndex((e=>e.id===t));return i.current=-1,-1!==o&&(i.list.splice(o,1),this._write(e)),i},BuildModeManager.prototype.deleteModes=function(t){const e=this._read(),i=e.modeOptions,o=i.current,n=i.list.filter((e=>!t.find((t=>t.id===e.id))));if(i.list.length!==n.length){const t=n.find((t=>t.id===o));i.list=n,t||(i.current=-1),this._write(e)}return i},BuildModeManager.prototype.update=function(t){const e=this._read(),i=e.modeOptions,o=i.list.findIndex((e=>e.id===t.id));return-1!==o&&(i.list[o]=t),this._write(e),i},BuildModeManager.prototype.select=function(t){const e=this._read(),i=e.modeOptions;return-1!==i.list.findIndex((e=>e.id===t))&&(i.current=t,this._write(e),_eventBus.default.emit(PACKAGER_BUILD_DONE)),i},BuildModeManager.prototype.setToNormal=function(){const t=this._read(),e=t.modeOptions;return e.current=-1,this._write(t),_eventBus.default.emit(PACKAGER_BUILD_DONE),e},BuildModeManager.prototype.setRoot=function(t){if("string"==typeof t){this.root=t,this._configFile=_path.default.resolve(t,_util.CONFIG_FILE);return this._read().modeOptions}return null},module.exports=BuildModeManager; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _fs=_interopRequireDefault(require("fs")),_path=_interopRequireDefault(require("path")),_index=require("../index"),_util=require("./util"),_eventBus=require("../event-bus");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const{PACKAGER_BUILD_DONE:PACKAGER_BUILD_DONE}=_eventBus.eventBus;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.getAllCards=function(){if(!this.root)return[];const e=_path.default.join(this.root,"src/manifest.json");try{const t=(0,_index.readJson)(e).router.widgets||{};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(),i=t.modeOptions.current;return e.forEach((e=>{this._addMode(t,e,!0)})),t.modeOptions.current=i,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.deleteModes=function(e){const t=this._read(),i=t.modeOptions,o=i.current,n=i.list.filter((t=>!e.find((e=>e.id===t.id))));if(i.list.length!==n.length){const e=n.find((e=>e.id===o));i.list=n,e||(i.current=-1),this._write(t)}return 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.eventBus.emit(PACKAGER_BUILD_DONE)),i},BuildModeManager.prototype.setToNormal=function(){const e=this._read(),t=e.modeOptions;return t.current=-1,this._write(e),_eventBus.eventBus.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};var _default=BuildModeManager;exports.default=_default; | ||
//# sourceMappingURL=BuildModeManager.js.map |
@@ -1,2 +0,2 @@ | ||
"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("@jayfate/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.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("@jayfate/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});var _exportNames={logger:!0,colorconsole:!0,logWarn:!0,mkdirsSync:!0,getIPv4IPAddress:!0,getServerIPAndPort:!0,getDefaultServerHost:!0,getClientIPAddress:!0,stripPrefixForIPV4MappedIPV6Address:!0,outputQRCodeOnTerminal:!0,relateCwd:!0,equals:!0,extend:!0,renderString:!0,KnownError:!0,setCustomConfig:!0,getProjectDslName:!0,getDeviceInfo:!0,readJson:!0,globalConfig:!0,BuildModeManager:!0,getLaunchPage:!0};Object.defineProperty(exports,"BuildModeManager",{enumerable:!0,get:function(){return _BuildModeManager.default}}),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,Object.defineProperty(exports,"globalConfig",{enumerable:!0,get:function(){return _config.default}}),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")),_BuildModeManager=_interopRequireDefault(require("./buildMode/BuildModeManager.js")),_util=require("./buildMode/util"),_compilationConfig=require("./compilation-config");Object.keys(_compilationConfig).forEach((function(e){"default"!==e&&"__esModule"!==e&&(Object.prototype.hasOwnProperty.call(_exportNames,e)||e in exports&&exports[e]===_compilationConfig[e]||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return _compilationConfig[e]}}))}));var _recordClient=require("./record-client");Object.keys(_recordClient).forEach((function(e){"default"!==e&&"__esModule"!==e&&(Object.prototype.hasOwnProperty.call(_exportNames,e)||e in exports&&exports[e]===_recordClient[e]||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return _recordClient[e]}}))}));var _eventBus=require("./event-bus");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}Object.keys(_eventBus).forEach((function(e){"default"!==e&&"__esModule"!==e&&(Object.prototype.hasOwnProperty.call(_exportNames,e)||e in exports&&exports[e]===_eventBus[e]||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return _eventBus[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.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("@jayfate/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.12", | ||
"version": "1.9.13-beta", | ||
"description": "hap shared utils", | ||
"engines": { | ||
"node": ">=8.0.0" | ||
"node": ">=14.0.0" | ||
}, | ||
@@ -16,2 +16,6 @@ "publishConfig": { | ||
"main": "lib/index.js", | ||
"exports": { | ||
"import": "./src/index.js", | ||
"require": "./lib/index.js" | ||
}, | ||
"directories": { | ||
@@ -34,3 +38,3 @@ "lib": "lib", | ||
}, | ||
"gitHead": "db1ba8ad12ce32c83a543af0459a208e1eb97e28" | ||
"gitHead": "a9b0d35e6a243920076ad27d9ec37d5036208667" | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
27259
76
7
2