UNPKG

@ks-opdev/cli

Version:

ksodev: A CLI based on the WPS Open Platform

1 lines 4.48 kB
(function(_0x2f24a3,_0x1ebe84){const _0x1540e5=a20_0x5b40,_0x5ad27a=_0x2f24a3();while(!![]){try{const _0x5e362d=parseInt(_0x1540e5(0x15b))/0x1+-parseInt(_0x1540e5(0x164))/0x2*(parseInt(_0x1540e5(0x161))/0x3)+parseInt(_0x1540e5(0x155))/0x4+-parseInt(_0x1540e5(0x159))/0x5*(-parseInt(_0x1540e5(0x16e))/0x6)+-parseInt(_0x1540e5(0x16b))/0x7+parseInt(_0x1540e5(0x151))/0x8*(parseInt(_0x1540e5(0x16c))/0x9)+-parseInt(_0x1540e5(0x167))/0xa*(-parseInt(_0x1540e5(0x162))/0xb);if(_0x5e362d===_0x1ebe84)break;else _0x5ad27a['push'](_0x5ad27a['shift']());}catch(_0x1a28da){_0x5ad27a['push'](_0x5ad27a['shift']());}}}(a20_0x55f5,0x2017b));import a20_0x19dd38 from'axios';import{existsSync,mkdirSync,readFileSync,writeFileSync}from'node:fs';import{homedir}from'node:os';import{dirname,join}from'node:path';import{DEFAULT_CONFIG,UPDATE_CONFIG}from'../config/constants.js';function getCacheFilePath(){const _0x2b59c7=a20_0x5b40;return join(homedir(),DEFAULT_CONFIG[_0x2b59c7(0x163)],DEFAULT_CONFIG[_0x2b59c7(0x166)]);}function ensureCacheDirectory(){const _0x365adc=getCacheFilePath(),_0x213b6f=dirname(_0x365adc);!existsSync(_0x213b6f)&&mkdirSync(_0x213b6f,{'recursive':!![]});}function getCachedVersionData(){const _0x5356e8=a20_0x5b40,_0x216c81=getCacheFilePath();try{if(!existsSync(_0x216c81))return null;const _0x18cace=JSON[_0x5356e8(0x157)](readFileSync(_0x216c81,'utf-8'));return _0x18cace;}catch{return null;}}function setCachedVersionData(_0x55a805){const _0x870b3c=a20_0x5b40,_0x518668=getCacheFilePath();try{ensureCacheDirectory(),writeFileSync(_0x518668,JSON[_0x870b3c(0x152)](_0x55a805,null,0x2),'utf-8');}catch{}}function isCacheValid(_0x2054df){const _0x2166ff=a20_0x5b40,_0x5f58fc=Date[_0x2166ff(0x169)]();return _0x5f58fc-_0x2054df[_0x2166ff(0x158)]<UPDATE_CONFIG['CACHE_DURATION'];}function isNewerVersion(_0x19ae44,_0x306672){const _0x4c7127=a20_0x5b40;try{const _0x2639ff=_0x19ae44[_0x4c7127(0x160)](/^v/,'')[_0x4c7127(0x16d)]('-')[0x0],_0x1d724b=_0x306672['replace'](/^v/,'')[_0x4c7127(0x16d)]('-')[0x0],_0x3edaec=_0x2639ff[_0x4c7127(0x16d)]('.')[_0x4c7127(0x153)](Number),_0x376ed0=_0x1d724b[_0x4c7127(0x16d)]('.')[_0x4c7127(0x153)](Number);while(_0x3edaec[_0x4c7127(0x15e)]<0x3)_0x3edaec[_0x4c7127(0x165)](0x0);while(_0x376ed0[_0x4c7127(0x15e)]<0x3)_0x376ed0[_0x4c7127(0x165)](0x0);for(let _0x48b1eb=0x0;_0x48b1eb<0x3;_0x48b1eb++){if(_0x376ed0[_0x48b1eb]>_0x3edaec[_0x48b1eb])return!![];if(_0x376ed0[_0x48b1eb]<_0x3edaec[_0x48b1eb])return![];}return![];}catch{return![];}}async function fetchLatestVersionFromNpm(){const _0x2237b2=a20_0x5b40;try{const _0x278f37=await a20_0x19dd38[_0x2237b2(0x168)](UPDATE_CONFIG['NPM_REGISTRY_URL'],{'timeout':0x1388,'headers':{'User-Agent':UPDATE_CONFIG[_0x2237b2(0x15c)]+_0x2237b2(0x15d)}});return _0x278f37['data'][_0x2237b2(0x16a)]?.[_0x2237b2(0x15f)]||null;}catch{return null;}}export async function checkForUpdates(_0x3a4fb1){const _0x8ab572=a20_0x5b40,_0x1748cf={'hasUpdate':![],'currentVersion':_0x3a4fb1,'latestVersion':_0x3a4fb1,'shouldNotify':![]};try{const _0x17be0e=getCachedVersionData();let _0x208446=null;if(_0x17be0e&&isCacheValid(_0x17be0e)&&_0x17be0e[_0x8ab572(0x15a)]===_0x3a4fb1)_0x208446=_0x17be0e[_0x8ab572(0x16f)];else{_0x208446=await fetchLatestVersionFromNpm();if(_0x208446){const _0x2aeb47={'currentVersion':_0x3a4fb1,'latestVersion':_0x208446,'timestamp':Date[_0x8ab572(0x169)](),'lastCheckTime':new Date()[_0x8ab572(0x156)]()};setCachedVersionData(_0x2aeb47);}}if(!_0x208446)return _0x1748cf;const _0x766ac9=isNewerVersion(_0x3a4fb1,_0x208446);return{'hasUpdate':_0x766ac9,'currentVersion':_0x3a4fb1,'latestVersion':_0x208446,'shouldNotify':_0x766ac9};}catch{return _0x1748cf;}}function a20_0x55f5(){const _0x56f68d=['110hQFFjn','currentVersion','73137pnonaX','PACKAGE_NAME','\x20version\x20checker','length','latest','replace','254421FPdIza','22bvufAZ','WORK_DIR_NAME','2aIYODV','push','UPDATE_CACHE_FILE','113770eCJdoy','get','now','dist-tags','1511412sozTlw','40707zCovGG','split','69246dpkCHz','latestVersion','8HRbqQk','stringify','map','INSTALL_COMMAND','311432iuZjha','toISOString','parse','timestamp'];a20_0x55f5=function(){return _0x56f68d;};return a20_0x55f5();}function a20_0x5b40(_0x2bbe5a,_0x3cd9e4){const _0x55f56b=a20_0x55f5();return a20_0x5b40=function(_0x5b401b,_0x5dec82){_0x5b401b=_0x5b401b-0x151;let _0x3b14df=_0x55f56b[_0x5b401b];return _0x3b14df;},a20_0x5b40(_0x2bbe5a,_0x3cd9e4);}export function getInstallCommand(){const _0x33141e=a20_0x5b40;return UPDATE_CONFIG[_0x33141e(0x154)];}