@cyberskill/shared 1.46.0 → 1.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/README.md +12 -18
  2. package/dist/_tsup-dts-rollup.d.cts +413 -31
  3. package/dist/_tsup-dts-rollup.d.ts +413 -31
  4. package/dist/cli.cjs +2136 -1
  5. package/dist/cli.d.cts +2 -1
  6. package/dist/cli.d.ts +2 -1
  7. package/dist/cli.js +2056 -1
  8. package/dist/configs/commitlint/base.cjs +64 -1
  9. package/dist/configs/commitlint/base.js +7 -1
  10. package/dist/configs/eslint/base.cjs +121 -1
  11. package/dist/configs/eslint/base.js +52 -1
  12. package/dist/configs/eslint/nestjs.cjs +155 -1
  13. package/dist/configs/eslint/nestjs.js +85 -1
  14. package/dist/configs/eslint/nextjs.cjs +155 -1
  15. package/dist/configs/eslint/nextjs.js +85 -1
  16. package/dist/configs/eslint/nodejs.cjs +156 -1
  17. package/dist/configs/eslint/nodejs.js +86 -1
  18. package/dist/configs/eslint/vite-react.cjs +159 -1
  19. package/dist/configs/eslint/vite-react.js +89 -1
  20. package/dist/configs/graphql/graphql-codegen.cjs +125 -1
  21. package/dist/configs/graphql/graphql-codegen.js +64 -1
  22. package/dist/configs/graphql/index.cjs +126 -1
  23. package/dist/configs/graphql/index.js +64 -1
  24. package/dist/configs/i18n/react/i18next.cjs +80 -1
  25. package/dist/configs/i18n/react/i18next.js +7 -1
  26. package/dist/configs/i18n/react/index.cjs +81 -1
  27. package/dist/configs/i18n/react/index.js +7 -1
  28. package/dist/configs/index.cjs +232 -1
  29. package/dist/configs/index.js +166 -1
  30. package/dist/configs/lint-staged/base.cjs +64 -1
  31. package/dist/configs/lint-staged/base.js +7 -1
  32. package/dist/configs/vitest/react/e2e.cjs +128 -1
  33. package/dist/configs/vitest/react/e2e.js +59 -1
  34. package/dist/configs/vitest/react/unit.cjs +305 -1
  35. package/dist/configs/vitest/react/unit.js +228 -1
  36. package/dist/configs/vitest/react/unit.setup.cjs +60 -1
  37. package/dist/configs/vitest/react/unit.setup.js +8 -1
  38. package/dist/constants/index.cjs +678 -1
  39. package/dist/constants/index.d.cts +31 -1
  40. package/dist/constants/index.d.ts +31 -1
  41. package/dist/constants/index.js +469 -1
  42. package/dist/constants/path.cjs +423 -1
  43. package/dist/constants/path.d.cts +31 -1
  44. package/dist/constants/path.d.ts +31 -1
  45. package/dist/constants/path.js +218 -1
  46. package/dist/constants/response-status.cjs +313 -1
  47. package/dist/constants/response-status.js +252 -1
  48. package/dist/index.cjs +4546 -1
  49. package/dist/index.d.cts +51 -6
  50. package/dist/index.d.ts +51 -6
  51. package/dist/index.js +4133 -1
  52. package/dist/nodejs/index.cjs +2138 -1
  53. package/dist/nodejs/index.js +2054 -1
  54. package/dist/nodejs/mongo.cjs +2137 -1
  55. package/dist/nodejs/mongo.js +2054 -1
  56. package/dist/react/apollo-client.cjs +177 -1
  57. package/dist/react/apollo-client.js +116 -1
  58. package/dist/react/index.cjs +990 -1
  59. package/dist/react/index.js +876 -1
  60. package/dist/react/loading.cjs +301 -1
  61. package/dist/react/loading.js +216 -1
  62. package/dist/react/next-intl.cjs +744 -1
  63. package/dist/react/next-intl.js +655 -1
  64. package/dist/react/storage.cjs +631 -1
  65. package/dist/react/storage.js +558 -1
  66. package/dist/typescript/api-response.cjs +48 -1
  67. package/dist/typescript/apollo.cjs +48 -1
  68. package/dist/typescript/command.cjs +68 -1
  69. package/dist/typescript/command.d.cts +4 -0
  70. package/dist/typescript/command.d.ts +4 -0
  71. package/dist/typescript/command.js +7 -1
  72. package/dist/typescript/config.cjs +48 -1
  73. package/dist/typescript/fs.cjs +48 -0
  74. package/dist/typescript/fs.d.cts +1 -0
  75. package/dist/typescript/fs.d.ts +1 -0
  76. package/dist/typescript/fs.js +0 -0
  77. package/dist/typescript/graphql-codegen.cjs +48 -1
  78. package/dist/typescript/index.cjs +175 -1
  79. package/dist/typescript/index.d.cts +5 -0
  80. package/dist/typescript/index.d.ts +5 -0
  81. package/dist/typescript/index.js +151 -1
  82. package/dist/typescript/loading.cjs +48 -1
  83. package/dist/typescript/log.cjs +48 -1
  84. package/dist/typescript/mongo.cjs +164 -1
  85. package/dist/typescript/mongo.js +145 -1
  86. package/dist/typescript/next-intl.cjs +48 -1
  87. package/dist/typescript/react.cjs +48 -1
  88. package/dist/typescript/serializer.cjs +48 -1
  89. package/dist/typescript/string.cjs +48 -1
  90. package/dist/utils/command.cjs +1387 -1
  91. package/dist/utils/command.d.cts +2 -0
  92. package/dist/utils/command.d.ts +2 -0
  93. package/dist/utils/command.js +1287 -1
  94. package/dist/utils/common.cjs +300 -1
  95. package/dist/utils/common.js +219 -1
  96. package/dist/utils/config.cjs +146 -1
  97. package/dist/utils/config.js +89 -1
  98. package/dist/utils/fs.cjs +118 -1
  99. package/dist/utils/fs.d.cts +4 -1
  100. package/dist/utils/fs.d.ts +4 -1
  101. package/dist/utils/fs.js +37 -1
  102. package/dist/utils/index-nodejs.cjs +1738 -1
  103. package/dist/utils/index-nodejs.d.cts +15 -5
  104. package/dist/utils/index-nodejs.d.ts +15 -5
  105. package/dist/utils/index-nodejs.js +1571 -1
  106. package/dist/utils/index.cjs +727 -1
  107. package/dist/utils/index.js +625 -1
  108. package/dist/utils/log.cjs +330 -1
  109. package/dist/utils/log.js +269 -1
  110. package/dist/utils/package.cjs +941 -0
  111. package/dist/utils/package.d.cts +3 -0
  112. package/dist/utils/package.d.ts +3 -0
  113. package/dist/utils/package.js +857 -0
  114. package/dist/utils/path.cjs +291 -0
  115. package/dist/utils/path.d.cts +6 -0
  116. package/dist/utils/path.d.ts +6 -0
  117. package/dist/utils/path.js +191 -0
  118. package/dist/utils/serializer.cjs +91 -1
  119. package/dist/utils/serializer.js +30 -1
  120. package/dist/utils/storage-client.cjs +349 -1
  121. package/dist/utils/storage-client.js +276 -1
  122. package/dist/utils/storage-server.cjs +636 -1
  123. package/dist/utils/storage-server.d.cts +1 -1
  124. package/dist/utils/storage-server.d.ts +1 -1
  125. package/dist/utils/storage-server.js +550 -1
  126. package/dist/utils/string.cjs +152 -1
  127. package/dist/utils/string.js +75 -1
  128. package/dist/utils/validate.cjs +90 -1
  129. package/dist/utils/validate.js +33 -1
  130. package/package.json +19 -16
  131. package/dist/utils/npm-package.cjs +0 -1
  132. package/dist/utils/npm-package.d.cts +0 -4
  133. package/dist/utils/npm-package.d.ts +0 -4
  134. package/dist/utils/npm-package.js +0 -1
package/dist/cli.js CHANGED
@@ -1,2 +1,2057 @@
1
1
  #!/usr/bin/env node
2
- function e(e,n,t,r,s,o,i){try{var c=e[o](i);var a=c.value}catch(e){t(e);return}if(c.done){n(a)}else{Promise.resolve(a).then(r,s)}}function n(n){return function(){var t=this,r=arguments;return new Promise(function(s,o){var i=n.apply(t,r);function c(n){e(i,s,o,c,a,"next",n)}function a(n){e(i,s,o,c,a,"throw",n)}c(undefined)})}}function t(e,n,t){if(n in e){Object.defineProperty(e,n,{value:t,enumerable:true,configurable:true,writable:true})}else{e[n]=t}return e}function r(e){for(var n=1;n<arguments.length;n++){var r=arguments[n]!=null?arguments[n]:{};var s=Object.keys(r);if(typeof Object.getOwnPropertySymbols==="function"){s=s.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))}s.forEach(function(n){t(e,n,r[n])})}return e}function s(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);if(n){r=r.filter(function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable})}t.push.apply(t,r)}return t}function o(e,n){n=n!=null?n:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(e,Object.getOwnPropertyDescriptors(n))}else{s(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function i(e,n){var t,r,s,o,i={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]};return o={next:c(0),"throw":c(1),"return":c(2)},typeof Symbol==="function"&&(o[Symbol.iterator]=function(){return this}),o;function c(e){return function(n){return a([e,n])}}function a(o){if(t)throw new TypeError("Generator is already executing.");while(i)try{if(t=1,r&&(s=o[0]&2?r["return"]:o[0]?r["throw"]||((s=r["return"])&&s.call(r),0):r.next)&&!(s=s.call(r,o[1])).done)return s;if(r=0,s)o=[o[0]&2,s.value];switch(o[0]){case 0:case 1:s=o;break;case 4:i.label++;return{value:o[1],done:false};case 5:i.label++;r=o[1];o=[0];continue;case 7:o=i.ops.pop();i.trys.pop();continue;default:if(!(s=i.trys,s=s.length>0&&s[s.length-1])&&(o[0]===6||o[0]===2)){i=0;continue}if(o[0]===3&&(!s||o[1]>s[0]&&o[1]<s[3])){i.label=o[1];break}if(o[0]===6&&i.label<s[1]){i.label=s[1];s=o;break}if(s&&i.label<s[2]){i.label=s[2];i.ops.push(o);break}if(s[2])i.ops.pop();i.trys.pop();continue}o=n.call(e,i)}catch(e){o=[6,e];r=0}finally{t=s=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:true}}}import*as c from"node:fs";import*as a from"node:path";import u from"node:process";import{hideBin as l}from"yargs/helpers";import f from"yargs/yargs";import{dirname as p}from"node:path";import h from"node:process";import{fileURLToPath as g}from"node:url";var d=g(import.meta.url),m=p(d),y=h.env.INIT_CWD||h.cwd();import v from"boxen";import b from"chalk";import{exec as w}from"node:child_process";import S from"node:process";import*as _ from"node:util";import O from"node-persist";import T from"node:os";import A from"node:path";import k from"node:process";var E=k.env.CYBERSKILL_STORAGE_DIR||A.join(T.homedir(),".cyberskill-storage");function P(){return I.apply(this,arguments)}function I(){I=n(function(){var e;return i(this,function(n){switch(n.label){case 0:e=O.defaultInstance;if(e)return[3,2];return[4,O.init({dir:E,stringify:JSON.stringify,parse:JSON.parse,encoding:"utf8",logging:!1,forgiveParseErrors:!0})];case 1:e=n.sent();n.label=2;case 2:e;return[2]}})});return I.apply(this,arguments)}var j={get:function e(e){return n(function(){var n,t;return i(this,function(r){switch(r.label){case 0:r.trys.push([0,3,,4]);return[4,P()];case 1:r.sent();return[4,O.getItem(e)];case 2:return[2,(n=r.sent())!==null&&n!==void 0?n:null];case 3:t=r.sent();return[2,(console.error('❌ [Storage:get] Error getting key "'.concat(e,'":'),t),null)];case 4:return[2]}})})()},set:function e(e,t){return n(function(){var n;return i(this,function(r){switch(r.label){case 0:r.trys.push([0,3,,4]);return[4,P()];case 1:r.sent();return[4,O.setItem(e,t)];case 2:r.sent();return[3,4];case 3:n=r.sent();console.error('❌ [Storage:set] Error setting key "'.concat(e,'":'),n);return[3,4];case 4:return[2]}})})()},remove:function e(e){return n(function(){var n;return i(this,function(t){switch(t.label){case 0:t.trys.push([0,3,,4]);return[4,P()];case 1:t.sent();return[4,O.removeItem(e)];case 2:t.sent();return[3,4];case 3:n=t.sent();console.error('❌ [Storage:remove] Error removing key "'.concat(e,'":'),n);return[3,4];case 4:return[2]}})})()},keys:function e(){return n(function(){var e,n;return i(this,function(t){switch(t.label){case 0:t.trys.push([0,3,,4]);return[4,P()];case 1:t.sent();return[4,O.keys()];case 2:e=t.sent();return[2,Array.isArray(e)?e:(console.warn("⚠️ [Storage:keys] Invalid keys response:",e),[])];case 3:n=t.sent();return[2,(console.error("❌ [Storage:keys] Error getting keys:",n),[])];case 4:return[2]}})})()},getLogLink:function e(e){return n(function(){return i(this,function(n){try{return[2,"".concat(E," (key: ").concat(e,")")]}catch(e){return[2,(console.error("❌ [Storage:getLogLink] Error getting log link:",e),null)]}return[2]})})()}};var C=S.env.DEBUG==="true",N=_.promisify(w),G=b.gray,x=b.blue,F=function(){return G("[".concat(new Date().toLocaleTimeString(),"]"))};function H(e){var n=b[e];return typeof n=="function"?n:b.green}function M(e,n,t,r){var s=H(n);console.log("".concat(F()," ").concat(s("".concat(t," ").concat(e))," ").concat(r))}function L(e,n){var t=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},r=t.color,s=r===void 0?"green":r,o=t.padding,i=o===void 0?1:o,c=t.margin,a=c===void 0?1:c,u=t.borderStyle,l=u===void 0?"round":u,f=t.titleColor,p=f===void 0?"bold":f;var h=H(s),g=H(p);if(typeof n=="string"){console.log(v(g(h("".concat(e,"\n").concat(n))),{padding:i,margin:a,borderStyle:l,borderColor:s}));return}Array.isArray(n)&&n.length&&(n.forEach(function(e){var n=e.file,t=e.position,r=e.rule,s=e.message;console.log("".concat(F()," ").concat(h("File:")," ").concat(x("".concat(n).concat(t?":".concat(t):"")))),r&&console.log(" ".concat(h("Rule:")," ").concat(h(r))),console.log(" ".concat(h("Message:")," ").concat(h(s)))}),console.log(v(g(h("".concat(e,": ").concat(n.length))),{padding:i,margin:a,borderStyle:l,borderColor:s})),console.log(G("─".repeat(40))))}var R={success:function(e){return M("SUCCESS","green","✔",e)},error:function(e){return M("ERROR","red","✖",e)},warning:function(e){return M("WARNING","yellow","⚠",e)},info:function(e){return M("INFO","blue","ℹ",e)},printBoxedLog:L},K=function(e){return"error_list:".concat(e)};function D(e){return U.apply(this,arguments)}function U(){U=n(function(e){var t,r,s;return i(this,function(o){switch(o.label){case 0:if(e.length===0)return[2];t=Date.now(),r=K(t);o.label=1;case 1:o.trys.push([1,3,,4]);return[4,j.set(r,{errors:e,timestamp:t})];case 2:o.sent(),setTimeout(/*#__PURE__*/n(function(){var e;return i(this,function(n){switch(n.label){case 0:return[4,j.getLogLink(r)];case 1:e=n.sent();e&&R.info("\uD83D\uDCC2 Open the error list manually: ".concat(e));return[2]}})}),10);return[3,4];case 3:s=o.sent();R.error("Failed to save errors: ".concat(s.message));return[3,4];case 4:return[2]}})});return U.apply(this,arguments)}function J(){return B.apply(this,arguments)}function B(){B=n(function(){var e,t,r;return i(this,function(s){switch(s.label){case 0:s.trys.push([0,3,,4]);return[4,j.keys()];case 1:e=s.sent(),t=Array.isArray(e)?e.filter(function(e){var n;return e===null||e===void 0?void 0:(n=e.startsWith)===null||n===void 0?void 0:n.call(e,"error_list:")}):[];return[4,Promise.all(t.map(/*#__PURE__*/function(){var e=n(function(e){var n;return i(this,function(t){switch(t.label){case 0:return[4,j.get(e)];case 1:return[2,((n=t.sent())===null||n===void 0?void 0:n.errors)||[]]}})});return function(n){return e.apply(this,arguments)}}()))];case 2:return[2,s.sent().flat()];case 3:r=s.sent();return[2,(R.error("Failed to retrieve stored errors: ".concat(r.message)),[])];case 4:return[2]}})});return B.apply(this,arguments)}function W(){return Y.apply(this,arguments)}function Y(){Y=n(function(){var e,n,t;return i(this,function(r){switch(r.label){case 0:r.trys.push([0,3,,4]);return[4,j.keys()];case 1:e=r.sent(),n=Array.isArray(e)?e.filter(function(e){var n;return e===null||e===void 0?void 0:(n=e.startsWith)===null||n===void 0?void 0:n.call(e,"error_list:")}):[];return[4,Promise.all(n.map(function(e){return j.remove(e)}))];case 2:r.sent();return[3,4];case 3:t=r.sent();R.error("Failed to clear error lists: ".concat(t.message));return[3,4];case 4:return[2]}})});return Y.apply(this,arguments)}function $(e){var n=[],t=[],r="",s=/^\s*(\d+):(\d+)\s+(error|warning)\s+(.+?)\s+(\S+)$/,o=/^(.+?)\((\d+),(\d+)\):\s+(error|warning)\s+TS\d+:\s+(\S.+)$/,i=/^✖\s+(.*?)\s+\[(.*?)\]$/;e.split("\n").forEach(function(e){if(e.startsWith("/"))r=e.trim();else{var c=s.exec(e)||[],a=o.exec(e)||[],u=i.exec(e)||[];c.length&&r?n.push({file:r,position:"".concat(c[1],":").concat(c[2]),type:c[3]==="error"?"error":"warning",message:c[4].trim(),rule:c[5].trim()}):a.length?n.push({file:a[1],position:"".concat(a[2],":").concat(a[3]),type:a[4]==="error"?"error":"warning",message:a[5].trim()}):u.length?n.push({file:"commitlint",type:"error",message:u[1].trim(),rule:u[2].trim()}):t.push(e.trim())}}),n.length&&D(n),t.length&&C&&(R.warning("Unmatched lines:"),t.forEach(function(e){return console.log(" ".concat(e))}))}function q(e){try{var n=JSON.parse(e),t=[];n.forEach(function(e){var n=e.filePath,r=e.messages;r.forEach(function(e){var r=e.severity,s=e.line,o=e.column,i=e.ruleId,c=e.message;t.push({type:r===2?"error":"warning",file:n,position:"".concat(s,":").concat(o),rule:i,message:c})})}),t.length&&D(t)}catch(n){$(e)}}function z(e){return Q.apply(this,arguments)}function Q(){Q=n(function(e){var n,t,r,s,o,c,a,u,l;var f=arguments;return i(this,function(i){switch(i.label){case 0:n=f.length>1&&f[1]!==void 0?f[1]:q;t=new AbortController;S.on("SIGINT",function(){R.warning("Process interrupted. Terminating..."),t.abort(),S.exit()});i.label=1;case 1:i.trys.push([1,3,,4]);return[4,N(e,{maxBuffer:0x6400000,signal:t.signal})];case 2:r=i.sent(),s=r.stdout,o=r.stderr;[s,o].forEach(function(e){return e&&n(e)});return[3,4];case 3:c=i.sent();a=c.stdout,u=c.stderr,l=c.message;[a,u].forEach(function(e){return e&&n(e)}),!u&&!a&&R.error("Command failed: ".concat(l));return[3,4];case 4:return[2]}})});return Q.apply(this,arguments)}import*as V from"node:fs";var X=function(e){return V.existsSync(e)};import Z from"node-fetch";import ee from"node:fs";import en from"node:path";var et=24*60*60*1e3;function er(e){return e?en.join(y,"node_modules",e,"package.json"):en.join(y,"package.json")}function es(e){return eo.apply(this,arguments)}function eo(){eo=n(function(e){var n,t,r,s,o,c,a,u,l,f;var p=arguments;return i(this,function(i){switch(i.label){case 0:n=p.length>1&&p[1]!==void 0?p[1]:!1;t="npm_version:".concat(e),r="npm_metadata:".concat(e);return[4,j.get(t)];case 1:s=i.sent();return[4,j.get(r)];case 2:o=i.sent(),c=s&&Date.now()-s.timestamp<et;if(!n&&c)return[2,s.version];a={};(o===null||o===void 0?void 0:o.etag)&&(a["If-None-Match"]=o.etag),(o===null||o===void 0?void 0:o.lastModified)&&(a["If-Modified-Since"]=o.lastModified);i.label=3;case 3:i.trys.push([3,8,,9]);return[4,Z("https://registry.npmjs.org/".concat(e,"/latest"),{headers:a})];case 4:u=i.sent();if(u.status===304&&s)return[2,s.version];if(!u.ok)throw new Error("Failed to fetch latest version: ".concat(u.statusText));return[4,u.json()];case 5:l=i.sent().version;return[4,j.set(t,{version:l,timestamp:Date.now()})];case 6:i.sent();return[4,j.set(r,{etag:u.headers.get("ETag")||void 0,lastModified:u.headers.get("Last-Modified")||void 0})];case 7:return[2,(i.sent(),l)];case 8:f=i.sent();if(R.error("Error fetching latest version for ".concat(e,": ").concat(f.message)),s)return[2,(R.warning("Falling back to cached version for ".concat(e,": ").concat(s.version)),s.version)];throw f;case 9:return[2]}})});return eo.apply(this,arguments)}function ei(e){return ec.apply(this,arguments)}function ec(){ec=n(function(e){var n,t,r,s,o;var c=arguments;return i(this,function(i){switch(i.label){case 0:n=c.length>1&&c[1]!==void 0?c[1]:!0;i.label=1;case 1:i.trys.push([1,3,,4]);t=er(e);if(!ee.existsSync(t))return[2,(R.info("".concat(e," is not installed.")),!0)];r=JSON.parse(ee.readFileSync(t,"utf-8")).version;return[4,es(e,n)];case 2:s=i.sent();return[2,(R.info("Installed version of ".concat(e,": ").concat(r)),R.info("Latest version of ".concat(e,": ").concat(s)),r!==s)];case 3:o=i.sent();return[2,(R.warning("Failed to check version for ".concat(e,": ").concat(o.message)),!0)];case 4:return[2]}})});return ec.apply(this,arguments)}function ea(e){return eu.apply(this,arguments)}function eu(){eu=n(function(e){var n,s,c,a;return i(this,function(i){switch(i.label){case 0:i.trys.push([0,4,,5]);return[4,es(e,!0)];case 1:n=i.sent(),s=er();if(!ee.existsSync(s)){R.error("package.json not found. Cannot update ".concat(e));return[2]}c=JSON.parse(ee.readFileSync(s,"utf-8"));c.dependencies=o(r({},c.dependencies),t({},e,n)),ee.writeFileSync(s,JSON.stringify(c,null,2)),R.info("Updated ".concat(e," to version ").concat(n));return[4,z("npm i -f")];case 2:i.sent();return[4,z("npm run lint:fix")];case 3:i.sent(),R.success("".concat(e," updated successfully."));return[3,5];case 4:a=i.sent();throw R.error("Failed to update ".concat(e,": ").concat(a.message)),a;case 5:return[2]}})});return eu.apply(this,arguments)}function el(e,n){try{var t=en.join(e,"package.json");return ee.existsSync(t)?JSON.parse(ee.readFileSync(t,"utf-8")).name===n:!1}catch(e){return R.error("Error reading package.json: ".concat(e.message)),!1}}var ef={TS_CONFIG_PATH:a.resolve(y,"tsconfig.json"),HUSKY_PATH:a.resolve(y,".husky"),GIT_HOOK_PATH:a.resolve(y,".git/hooks"),GIT_COMMIT_MSG:a.resolve(y,".git/COMMIT_EDITMSG"),SIMPLE_GIT_HOOKS_PATH:a.resolve(y,".simple-git-hooks.json"),PACKAGE_JSON_PATH:a.resolve(y,"package.json"),PACKAGE_LOCK_PATH:a.resolve(y,"package-lock.json"),PACKAGE_NAME:"@cyberskill/shared",LINT_STAGED_CONFIG_PATH:a.resolve(m,"./configs/lint-staged/base.js"),COMMITLINT_CONFIG_PATH:a.resolve(m,"./configs/commitlint/base.js"),UNIT_TEST_CONFIG_PATH:a.resolve(m,"./configs/vitest/react/unit.js"),E2E_TEST_CONFIG_PATH:a.resolve(m,"./configs/vitest/react/e2e.js"),HOOKS_CONFIG:{"pre-commit":"npx --yes cyberskill lint-staged","commit-msg":"npx --yes cyberskill commitlint"}};function ep(e,n){return eh.apply(this,arguments)}function eh(){eh=n(function(e,n){return i(this,function(t){switch(t.label){case 0:R.info("".concat(e,"..."));return[4,z(n)];case 1:t.sent(),R.success("".concat(e," completed."));return[2]}})});return eh.apply(this,arguments)}function eg(){return ed.apply(this,arguments)}function ed(){ed=n(function(){var e;return i(this,function(n){switch(n.label){case 0:if(!X(ef.TS_CONFIG_PATH))return[3,2];return[4,ep("Running TypeScript check","npx tsc -p ".concat(ef.TS_CONFIG_PATH," --noEmit"))];case 1:e=n.sent();return[3,3];case 2:e=R.warning("TypeScript config not found. Skipping TypeScript check.");n.label=3;case 3:e;return[2]}})});return ed.apply(this,arguments)}function em(){return ey.apply(this,arguments)}function ey(){ey=n(function(){var e;var n=arguments;return i(this,function(t){switch(t.label){case 0:e=n.length>0&&n[0]!==void 0?n[0]:!1;return[4,ep("Running ESLint ".concat(e?"(with fix)":"(without fix)"),"npx eslint ".concat(y).concat(e?" --fix":""))];case 1:t.sent();return[2]}})});return ey.apply(this,arguments)}function ev(){return eb.apply(this,arguments)}function eb(){eb=n(function(){var e,n,t;return i(this,function(r){switch(r.label){case 0:return[4,J()];case 1:e=r.sent(),n=e.filter(function(e){return e.type==="error"}),t=e.filter(function(e){return e.type==="warning"});!n.length&&!t.length?R.printBoxedLog("✔ NO ISSUES FOUND","",{color:"green"}):(R.printBoxedLog("⚠ Warnings",t,{color:"yellow"}),R.printBoxedLog("✖ Errors",n,{color:"red"}));return[2]}})});return eb.apply(this,arguments)}function ew(){return eS.apply(this,arguments)}function eS(){eS=n(function(){var e;return i(this,function(n){switch(n.label){case 0:if(!el(y,ef.PACKAGE_NAME))return[3,5];n.label=1;case 1:n.trys.push([1,4,,5]);return[4,ep("Building @cyberskill/shared","npm run build")];case 2:n.sent();return[4,z("git add dist")];case 3:n.sent(),R.success("Built and staged @cyberskill/shared");return[3,5];case 4:e=n.sent();throw R.error("Failed to build and stage @cyberskill/shared: ".concat(e.message)),e;case 5:return[4,ep("Running lint-staged","npx lint-staged --config ".concat(ef.LINT_STAGED_CONFIG_PATH))];case 6:n.sent(),ev();return[2]}})});return eS.apply(this,arguments)}function e_(){return eO.apply(this,arguments)}function eO(){eO=n(function(){return i(this,function(e){switch(e.label){case 0:return[4,ep("Inspecting ESLint rules","npx @eslint/config-inspector")];case 1:e.sent();return[2]}})});return eO.apply(this,arguments)}function eT(){return eA.apply(this,arguments)}function eA(){eA=n(function(){return i(this,function(e){switch(e.label){case 0:return[4,W()];case 1:e.sent();return[4,Promise.all([eg(),em()])];case 2:e.sent(),ev();return[2]}})});return eA.apply(this,arguments)}function ek(){return eE.apply(this,arguments)}function eE(){eE=n(function(){return i(this,function(e){switch(e.label){case 0:return[4,W()];case 1:e.sent();return[4,Promise.all([eg(),em(!0)])];case 2:e.sent(),ev();return[2]}})});return eE.apply(this,arguments)}function eP(){return eI.apply(this,arguments)}function eI(){eI=n(function(){return i(this,function(e){switch(e.label){case 0:return[4,ep("Running commit lint","npx commitlint --edit ".concat(ef.GIT_COMMIT_MSG," --config ").concat(ef.COMMITLINT_CONFIG_PATH))];case 1:e.sent(),ev();return[2]}})});return eI.apply(this,arguments)}function ej(){return eC.apply(this,arguments)}function eC(){eC=n(function(){var e,n,t,r,s,o;return i(this,function(i){switch(i.label){case 0:if(R.info("Starting project setup..."),!X(ef.PACKAGE_JSON_PATH)){R.error("package.json not found. Aborting setup.");return[2]}i.label=1;case 1:i.trys.push([1,9,,10]);n=JSON.parse(c.readFileSync(ef.PACKAGE_JSON_PATH,"utf-8"));r=el(y,ef.PACKAGE_NAME);if(r)return[3,4];s=(e=n.dependencies)===null||e===void 0?void 0:e[ef.PACKAGE_NAME];if(!s)return[3,3];return[4,ei(ef.PACKAGE_NAME)];case 2:s=!i.sent();i.label=3;case 3:r=s;i.label=4;case 4:if(!r)return[3,5];t=R.success("Cyberskill package is already up to date.");return[3,7];case 5:R.info("\uD83D\uDCE6 Updating Cyberskill package...");return[4,ea(ef.PACKAGE_NAME)];case 6:t=(i.sent(),R.success("Cyberskill package updated successfully."));i.label=7;case 7:t;return[4,eN()];case 8:i.sent(),R.success("Project setup completed.");return[3,10];case 9:o=i.sent();throw R.error("Failed to setup project: ".concat(o.message)),o;case 10:return[2]}})});return eC.apply(this,arguments)}function eN(){return eG.apply(this,arguments)}function eG(){eG=n(function(){var e,n;return i(this,function(t){switch(t.label){case 0:R.info("Setting up Git hooks...");e=X(ef.HUSKY_PATH);if(!e)return[3,3];return[4,z("npx rimraf ".concat(ef.HUSKY_PATH," ").concat(ef.GIT_HOOK_PATH))];case 1:t.sent();return[4,z("git config core.hooksPath ".concat(ef.GIT_HOOK_PATH))];case 2:e=t.sent();t.label=3;case 3:e,c.writeFileSync(ef.SIMPLE_GIT_HOOKS_PATH,JSON.stringify(ef.HOOKS_CONFIG,null,4));n=a.resolve(".gitignore");X(n)?c.readFileSync(n,"utf8").split("\n").includes(".simple-git-hooks.json")?R.info(".simple-git-hooks.json is already ignored in .gitignore"):(c.appendFileSync(n,"\n# Ignore simple-git-hooks config\n.simple-git-hooks.json\n"),R.info("Added .simple-git-hooks.json to .gitignore")):(c.writeFileSync(n,"# Ignore simple-git-hooks config\n.simple-git-hooks.json\n"),R.info("Created .gitignore and added .simple-git-hooks.json"));return[4,z("npx simple-git-hooks")];case 4:t.sent(),R.success("Git hooks configured successfully.");return[2]}})});return eG.apply(this,arguments)}function ex(){return eF.apply(this,arguments)}function eF(){eF=n(function(){var e,n,t,r,s,o,c,a,u,l,f;return i(this,function(i){switch(i.label){case 0:e=[{command:"npm install",message:"Standard installation"},{command:"npm install --legacy-peer-deps",message:"Attempting installation with --legacy-peer-deps"},{command:"npm install --force",message:"Attempting forced installation"}];n=true,t=false,r=undefined;i.label=1;case 1:i.trys.push([1,8,9,10]);s=e[Symbol.iterator]();i.label=2;case 2:if(!!(n=(o=s.next()).done))return[3,7];c=o.value,a=c.command,u=c.message;i.label=3;case 3:i.trys.push([3,5,,6]);R.info("".concat(u,"..."));return[4,z(a)];case 4:i.sent(),R.success("Dependencies installed using: ".concat(a));return[2];case 5:l=i.sent();R.warning("Failed with: ".concat(a)),R.error("Error: ".concat(l.message));return[3,6];case 6:n=true;return[3,2];case 7:return[3,10];case 8:f=i.sent();t=true;r=f;return[3,10];case 9:try{if(!n&&s.return!=null){s.return()}}finally{if(t){throw r}}return[7];case 10:throw new Error("Failed to install dependencies after multiple attempts.")}})});return eF.apply(this,arguments)}function eH(){return eM.apply(this,arguments)}function eM(){eM=n(function(){return i(this,function(e){switch(e.label){case 0:return[4,ep("Resetting project","npx rimraf ".concat(y,"/node_modules ").concat(ef.PACKAGE_LOCK_PATH))];case 1:e.sent();return[4,ex()];case 2:e.sent();return[4,eN()];case 3:e.sent();return[2]}})});return eM.apply(this,arguments)}function eL(){return eR.apply(this,arguments)}function eR(){eR=n(function(){return i(this,function(e){switch(e.label){case 0:return[4,ep("Inspecting project dependencies","npx node-modules-inspector")];case 1:e.sent();return[2]}})});return eR.apply(this,arguments)}function eK(){return eD.apply(this,arguments)}function eD(){eD=n(function(){return i(this,function(e){switch(e.label){case 0:return[4,ep("Running unit tests","npx vitest --config ".concat(ef.UNIT_TEST_CONFIG_PATH))];case 1:e.sent();return[2]}})});return eD.apply(this,arguments)}function eU(){return eJ.apply(this,arguments)}function eJ(){eJ=n(function(){return i(this,function(e){switch(e.label){case 0:return[4,ep("Running E2E tests","npx vitest --config ".concat(ef.E2E_TEST_CONFIG_PATH))];case 1:e.sent();return[2]}})});return eJ.apply(this,arguments)}f(l(u.argv)).command("lint","Run linting checks",eT).command("lint:fix","Fix linting issues",ek).command("lint:inspect","Inspect linting rules",e_).command("lint-staged","Run lint-staged",ew).command("commitlint","Run commitlint",eP).command("setup","Run project setup",ej).command("reset","Reset project dependencies",eH).command("inspect","Inspect project dependencies",eL).command("test:unit","Run unit tests",eK).command("test:e2e","Run e2e tests",eU).help().parse();
2
+ function _array_like_to_array(arr, len) {
3
+ if (len == null || len > arr.length) len = arr.length;
4
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
5
+ return arr2;
6
+ }
7
+ function _array_with_holes(arr) {
8
+ if (Array.isArray(arr)) return arr;
9
+ }
10
+ function _array_without_holes(arr) {
11
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
12
+ }
13
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
14
+ try {
15
+ var info = gen[key](arg);
16
+ var value = info.value;
17
+ } catch (error) {
18
+ reject(error);
19
+ return;
20
+ }
21
+ if (info.done) {
22
+ resolve(value);
23
+ } else {
24
+ Promise.resolve(value).then(_next, _throw);
25
+ }
26
+ }
27
+ function _async_to_generator(fn) {
28
+ return function() {
29
+ var self = this, args = arguments;
30
+ return new Promise(function(resolve, reject) {
31
+ var gen = fn.apply(self, args);
32
+ function _next(value) {
33
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
34
+ }
35
+ function _throw(err) {
36
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
37
+ }
38
+ _next(undefined);
39
+ });
40
+ };
41
+ }
42
+ function _define_property(obj, key, value) {
43
+ if (key in obj) {
44
+ Object.defineProperty(obj, key, {
45
+ value: value,
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true
49
+ });
50
+ } else {
51
+ obj[key] = value;
52
+ }
53
+ return obj;
54
+ }
55
+ function _iterable_to_array(iter) {
56
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
57
+ }
58
+ function _iterable_to_array_limit(arr, i) {
59
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
60
+ if (_i == null) return;
61
+ var _arr = [];
62
+ var _n = true;
63
+ var _d = false;
64
+ var _s, _e;
65
+ try {
66
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
67
+ _arr.push(_s.value);
68
+ if (i && _arr.length === i) break;
69
+ }
70
+ } catch (err) {
71
+ _d = true;
72
+ _e = err;
73
+ } finally{
74
+ try {
75
+ if (!_n && _i["return"] != null) _i["return"]();
76
+ } finally{
77
+ if (_d) throw _e;
78
+ }
79
+ }
80
+ return _arr;
81
+ }
82
+ function _non_iterable_rest() {
83
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
84
+ }
85
+ function _non_iterable_spread() {
86
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
87
+ }
88
+ function _object_spread(target) {
89
+ for(var i = 1; i < arguments.length; i++){
90
+ var source = arguments[i] != null ? arguments[i] : {};
91
+ var ownKeys = Object.keys(source);
92
+ if (typeof Object.getOwnPropertySymbols === "function") {
93
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
94
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
95
+ }));
96
+ }
97
+ ownKeys.forEach(function(key) {
98
+ _define_property(target, key, source[key]);
99
+ });
100
+ }
101
+ return target;
102
+ }
103
+ function ownKeys(object, enumerableOnly) {
104
+ var keys = Object.keys(object);
105
+ if (Object.getOwnPropertySymbols) {
106
+ var symbols = Object.getOwnPropertySymbols(object);
107
+ if (enumerableOnly) {
108
+ symbols = symbols.filter(function(sym) {
109
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
110
+ });
111
+ }
112
+ keys.push.apply(keys, symbols);
113
+ }
114
+ return keys;
115
+ }
116
+ function _object_spread_props(target, source) {
117
+ source = source != null ? source : {};
118
+ if (Object.getOwnPropertyDescriptors) {
119
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
120
+ } else {
121
+ ownKeys(Object(source)).forEach(function(key) {
122
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
123
+ });
124
+ }
125
+ return target;
126
+ }
127
+ function _sliced_to_array(arr, i) {
128
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
129
+ }
130
+ function _to_consumable_array(arr) {
131
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
132
+ }
133
+ function _type_of(obj) {
134
+ "@swc/helpers - typeof";
135
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
136
+ }
137
+ function _unsupported_iterable_to_array(o, minLen) {
138
+ if (!o) return;
139
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
140
+ var n = Object.prototype.toString.call(o).slice(8, -1);
141
+ if (n === "Object" && o.constructor) n = o.constructor.name;
142
+ if (n === "Map" || n === "Set") return Array.from(n);
143
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
144
+ }
145
+ function _ts_generator(thisArg, body) {
146
+ var f, y, t, g, _ = {
147
+ label: 0,
148
+ sent: function() {
149
+ if (t[0] & 1) throw t[1];
150
+ return t[1];
151
+ },
152
+ trys: [],
153
+ ops: []
154
+ };
155
+ return g = {
156
+ next: verb(0),
157
+ "throw": verb(1),
158
+ "return": verb(2)
159
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
160
+ return this;
161
+ }), g;
162
+ function verb(n) {
163
+ return function(v) {
164
+ return step([
165
+ n,
166
+ v
167
+ ]);
168
+ };
169
+ }
170
+ function step(op) {
171
+ if (f) throw new TypeError("Generator is already executing.");
172
+ while(_)try {
173
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
174
+ if (y = 0, t) op = [
175
+ op[0] & 2,
176
+ t.value
177
+ ];
178
+ switch(op[0]){
179
+ case 0:
180
+ case 1:
181
+ t = op;
182
+ break;
183
+ case 4:
184
+ _.label++;
185
+ return {
186
+ value: op[1],
187
+ done: false
188
+ };
189
+ case 5:
190
+ _.label++;
191
+ y = op[1];
192
+ op = [
193
+ 0
194
+ ];
195
+ continue;
196
+ case 7:
197
+ op = _.ops.pop();
198
+ _.trys.pop();
199
+ continue;
200
+ default:
201
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
202
+ _ = 0;
203
+ continue;
204
+ }
205
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
206
+ _.label = op[1];
207
+ break;
208
+ }
209
+ if (op[0] === 6 && _.label < t[1]) {
210
+ _.label = t[1];
211
+ t = op;
212
+ break;
213
+ }
214
+ if (t && _.label < t[2]) {
215
+ _.label = t[2];
216
+ _.ops.push(op);
217
+ break;
218
+ }
219
+ if (t[2]) _.ops.pop();
220
+ _.trys.pop();
221
+ continue;
222
+ }
223
+ op = body.call(thisArg, _);
224
+ } catch (e) {
225
+ op = [
226
+ 6,
227
+ e
228
+ ];
229
+ y = 0;
230
+ } finally{
231
+ f = t = 0;
232
+ }
233
+ if (op[0] & 5) throw op[1];
234
+ return {
235
+ value: op[0] ? op[1] : void 0,
236
+ done: true
237
+ };
238
+ }
239
+ }
240
+ // src/cli.ts
241
+ import process4 from "node:process";
242
+ import { hideBin } from "yargs/helpers";
243
+ import yargs from "yargs/yargs";
244
+ // src/constants/path.ts
245
+ import process3 from "node:process";
246
+ import { fileURLToPath } from "node:url";
247
+ // src/utils/command.ts
248
+ import boxen from "boxen";
249
+ import chalk from "chalk";
250
+ import { exec } from "node:child_process";
251
+ import process2 from "node:process";
252
+ import * as util from "node:util";
253
+ // src/utils/package.ts
254
+ import fetch from "node-fetch";
255
+ // src/utils/fs.ts
256
+ import * as fs from "node:fs";
257
+ var existsSync2 = function(filePath) {
258
+ return fs.existsSync(filePath);
259
+ };
260
+ function readFileSync2(filePath, options) {
261
+ var content = fs.readFileSync(filePath, "utf-8");
262
+ if (options === null || options === void 0 ? void 0 : options.asJson) {
263
+ try {
264
+ var parsed = JSON.parse(content);
265
+ if ((typeof parsed === "undefined" ? "undefined" : _type_of(parsed)) === "object" && parsed !== null) {
266
+ return parsed;
267
+ }
268
+ throw new Error("Parsed JSON is not an object or array");
269
+ } catch (e) {
270
+ throw new Error("Failed to parse JSON from file: ".concat(filePath));
271
+ }
272
+ }
273
+ return content;
274
+ }
275
+ function writeFileSync2(filePath, data) {
276
+ var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
277
+ var _options_isJson = options.isJson, isJson = _options_isJson === void 0 ? false : _options_isJson;
278
+ var content = isJson && (typeof data === "undefined" ? "undefined" : _type_of(data)) === "object" ? JSON.stringify(data, null, 4) : String(data);
279
+ fs.writeFileSync(filePath, content, "utf-8");
280
+ }
281
+ function appendFileSync2(filePath, data) {
282
+ var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
283
+ var _options_isJson = options.isJson, isJson = _options_isJson === void 0 ? false : _options_isJson;
284
+ var content = isJson && (typeof data === "undefined" ? "undefined" : _type_of(data)) === "object" ? JSON.stringify(data, null, 4) : String(data);
285
+ fs.appendFileSync(filePath, content, "utf-8");
286
+ }
287
+ // src/utils/path.ts
288
+ import * as path from "node:path";
289
+ function resolveCyberSkillPath() {
290
+ for(var _len = arguments.length, urls = new Array(_len), _key = 0; _key < _len; _key++){
291
+ urls[_key] = arguments[_key];
292
+ }
293
+ var _path;
294
+ return (_path = path).resolve.apply(_path, [
295
+ CYBERSKILL_DIRECTORY
296
+ ].concat(_to_consumable_array(urls)));
297
+ }
298
+ function resolveWorkingPath() {
299
+ for(var _len = arguments.length, urls = new Array(_len), _key = 0; _key < _len; _key++){
300
+ urls[_key] = arguments[_key];
301
+ }
302
+ var _path;
303
+ return (_path = path).resolve.apply(_path, [
304
+ WORKING_DIRECTORY
305
+ ].concat(_to_consumable_array(urls)));
306
+ }
307
+ function resolve2() {
308
+ for(var _len = arguments.length, urls = new Array(_len), _key = 0; _key < _len; _key++){
309
+ urls[_key] = arguments[_key];
310
+ }
311
+ var _path;
312
+ return (_path = path).resolve.apply(_path, _to_consumable_array(urls));
313
+ }
314
+ function dirname2(url) {
315
+ return path.dirname(url);
316
+ }
317
+ function join2() {
318
+ for(var _len = arguments.length, urls = new Array(_len), _key = 0; _key < _len; _key++){
319
+ urls[_key] = arguments[_key];
320
+ }
321
+ var _path;
322
+ return (_path = path).join.apply(_path, _to_consumable_array(urls));
323
+ }
324
+ // src/utils/storage-server.ts
325
+ import nodePersist from "node-persist";
326
+ import os from "node:os";
327
+ import path2 from "node:path";
328
+ import process from "node:process";
329
+ function getStorageDir() {
330
+ return process.env.CYBERSKILL_STORAGE_DIR || path2.join(os.homedir(), CYBERSKILL_STORAGE);
331
+ }
332
+ function initNodePersist() {
333
+ return _initNodePersist.apply(this, arguments);
334
+ }
335
+ function _initNodePersist() {
336
+ _initNodePersist = _async_to_generator(function() {
337
+ return _ts_generator(this, function(_state) {
338
+ switch(_state.label){
339
+ case 0:
340
+ if (!!nodePersist.defaultInstance) return [
341
+ 3,
342
+ 2
343
+ ];
344
+ return [
345
+ 4,
346
+ nodePersist.init({
347
+ dir: getStorageDir(),
348
+ stringify: JSON.stringify,
349
+ parse: JSON.parse,
350
+ encoding: "utf8",
351
+ logging: false,
352
+ forgiveParseErrors: true
353
+ })
354
+ ];
355
+ case 1:
356
+ _state.sent();
357
+ _state.label = 2;
358
+ case 2:
359
+ return [
360
+ 2
361
+ ];
362
+ }
363
+ });
364
+ });
365
+ return _initNodePersist.apply(this, arguments);
366
+ }
367
+ var storageServer = {
368
+ get: function get(key) {
369
+ return _async_to_generator(function() {
370
+ var result, error;
371
+ return _ts_generator(this, function(_state) {
372
+ switch(_state.label){
373
+ case 0:
374
+ _state.trys.push([
375
+ 0,
376
+ 3,
377
+ ,
378
+ 4
379
+ ]);
380
+ return [
381
+ 4,
382
+ initNodePersist()
383
+ ];
384
+ case 1:
385
+ _state.sent();
386
+ return [
387
+ 4,
388
+ nodePersist.getItem(key)
389
+ ];
390
+ case 2:
391
+ result = _state.sent();
392
+ return [
393
+ 2,
394
+ result !== null && result !== void 0 ? result : null
395
+ ];
396
+ case 3:
397
+ error = _state.sent();
398
+ console.error('❌ [Storage:get] Error getting key "'.concat(key, '":'), error);
399
+ return [
400
+ 2,
401
+ null
402
+ ];
403
+ case 4:
404
+ return [
405
+ 2
406
+ ];
407
+ }
408
+ });
409
+ })();
410
+ },
411
+ set: function set(key, value) {
412
+ return _async_to_generator(function() {
413
+ var error;
414
+ return _ts_generator(this, function(_state) {
415
+ switch(_state.label){
416
+ case 0:
417
+ _state.trys.push([
418
+ 0,
419
+ 3,
420
+ ,
421
+ 4
422
+ ]);
423
+ return [
424
+ 4,
425
+ initNodePersist()
426
+ ];
427
+ case 1:
428
+ _state.sent();
429
+ return [
430
+ 4,
431
+ nodePersist.setItem(key, value)
432
+ ];
433
+ case 2:
434
+ _state.sent();
435
+ return [
436
+ 3,
437
+ 4
438
+ ];
439
+ case 3:
440
+ error = _state.sent();
441
+ console.error('❌ [Storage:set] Error setting key "'.concat(key, '":'), error);
442
+ return [
443
+ 3,
444
+ 4
445
+ ];
446
+ case 4:
447
+ return [
448
+ 2
449
+ ];
450
+ }
451
+ });
452
+ })();
453
+ },
454
+ remove: function remove(key) {
455
+ return _async_to_generator(function() {
456
+ var error;
457
+ return _ts_generator(this, function(_state) {
458
+ switch(_state.label){
459
+ case 0:
460
+ _state.trys.push([
461
+ 0,
462
+ 3,
463
+ ,
464
+ 4
465
+ ]);
466
+ return [
467
+ 4,
468
+ initNodePersist()
469
+ ];
470
+ case 1:
471
+ _state.sent();
472
+ return [
473
+ 4,
474
+ nodePersist.removeItem(key)
475
+ ];
476
+ case 2:
477
+ _state.sent();
478
+ return [
479
+ 3,
480
+ 4
481
+ ];
482
+ case 3:
483
+ error = _state.sent();
484
+ console.error('❌ [Storage:remove] Error removing key "'.concat(key, '":'), error);
485
+ return [
486
+ 3,
487
+ 4
488
+ ];
489
+ case 4:
490
+ return [
491
+ 2
492
+ ];
493
+ }
494
+ });
495
+ })();
496
+ },
497
+ keys: function keys() {
498
+ return _async_to_generator(function() {
499
+ var keys, error;
500
+ return _ts_generator(this, function(_state) {
501
+ switch(_state.label){
502
+ case 0:
503
+ _state.trys.push([
504
+ 0,
505
+ 3,
506
+ ,
507
+ 4
508
+ ]);
509
+ return [
510
+ 4,
511
+ initNodePersist()
512
+ ];
513
+ case 1:
514
+ _state.sent();
515
+ return [
516
+ 4,
517
+ nodePersist.keys()
518
+ ];
519
+ case 2:
520
+ keys = _state.sent();
521
+ if (!Array.isArray(keys)) {
522
+ console.warn("⚠️ [Storage:keys] Invalid keys response:", keys);
523
+ return [
524
+ 2,
525
+ []
526
+ ];
527
+ }
528
+ return [
529
+ 2,
530
+ keys
531
+ ];
532
+ case 3:
533
+ error = _state.sent();
534
+ console.error("❌ [Storage:keys] Error getting keys:", error);
535
+ return [
536
+ 2,
537
+ []
538
+ ];
539
+ case 4:
540
+ return [
541
+ 2
542
+ ];
543
+ }
544
+ });
545
+ })();
546
+ },
547
+ getLogLink: function getLogLink(key) {
548
+ return _async_to_generator(function() {
549
+ var storagePath;
550
+ return _ts_generator(this, function(_state) {
551
+ try {
552
+ storagePath = getStorageDir();
553
+ return [
554
+ 2,
555
+ "".concat(storagePath, " (key: ").concat(key, ")")
556
+ ];
557
+ } catch (error) {
558
+ console.error("❌ [Storage:getLogLink] Error getting log link:", error);
559
+ return [
560
+ 2,
561
+ null
562
+ ];
563
+ }
564
+ return [
565
+ 2
566
+ ];
567
+ });
568
+ })();
569
+ }
570
+ };
571
+ // src/utils/package.ts
572
+ var CACHE_EXPIRATION_MS = 24 * 60 * 60 * 1e3;
573
+ function getPackageJson(packageName) {
574
+ var workingPackageJsonPath = join2(WORKING_DIRECTORY, PACKAGE_JSON);
575
+ if (existsSync2(workingPackageJsonPath)) {
576
+ try {
577
+ var pkg = readFileSync2(workingPackageJsonPath, {
578
+ asJson: true
579
+ });
580
+ if (pkg.name === packageName) {
581
+ return {
582
+ path: workingPackageJsonPath,
583
+ file: pkg
584
+ };
585
+ }
586
+ } catch (error) {
587
+ commandLog.warning("Failed to read local package.json: ".concat(error.message));
588
+ }
589
+ }
590
+ var externalPackageJsonPath = join2(WORKING_DIRECTORY, NODE_MODULES, packageName, PACKAGE_JSON);
591
+ if (existsSync2(externalPackageJsonPath)) {
592
+ try {
593
+ var pkg1 = readFileSync2(externalPackageJsonPath, {
594
+ asJson: true
595
+ });
596
+ if (pkg1.name === packageName) {
597
+ return {
598
+ path: externalPackageJsonPath,
599
+ file: pkg1
600
+ };
601
+ }
602
+ } catch (error) {
603
+ commandLog.warning("Failed to read node_modules package.json for ".concat(packageName, ": ").concat(error.message));
604
+ }
605
+ }
606
+ return false;
607
+ }
608
+ function getLatestPackageVersion(packageName) {
609
+ return _getLatestPackageVersion.apply(this, arguments);
610
+ }
611
+ function _getLatestPackageVersion() {
612
+ _getLatestPackageVersion = _async_to_generator(function(packageName) {
613
+ var forceRefresh, versionCacheKey, metadataCacheKey, cached, metadata, isCacheValid, headers, response, data, latestVersion, error;
614
+ var _arguments = arguments;
615
+ return _ts_generator(this, function(_state) {
616
+ switch(_state.label){
617
+ case 0:
618
+ forceRefresh = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : false;
619
+ versionCacheKey = "npm_version:".concat(packageName);
620
+ metadataCacheKey = "npm_metadata:".concat(packageName);
621
+ return [
622
+ 4,
623
+ storageServer.get(versionCacheKey)
624
+ ];
625
+ case 1:
626
+ cached = _state.sent();
627
+ return [
628
+ 4,
629
+ storageServer.get(metadataCacheKey)
630
+ ];
631
+ case 2:
632
+ metadata = _state.sent();
633
+ isCacheValid = cached && Date.now() - cached.timestamp < CACHE_EXPIRATION_MS;
634
+ if (!forceRefresh && isCacheValid) {
635
+ return [
636
+ 2,
637
+ cached.version
638
+ ];
639
+ }
640
+ headers = {};
641
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.etag) {
642
+ headers["If-None-Match"] = metadata.etag;
643
+ }
644
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.lastModified) {
645
+ headers["If-Modified-Since"] = metadata.lastModified;
646
+ }
647
+ _state.label = 3;
648
+ case 3:
649
+ _state.trys.push([
650
+ 3,
651
+ 8,
652
+ ,
653
+ 9
654
+ ]);
655
+ return [
656
+ 4,
657
+ fetch("https://registry.npmjs.org/".concat(packageName, "/latest"), {
658
+ headers: headers
659
+ })
660
+ ];
661
+ case 4:
662
+ response = _state.sent();
663
+ if (response.status === 304 && cached) {
664
+ return [
665
+ 2,
666
+ cached.version
667
+ ];
668
+ }
669
+ if (!response.ok) {
670
+ throw new Error("Failed to fetch latest version: ".concat(response.statusText));
671
+ }
672
+ return [
673
+ 4,
674
+ response.json()
675
+ ];
676
+ case 5:
677
+ data = _state.sent();
678
+ latestVersion = data.version;
679
+ return [
680
+ 4,
681
+ storageServer.set(versionCacheKey, {
682
+ version: latestVersion,
683
+ timestamp: Date.now()
684
+ })
685
+ ];
686
+ case 6:
687
+ _state.sent();
688
+ return [
689
+ 4,
690
+ storageServer.set(metadataCacheKey, {
691
+ etag: response.headers.get("ETag") || void 0,
692
+ lastModified: response.headers.get("Last-Modified") || void 0
693
+ })
694
+ ];
695
+ case 7:
696
+ _state.sent();
697
+ return [
698
+ 2,
699
+ latestVersion
700
+ ];
701
+ case 8:
702
+ error = _state.sent();
703
+ commandLog.error("Error fetching latest version for ".concat(packageName, ": ").concat(error.message));
704
+ if (cached) {
705
+ commandLog.warning("Falling back to cached version for ".concat(packageName, ": ").concat(cached.version));
706
+ return [
707
+ 2,
708
+ cached.version
709
+ ];
710
+ }
711
+ throw error;
712
+ case 9:
713
+ return [
714
+ 2
715
+ ];
716
+ }
717
+ });
718
+ });
719
+ return _getLatestPackageVersion.apply(this, arguments);
720
+ }
721
+ function checkPackage(packageName) {
722
+ return _checkPackage.apply(this, arguments);
723
+ }
724
+ function _checkPackage() {
725
+ _checkPackage = _async_to_generator(function(packageName) {
726
+ var result, packageFound, cyberskillPackageJsonPath, isCurrentProject, _tmp, error;
727
+ return _ts_generator(this, function(_state) {
728
+ switch(_state.label){
729
+ case 0:
730
+ result = {
731
+ isInstalled: false,
732
+ isCurrentProject: false,
733
+ installedPath: "",
734
+ installedVersion: "",
735
+ latestVersion: "",
736
+ file: {}
737
+ };
738
+ _state.label = 1;
739
+ case 1:
740
+ _state.trys.push([
741
+ 1,
742
+ 5,
743
+ ,
744
+ 6
745
+ ]);
746
+ packageFound = getPackageJson(packageName);
747
+ if (!packageFound) {
748
+ return [
749
+ 2,
750
+ result
751
+ ];
752
+ }
753
+ cyberskillPackageJsonPath = resolveCyberSkillPath(PACKAGE_JSON);
754
+ isCurrentProject = packageFound.path === cyberskillPackageJsonPath;
755
+ result.file = packageFound.file;
756
+ result.isInstalled = true;
757
+ result.installedPath = packageFound.path;
758
+ result.installedVersion = packageFound.file.version;
759
+ result.isCurrentProject = isCurrentProject;
760
+ if (!isCurrentProject) return [
761
+ 3,
762
+ 2
763
+ ];
764
+ _tmp = packageFound.file.version;
765
+ return [
766
+ 3,
767
+ 4
768
+ ];
769
+ case 2:
770
+ return [
771
+ 4,
772
+ getLatestPackageVersion(packageName, true)
773
+ ];
774
+ case 3:
775
+ _tmp = _state.sent();
776
+ _state.label = 4;
777
+ case 4:
778
+ result.latestVersion = _tmp;
779
+ return [
780
+ 2,
781
+ result
782
+ ];
783
+ case 5:
784
+ error = _state.sent();
785
+ commandLog.error('Error checking package "'.concat(packageName, '": ').concat(error.message));
786
+ return [
787
+ 2,
788
+ result
789
+ ];
790
+ case 6:
791
+ return [
792
+ 2
793
+ ];
794
+ }
795
+ });
796
+ });
797
+ return _checkPackage.apply(this, arguments);
798
+ }
799
+ // src/utils/command.ts
800
+ var DEBUG = process2.env.DEBUG === "true";
801
+ var execPromise = util.promisify(exec);
802
+ var gray = chalk.gray, blue = chalk.blue;
803
+ var getTimeStamp = function() {
804
+ return gray("[".concat(/* @__PURE__ */ new Date().toLocaleTimeString(), "]"));
805
+ };
806
+ function chalkKeyword(color) {
807
+ var chalkColor = chalk[color];
808
+ return typeof chalkColor === "function" ? chalkColor : chalk.green;
809
+ }
810
+ function printLog(type, color, icon, message) {
811
+ var chalkColor = chalkKeyword(color);
812
+ console.log("".concat(getTimeStamp(), " ").concat(chalkColor("".concat(icon, " ").concat(type)), " ").concat(message));
813
+ }
814
+ function printBoxedLog(title, content) {
815
+ var _ref = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, _ref_color = _ref.color, color = _ref_color === void 0 ? "green" : _ref_color, _ref_padding = _ref.padding, padding = _ref_padding === void 0 ? 1 : _ref_padding, _ref_margin = _ref.margin, margin = _ref_margin === void 0 ? 1 : _ref_margin, _ref_borderStyle = _ref.borderStyle, borderStyle = _ref_borderStyle === void 0 ? "round" : _ref_borderStyle, _ref_titleColor = _ref.titleColor, titleColor = _ref_titleColor === void 0 ? "bold" : _ref_titleColor;
816
+ var chalkColor = chalkKeyword(color);
817
+ var chalkTitleColor = chalkKeyword(titleColor);
818
+ if (typeof content === "string") {
819
+ console.log(boxen(chalkTitleColor(chalkColor("".concat(title, "\n").concat(content))), {
820
+ padding: padding,
821
+ margin: margin,
822
+ borderStyle: borderStyle,
823
+ borderColor: color
824
+ }));
825
+ return;
826
+ }
827
+ if (Array.isArray(content) && content.length) {
828
+ content.forEach(function(param) {
829
+ var file = param.file, position = param.position, rule = param.rule, message = param.message;
830
+ console.log("".concat(getTimeStamp(), " ").concat(chalkColor("File:"), " ").concat(blue("".concat(file).concat(position ? ":".concat(position) : ""))));
831
+ if (rule) console.log(" ".concat(chalkColor("Rule:"), " ").concat(chalkColor(rule)));
832
+ console.log(" ".concat(chalkColor("Message:"), " ").concat(chalkColor(message)));
833
+ });
834
+ console.log(boxen(chalkTitleColor(chalkColor("".concat(title, ": ").concat(content.length))), {
835
+ padding: padding,
836
+ margin: margin,
837
+ borderStyle: borderStyle,
838
+ borderColor: color
839
+ }));
840
+ console.log(gray("\u2500".repeat(40)));
841
+ }
842
+ }
843
+ var commandLog = {
844
+ success: function(message) {
845
+ return printLog("SUCCESS", "green", "\u2714", message);
846
+ },
847
+ error: function(message) {
848
+ return printLog("ERROR", "red", "\u2716", message);
849
+ },
850
+ warning: function(message) {
851
+ return printLog("WARNING", "yellow", "\u26A0", message);
852
+ },
853
+ info: function(message) {
854
+ return printLog("INFO", "blue", "\u2139", message);
855
+ },
856
+ printBoxedLog: printBoxedLog
857
+ };
858
+ var getErrorListKey = function(timestamp) {
859
+ return "error_list:".concat(timestamp);
860
+ };
861
+ function saveErrorListToStorage(errorList) {
862
+ return _saveErrorListToStorage.apply(this, arguments);
863
+ }
864
+ function _saveErrorListToStorage() {
865
+ _saveErrorListToStorage = _async_to_generator(function(errorList) {
866
+ var timestamp, key, error;
867
+ return _ts_generator(this, function(_state) {
868
+ switch(_state.label){
869
+ case 0:
870
+ if (errorList.length === 0) {
871
+ return [
872
+ 2
873
+ ];
874
+ }
875
+ timestamp = Date.now();
876
+ key = getErrorListKey(timestamp);
877
+ _state.label = 1;
878
+ case 1:
879
+ _state.trys.push([
880
+ 1,
881
+ 3,
882
+ ,
883
+ 4
884
+ ]);
885
+ return [
886
+ 4,
887
+ storageServer.set(key, {
888
+ errors: errorList,
889
+ timestamp: timestamp
890
+ })
891
+ ];
892
+ case 2:
893
+ _state.sent();
894
+ setTimeout(/*#__PURE__*/ _async_to_generator(function() {
895
+ var logPath;
896
+ return _ts_generator(this, function(_state) {
897
+ switch(_state.label){
898
+ case 0:
899
+ return [
900
+ 4,
901
+ storageServer.getLogLink(key)
902
+ ];
903
+ case 1:
904
+ logPath = _state.sent();
905
+ if (logPath) {
906
+ commandLog.info("\uD83D\uDCC2 Open the error list manually: ".concat(logPath));
907
+ }
908
+ return [
909
+ 2
910
+ ];
911
+ }
912
+ });
913
+ }), 10);
914
+ return [
915
+ 3,
916
+ 4
917
+ ];
918
+ case 3:
919
+ error = _state.sent();
920
+ commandLog.error("Failed to save errors: ".concat(error.message));
921
+ return [
922
+ 3,
923
+ 4
924
+ ];
925
+ case 4:
926
+ return [
927
+ 2
928
+ ];
929
+ }
930
+ });
931
+ });
932
+ return _saveErrorListToStorage.apply(this, arguments);
933
+ }
934
+ function getStoredErrorLists() {
935
+ return _getStoredErrorLists.apply(this, arguments);
936
+ }
937
+ function _getStoredErrorLists() {
938
+ _getStoredErrorLists = _async_to_generator(function() {
939
+ var keys, errorKeys, allErrors, error;
940
+ return _ts_generator(this, function(_state) {
941
+ switch(_state.label){
942
+ case 0:
943
+ _state.trys.push([
944
+ 0,
945
+ 3,
946
+ ,
947
+ 4
948
+ ]);
949
+ return [
950
+ 4,
951
+ storageServer.keys()
952
+ ];
953
+ case 1:
954
+ keys = _state.sent();
955
+ errorKeys = Array.isArray(keys) ? keys.filter(function(key) {
956
+ var _key_startsWith;
957
+ return key === null || key === void 0 ? void 0 : (_key_startsWith = key.startsWith) === null || _key_startsWith === void 0 ? void 0 : _key_startsWith.call(key, "error_list:");
958
+ }) : [];
959
+ return [
960
+ 4,
961
+ Promise.all(errorKeys.map(/*#__PURE__*/ function() {
962
+ var _ref = _async_to_generator(function(key) {
963
+ var entry;
964
+ return _ts_generator(this, function(_state) {
965
+ switch(_state.label){
966
+ case 0:
967
+ return [
968
+ 4,
969
+ storageServer.get(key)
970
+ ];
971
+ case 1:
972
+ entry = _state.sent();
973
+ return [
974
+ 2,
975
+ (entry === null || entry === void 0 ? void 0 : entry.errors) || []
976
+ ];
977
+ }
978
+ });
979
+ });
980
+ return function(key) {
981
+ return _ref.apply(this, arguments);
982
+ };
983
+ }()))
984
+ ];
985
+ case 2:
986
+ allErrors = _state.sent();
987
+ return [
988
+ 2,
989
+ allErrors.flat()
990
+ ];
991
+ case 3:
992
+ error = _state.sent();
993
+ commandLog.error("Failed to retrieve stored errors: ".concat(error.message));
994
+ return [
995
+ 2,
996
+ []
997
+ ];
998
+ case 4:
999
+ return [
1000
+ 2
1001
+ ];
1002
+ }
1003
+ });
1004
+ });
1005
+ return _getStoredErrorLists.apply(this, arguments);
1006
+ }
1007
+ function clearAllErrorLists() {
1008
+ return _clearAllErrorLists.apply(this, arguments);
1009
+ }
1010
+ function _clearAllErrorLists() {
1011
+ _clearAllErrorLists = _async_to_generator(function() {
1012
+ var keys, errorKeys, error;
1013
+ return _ts_generator(this, function(_state) {
1014
+ switch(_state.label){
1015
+ case 0:
1016
+ _state.trys.push([
1017
+ 0,
1018
+ 3,
1019
+ ,
1020
+ 4
1021
+ ]);
1022
+ return [
1023
+ 4,
1024
+ storageServer.keys()
1025
+ ];
1026
+ case 1:
1027
+ keys = _state.sent();
1028
+ errorKeys = Array.isArray(keys) ? keys.filter(function(key) {
1029
+ var _key_startsWith;
1030
+ return key === null || key === void 0 ? void 0 : (_key_startsWith = key.startsWith) === null || _key_startsWith === void 0 ? void 0 : _key_startsWith.call(key, "error_list:");
1031
+ }) : [];
1032
+ return [
1033
+ 4,
1034
+ Promise.all(errorKeys.map(function(key) {
1035
+ return storageServer.remove(key);
1036
+ }))
1037
+ ];
1038
+ case 2:
1039
+ _state.sent();
1040
+ return [
1041
+ 3,
1042
+ 4
1043
+ ];
1044
+ case 3:
1045
+ error = _state.sent();
1046
+ commandLog.error("Failed to clear error lists: ".concat(error.message));
1047
+ return [
1048
+ 3,
1049
+ 4
1050
+ ];
1051
+ case 4:
1052
+ return [
1053
+ 2
1054
+ ];
1055
+ }
1056
+ });
1057
+ });
1058
+ return _clearAllErrorLists.apply(this, arguments);
1059
+ }
1060
+ function parseTextErrors(output) {
1061
+ var errorList = [];
1062
+ var unmatchedLines = [];
1063
+ var lastFilePath = "";
1064
+ var eslintErrorDetailsRegex = /^\s*(\d+):(\d+)\s+(error|warning)\s+(.+?)\s+(\S+)$/;
1065
+ var tsRegex = /^(.+?)\((\d+),(\d+)\):\s+(error|warning)\s+TS\d+:\s+(\S.+)$/;
1066
+ var commitlintRegex = /^✖\s+(.*?)\s+\[(.*?)\]$/;
1067
+ output.split("\n").forEach(function(line) {
1068
+ if (line.startsWith("/")) {
1069
+ lastFilePath = line.trim();
1070
+ } else {
1071
+ var eslintMatch = eslintErrorDetailsRegex.exec(line) || [];
1072
+ var tsMatch = tsRegex.exec(line) || [];
1073
+ var commitlintMatch = commitlintRegex.exec(line) || [];
1074
+ if (eslintMatch.length && lastFilePath) {
1075
+ errorList.push({
1076
+ file: lastFilePath,
1077
+ position: "".concat(eslintMatch[1], ":").concat(eslintMatch[2]),
1078
+ type: eslintMatch[3] === "error" /* Error */ ? "error" /* Error */ : "warning" /* Warning */ ,
1079
+ message: eslintMatch[4].trim(),
1080
+ rule: eslintMatch[5].trim()
1081
+ });
1082
+ } else if (tsMatch.length) {
1083
+ errorList.push({
1084
+ file: tsMatch[1],
1085
+ position: "".concat(tsMatch[2], ":").concat(tsMatch[3]),
1086
+ type: tsMatch[4] === "error" /* Error */ ? "error" /* Error */ : "warning" /* Warning */ ,
1087
+ message: tsMatch[5].trim()
1088
+ });
1089
+ } else if (commitlintMatch.length) {
1090
+ errorList.push({
1091
+ file: "commitlint",
1092
+ type: "error" /* Error */ ,
1093
+ message: commitlintMatch[1].trim(),
1094
+ rule: commitlintMatch[2].trim()
1095
+ });
1096
+ } else {
1097
+ unmatchedLines.push(line.trim());
1098
+ }
1099
+ }
1100
+ });
1101
+ if (errorList.length) {
1102
+ saveErrorListToStorage(errorList);
1103
+ }
1104
+ if (unmatchedLines.length && DEBUG) {
1105
+ commandLog.warning("Unmatched lines:");
1106
+ unmatchedLines.forEach(function(line) {
1107
+ return console.log(" ".concat(line));
1108
+ });
1109
+ }
1110
+ }
1111
+ function parseCommandOutput(output) {
1112
+ try {
1113
+ var results = JSON.parse(output);
1114
+ var errorList = [];
1115
+ results.forEach(function(param) {
1116
+ var filePath = param.filePath, messages = param.messages;
1117
+ messages.forEach(function(param) {
1118
+ var severity = param.severity, line = param.line, column = param.column, ruleId = param.ruleId, message = param.message;
1119
+ errorList.push({
1120
+ type: severity === 2 ? "error" /* Error */ : "warning" /* Warning */ ,
1121
+ file: filePath,
1122
+ position: "".concat(line, ":").concat(column),
1123
+ rule: ruleId,
1124
+ message: message
1125
+ });
1126
+ });
1127
+ });
1128
+ if (errorList.length) {
1129
+ saveErrorListToStorage(errorList);
1130
+ }
1131
+ } catch (e) {
1132
+ parseTextErrors(output);
1133
+ }
1134
+ }
1135
+ function executeCommand(command) {
1136
+ return _executeCommand.apply(this, arguments);
1137
+ }
1138
+ function _executeCommand() {
1139
+ _executeCommand = _async_to_generator(function(command) {
1140
+ var parser, controller, _ref, stdout, stderr, error, stdout1, stderr1, message;
1141
+ var _arguments = arguments;
1142
+ return _ts_generator(this, function(_state) {
1143
+ switch(_state.label){
1144
+ case 0:
1145
+ parser = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : parseCommandOutput;
1146
+ controller = new AbortController();
1147
+ process2.on("SIGINT", function() {
1148
+ commandLog.warning("Process interrupted. Terminating...");
1149
+ controller.abort();
1150
+ process2.exit();
1151
+ });
1152
+ _state.label = 1;
1153
+ case 1:
1154
+ _state.trys.push([
1155
+ 1,
1156
+ 3,
1157
+ ,
1158
+ 4
1159
+ ]);
1160
+ return [
1161
+ 4,
1162
+ execPromise(command, {
1163
+ maxBuffer: 1024 * 1024 * 100,
1164
+ signal: controller.signal
1165
+ })
1166
+ ];
1167
+ case 2:
1168
+ _ref = _state.sent(), stdout = _ref.stdout, stderr = _ref.stderr;
1169
+ [
1170
+ stdout,
1171
+ stderr
1172
+ ].forEach(function(output) {
1173
+ return output && parser(output);
1174
+ });
1175
+ return [
1176
+ 3,
1177
+ 4
1178
+ ];
1179
+ case 3:
1180
+ error = _state.sent();
1181
+ stdout1 = error.stdout, stderr1 = error.stderr, message = error.message;
1182
+ [
1183
+ stdout1,
1184
+ stderr1
1185
+ ].forEach(function(output) {
1186
+ return output && parser(output);
1187
+ });
1188
+ if (!stderr1 && !stdout1) {
1189
+ commandLog.error("Command failed: ".concat(message));
1190
+ }
1191
+ return [
1192
+ 3,
1193
+ 4
1194
+ ];
1195
+ case 4:
1196
+ return [
1197
+ 2
1198
+ ];
1199
+ }
1200
+ });
1201
+ });
1202
+ return _executeCommand.apply(this, arguments);
1203
+ }
1204
+ var commandFormatter = {
1205
+ raw: function(cmd) {
1206
+ return {
1207
+ raw: true,
1208
+ cmd: cmd
1209
+ };
1210
+ },
1211
+ isRaw: function isRaw(cmd) {
1212
+ return (typeof cmd === "undefined" ? "undefined" : _type_of(cmd)) === "object" && cmd !== null && cmd.raw === true;
1213
+ },
1214
+ format: function format(command, context) {
1215
+ if (typeof command === "function") {
1216
+ return commandFormatter.formatCLI(command(context), context);
1217
+ }
1218
+ if (commandFormatter.isRaw(command)) {
1219
+ return command.cmd;
1220
+ }
1221
+ return commandFormatter.formatCLI(command, context);
1222
+ },
1223
+ formatCLI: function formatCLI(command, context) {
1224
+ if (context === null || context === void 0 ? void 0 : context.isRemote) {
1225
+ return "".concat(PNPM_DLX_CLI, " ").concat(CYBERSKILL_PACKAGE_NAME, " ").concat(command);
1226
+ }
1227
+ if (context === null || context === void 0 ? void 0 : context.isCurrentProject) {
1228
+ return "".concat(PNPM_EXEC_CLI, " ").concat(TSX_CLI, " src/cli.ts ").concat(command);
1229
+ }
1230
+ return "".concat(PNPM_EXEC_CLI, " ").concat(CYBERSKILL_CLI, " ").concat(command);
1231
+ }
1232
+ };
1233
+ function resolveCommands(input) {
1234
+ return _resolveCommands.apply(this, arguments);
1235
+ }
1236
+ function _resolveCommands() {
1237
+ _resolveCommands = _async_to_generator(function(input) {
1238
+ var context, _context_isRemote, isRemote, isCurrentProject, _tmp, ctx, commands;
1239
+ var _arguments = arguments;
1240
+ return _ts_generator(this, function(_state) {
1241
+ switch(_state.label){
1242
+ case 0:
1243
+ context = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {};
1244
+ isRemote = (_context_isRemote = context === null || context === void 0 ? void 0 : context.isRemote) !== null && _context_isRemote !== void 0 ? _context_isRemote : false;
1245
+ if (!isRemote) return [
1246
+ 3,
1247
+ 1
1248
+ ];
1249
+ _tmp = false;
1250
+ return [
1251
+ 3,
1252
+ 3
1253
+ ];
1254
+ case 1:
1255
+ return [
1256
+ 4,
1257
+ checkPackage(CYBERSKILL_PACKAGE_NAME)
1258
+ ];
1259
+ case 2:
1260
+ _tmp = _state.sent().isCurrentProject;
1261
+ _state.label = 3;
1262
+ case 3:
1263
+ isCurrentProject = _tmp;
1264
+ ctx = {
1265
+ isRemote: isRemote,
1266
+ isCurrentProject: isCurrentProject
1267
+ };
1268
+ commands = typeof input === "function" ? input(ctx) : input;
1269
+ return [
1270
+ 2,
1271
+ Object.fromEntries(Object.entries(commands).map(function(param) {
1272
+ var _param = _sliced_to_array(param, 2), key = _param[0], cmd = _param[1];
1273
+ return [
1274
+ key,
1275
+ commandFormatter.format(cmd, ctx)
1276
+ ];
1277
+ }))
1278
+ ];
1279
+ }
1280
+ });
1281
+ });
1282
+ return _resolveCommands.apply(this, arguments);
1283
+ }
1284
+ // src/constants/path.ts
1285
+ var __filename2 = fileURLToPath(import.meta.url);
1286
+ var __dirname2 = dirname2(__filename2);
1287
+ var CYBERSKILL_DIRECTORY = resolve2(__dirname2, "../../");
1288
+ var WORKING_DIRECTORY = process3.env.INIT_CWD || process3.cwd();
1289
+ var CYBERSKILL_PACKAGE_NAME = "@cyberskill/shared";
1290
+ var CYBERSKILL_STORAGE = ".cyberskill-storage";
1291
+ var NODE_MODULES = "node_modules";
1292
+ var BUILD_DIRECTORY = "dist";
1293
+ var PACKAGE_JSON = "package.json";
1294
+ var PACKAGE_LOCK_JSON = "package-lock.json";
1295
+ var TSCONFIG_JSON = "tsconfig.json";
1296
+ var GIT_IGNORE = ".gitignore";
1297
+ var SIMPLE_GIT_HOOK_JSON = ".simple-git-hooks.json";
1298
+ var PNPM_LOCK_YAML = "pnpm-lock.yaml";
1299
+ var GIT_HOOK = ".git/hooks";
1300
+ var GIT_COMMIT_EDITMSG = ".git/COMMIT_EDITMSG";
1301
+ var CYBERSKILL_CLI = "cyberskill";
1302
+ var ESLINT_CLI = "eslint";
1303
+ var VITEST_CLI = "vitest";
1304
+ var COMMIT_LINT_CLI = "commitlint";
1305
+ var LINT_STAGED_CLI = "lint-staged";
1306
+ var RIMRAF_CLI = "rimraf";
1307
+ var TSC_CLI = "tsc";
1308
+ var TSX_CLI = "tsx";
1309
+ var GIT_CLI = "git";
1310
+ var PNPM_CLI = "pnpm";
1311
+ var PNPM_DLX_CLI = "pnpm dlx";
1312
+ var PNPM_EXEC_CLI = "pnpm exec";
1313
+ var SIMPLE_GIT_HOOK_CLI = "simple-git-hooks";
1314
+ var ESLINT_INSPECT_CLI = "@eslint/config-inspector";
1315
+ var NODE_MODULES_INSPECT_CLI = "node_modules-inspect";
1316
+ var PATH = {
1317
+ CYBERSKILL_DIRECTORY: CYBERSKILL_DIRECTORY,
1318
+ WORKING_DIRECTORY: WORKING_DIRECTORY,
1319
+ TS_CONFIG: resolveWorkingPath(TSCONFIG_JSON),
1320
+ GIT_IGNORE: resolveWorkingPath(GIT_IGNORE),
1321
+ GIT_HOOK: resolveWorkingPath(GIT_HOOK),
1322
+ GIT_COMMIT_MSG: resolveWorkingPath(GIT_COMMIT_EDITMSG),
1323
+ SIMPLE_GIT_HOOKS: resolveWorkingPath(SIMPLE_GIT_HOOK_JSON),
1324
+ PACKAGE_JSON: resolveWorkingPath(PACKAGE_JSON),
1325
+ PACKAGE_LOCK_JSON: resolveWorkingPath(PACKAGE_LOCK_JSON),
1326
+ PNPM_LOCK_YAML: resolveWorkingPath(PNPM_LOCK_YAML),
1327
+ NODE_MODULES: resolveWorkingPath(NODE_MODULES),
1328
+ CYBERSKILL: {
1329
+ LINT_STAGED_CONFIG: resolveCyberSkillPath("./configs/lint-staged/base.js"),
1330
+ COMMITLINT_CONFIG: resolveCyberSkillPath("./configs/commitlint/base.js"),
1331
+ UNIT_TEST_CONFIG: resolveCyberSkillPath("./configs/vitest/react/unit.js"),
1332
+ E2E_TEST_CONFIG: resolveCyberSkillPath("./configs/vitest/react/e2e.js")
1333
+ }
1334
+ };
1335
+ function HOOK(param) {
1336
+ var isCurrentProject = param.isCurrentProject;
1337
+ return _object_spread({
1338
+ "postinstall": "setup",
1339
+ "pre-commit": LINT_STAGED_CLI,
1340
+ "commit-msg": COMMIT_LINT_CLI
1341
+ }, isCurrentProject && {
1342
+ "pre-push": commandFormatter.raw("".concat(GIT_CLI, " pull"))
1343
+ });
1344
+ }
1345
+ var COMMAND = {
1346
+ SIMPLE_GIT_HOOKS: commandFormatter.raw("".concat(PNPM_EXEC_CLI, " ").concat(SIMPLE_GIT_HOOK_CLI)),
1347
+ ESLINT_INSPECT: commandFormatter.raw("".concat(PNPM_EXEC_CLI, " ").concat(ESLINT_INSPECT_CLI)),
1348
+ NODE_MODULES_INSPECT: commandFormatter.raw("".concat(PNPM_EXEC_CLI, " ").concat(NODE_MODULES_INSPECT_CLI)),
1349
+ RESET: commandFormatter.raw("".concat(PNPM_EXEC_CLI, " ").concat(RIMRAF_CLI, " ").concat(NODE_MODULES, " ").concat(PNPM_LOCK_YAML)),
1350
+ ESLINT_CHECK: commandFormatter.raw("".concat(PNPM_EXEC_CLI, " ").concat(ESLINT_CLI, " ").concat(PATH.WORKING_DIRECTORY)),
1351
+ ESLINT_FIX: commandFormatter.raw("".concat(PNPM_EXEC_CLI, " ").concat(ESLINT_CLI, " ").concat(PATH.WORKING_DIRECTORY, " --fix")),
1352
+ TYPESCRIPT_CHECK: commandFormatter.raw("".concat(PNPM_EXEC_CLI, " ").concat(TSC_CLI, " -p ").concat(PATH.TS_CONFIG, " --noEmit")),
1353
+ CYBERSKILL: {
1354
+ TEST_UNIT: commandFormatter.raw("".concat(PNPM_EXEC_CLI, " ").concat(VITEST_CLI, " --config ").concat(PATH.CYBERSKILL.UNIT_TEST_CONFIG)),
1355
+ TEST_E2E: commandFormatter.raw("".concat(PNPM_EXEC_CLI, " ").concat(VITEST_CLI, " --config ").concat(PATH.CYBERSKILL.E2E_TEST_CONFIG)),
1356
+ COMMIT_LINT: commandFormatter.raw("".concat(PNPM_EXEC_CLI, " ").concat(COMMIT_LINT_CLI, " --edit ").concat(PATH.GIT_COMMIT_MSG, " --config ").concat(PATH.CYBERSKILL.COMMITLINT_CONFIG)),
1357
+ LINT_STAGED: commandFormatter.raw("".concat(PNPM_EXEC_CLI, " ").concat(LINT_STAGED_CLI, " --config ").concat(PATH.CYBERSKILL.LINT_STAGED_CONFIG))
1358
+ },
1359
+ CONFIGURE_GIT_HOOK: commandFormatter.raw("".concat(GIT_CLI, " config core.hooksPath ").concat(PATH.GIT_HOOK)),
1360
+ BUILD: commandFormatter.raw("".concat(PNPM_CLI, " run build")),
1361
+ STAGE_BUILD_DIRECTORY: commandFormatter.raw("".concat(GIT_CLI, " add ").concat(BUILD_DIRECTORY)),
1362
+ PNPM_INSTALL_STANDARD: commandFormatter.raw("".concat(PNPM_CLI, " install")),
1363
+ PNPM_INSTALL_LEGACY: commandFormatter.raw("".concat(PNPM_CLI, " install --legacy-peer-deps")),
1364
+ PNPM_INSTALL_FORCE: commandFormatter.raw("".concat(PNPM_CLI, " install --force"))
1365
+ };
1366
+ function runCommand(description, command) {
1367
+ return _runCommand.apply(this, arguments);
1368
+ }
1369
+ function _runCommand() {
1370
+ _runCommand = // src/cli.ts
1371
+ _async_to_generator(function(description, command) {
1372
+ return _ts_generator(this, function(_state) {
1373
+ switch(_state.label){
1374
+ case 0:
1375
+ commandLog.info("".concat(description, "..."));
1376
+ return [
1377
+ 4,
1378
+ executeCommand(commandFormatter.format(command))
1379
+ ];
1380
+ case 1:
1381
+ _state.sent();
1382
+ commandLog.success("".concat(description, " completed successfully."));
1383
+ return [
1384
+ 2
1385
+ ];
1386
+ }
1387
+ });
1388
+ });
1389
+ return _runCommand.apply(this, arguments);
1390
+ }
1391
+ function checkTypescript() {
1392
+ return _checkTypescript.apply(this, arguments);
1393
+ }
1394
+ function _checkTypescript() {
1395
+ _checkTypescript = _async_to_generator(function() {
1396
+ return _ts_generator(this, function(_state) {
1397
+ switch(_state.label){
1398
+ case 0:
1399
+ if (!existsSync2(PATH.TS_CONFIG)) return [
1400
+ 3,
1401
+ 2
1402
+ ];
1403
+ return [
1404
+ 4,
1405
+ runCommand("Performing TypeScript validation", COMMAND.TYPESCRIPT_CHECK)
1406
+ ];
1407
+ case 1:
1408
+ _state.sent();
1409
+ return [
1410
+ 3,
1411
+ 3
1412
+ ];
1413
+ case 2:
1414
+ commandLog.warning("No TypeScript configuration found. Skipping type check.");
1415
+ _state.label = 3;
1416
+ case 3:
1417
+ return [
1418
+ 2
1419
+ ];
1420
+ }
1421
+ });
1422
+ });
1423
+ return _checkTypescript.apply(this, arguments);
1424
+ }
1425
+ function checkEslint() {
1426
+ return _checkEslint.apply(this, arguments);
1427
+ }
1428
+ function _checkEslint() {
1429
+ _checkEslint = _async_to_generator(function() {
1430
+ var fix;
1431
+ var _arguments = arguments;
1432
+ return _ts_generator(this, function(_state) {
1433
+ switch(_state.label){
1434
+ case 0:
1435
+ fix = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : false;
1436
+ if (!fix) return [
1437
+ 3,
1438
+ 2
1439
+ ];
1440
+ return [
1441
+ 4,
1442
+ runCommand("Running ESLint with auto-fix", COMMAND.ESLINT_FIX)
1443
+ ];
1444
+ case 1:
1445
+ _state.sent();
1446
+ return [
1447
+ 3,
1448
+ 4
1449
+ ];
1450
+ case 2:
1451
+ return [
1452
+ 4,
1453
+ runCommand("Running ESLint check", COMMAND.ESLINT_CHECK)
1454
+ ];
1455
+ case 3:
1456
+ _state.sent();
1457
+ _state.label = 4;
1458
+ case 4:
1459
+ return [
1460
+ 2
1461
+ ];
1462
+ }
1463
+ });
1464
+ });
1465
+ return _checkEslint.apply(this, arguments);
1466
+ }
1467
+ function showCheckResult() {
1468
+ return _showCheckResult.apply(this, arguments);
1469
+ }
1470
+ function _showCheckResult() {
1471
+ _showCheckResult = _async_to_generator(function() {
1472
+ var allResults, errors, warnings;
1473
+ return _ts_generator(this, function(_state) {
1474
+ switch(_state.label){
1475
+ case 0:
1476
+ return [
1477
+ 4,
1478
+ getStoredErrorLists()
1479
+ ];
1480
+ case 1:
1481
+ allResults = _state.sent();
1482
+ errors = allResults.filter(function(e) {
1483
+ return e.type === "error" /* Error */ ;
1484
+ });
1485
+ warnings = allResults.filter(function(e) {
1486
+ return e.type === "warning" /* Warning */ ;
1487
+ });
1488
+ if (!errors.length && !warnings.length) {
1489
+ commandLog.printBoxedLog("\u2714 NO ISSUES FOUND", "", {
1490
+ color: "green"
1491
+ });
1492
+ } else {
1493
+ commandLog.printBoxedLog("\u26A0 Warnings", warnings, {
1494
+ color: "yellow"
1495
+ });
1496
+ commandLog.printBoxedLog("\u2716 Errors", errors, {
1497
+ color: "red"
1498
+ });
1499
+ }
1500
+ return [
1501
+ 2
1502
+ ];
1503
+ }
1504
+ });
1505
+ });
1506
+ return _showCheckResult.apply(this, arguments);
1507
+ }
1508
+ function lintStaged() {
1509
+ return _lintStaged.apply(this, arguments);
1510
+ }
1511
+ function _lintStaged() {
1512
+ _lintStaged = _async_to_generator(function() {
1513
+ var isCurrentProject, error;
1514
+ return _ts_generator(this, function(_state) {
1515
+ switch(_state.label){
1516
+ case 0:
1517
+ return [
1518
+ 4,
1519
+ checkPackage(CYBERSKILL_PACKAGE_NAME)
1520
+ ];
1521
+ case 1:
1522
+ isCurrentProject = _state.sent().isCurrentProject;
1523
+ if (!isCurrentProject) return [
1524
+ 3,
1525
+ 6
1526
+ ];
1527
+ _state.label = 2;
1528
+ case 2:
1529
+ _state.trys.push([
1530
+ 2,
1531
+ 5,
1532
+ ,
1533
+ 6
1534
+ ]);
1535
+ return [
1536
+ 4,
1537
+ runCommand("Building package: ".concat(CYBERSKILL_PACKAGE_NAME), COMMAND.BUILD)
1538
+ ];
1539
+ case 3:
1540
+ _state.sent();
1541
+ return [
1542
+ 4,
1543
+ runCommand("Staging build artifacts", COMMAND.STAGE_BUILD_DIRECTORY)
1544
+ ];
1545
+ case 4:
1546
+ _state.sent();
1547
+ return [
1548
+ 3,
1549
+ 6
1550
+ ];
1551
+ case 5:
1552
+ error = _state.sent();
1553
+ commandLog.error("Error building and staging ".concat(CYBERSKILL_PACKAGE_NAME, ": ").concat(error.message));
1554
+ throw error;
1555
+ case 6:
1556
+ return [
1557
+ 4,
1558
+ runCommand("Executing lint-staged", COMMAND.CYBERSKILL.LINT_STAGED)
1559
+ ];
1560
+ case 7:
1561
+ _state.sent();
1562
+ showCheckResult();
1563
+ return [
1564
+ 2
1565
+ ];
1566
+ }
1567
+ });
1568
+ });
1569
+ return _lintStaged.apply(this, arguments);
1570
+ }
1571
+ function inspectLint() {
1572
+ return _inspectLint.apply(this, arguments);
1573
+ }
1574
+ function _inspectLint() {
1575
+ _inspectLint = _async_to_generator(function() {
1576
+ return _ts_generator(this, function(_state) {
1577
+ switch(_state.label){
1578
+ case 0:
1579
+ return [
1580
+ 4,
1581
+ runCommand("Inspecting ESLint configuration", COMMAND.ESLINT_INSPECT)
1582
+ ];
1583
+ case 1:
1584
+ _state.sent();
1585
+ return [
1586
+ 2
1587
+ ];
1588
+ }
1589
+ });
1590
+ });
1591
+ return _inspectLint.apply(this, arguments);
1592
+ }
1593
+ function lintCheck() {
1594
+ return _lintCheck.apply(this, arguments);
1595
+ }
1596
+ function _lintCheck() {
1597
+ _lintCheck = _async_to_generator(function() {
1598
+ return _ts_generator(this, function(_state) {
1599
+ switch(_state.label){
1600
+ case 0:
1601
+ return [
1602
+ 4,
1603
+ clearAllErrorLists()
1604
+ ];
1605
+ case 1:
1606
+ _state.sent();
1607
+ return [
1608
+ 4,
1609
+ Promise.all([
1610
+ checkTypescript(),
1611
+ checkEslint()
1612
+ ])
1613
+ ];
1614
+ case 2:
1615
+ _state.sent();
1616
+ showCheckResult();
1617
+ return [
1618
+ 2
1619
+ ];
1620
+ }
1621
+ });
1622
+ });
1623
+ return _lintCheck.apply(this, arguments);
1624
+ }
1625
+ function lintFix() {
1626
+ return _lintFix.apply(this, arguments);
1627
+ }
1628
+ function _lintFix() {
1629
+ _lintFix = _async_to_generator(function() {
1630
+ return _ts_generator(this, function(_state) {
1631
+ switch(_state.label){
1632
+ case 0:
1633
+ return [
1634
+ 4,
1635
+ clearAllErrorLists()
1636
+ ];
1637
+ case 1:
1638
+ _state.sent();
1639
+ return [
1640
+ 4,
1641
+ Promise.all([
1642
+ checkTypescript(),
1643
+ checkEslint(true)
1644
+ ])
1645
+ ];
1646
+ case 2:
1647
+ _state.sent();
1648
+ showCheckResult();
1649
+ return [
1650
+ 2
1651
+ ];
1652
+ }
1653
+ });
1654
+ });
1655
+ return _lintFix.apply(this, arguments);
1656
+ }
1657
+ function commitLint() {
1658
+ return _commitLint.apply(this, arguments);
1659
+ }
1660
+ function _commitLint() {
1661
+ _commitLint = _async_to_generator(function() {
1662
+ return _ts_generator(this, function(_state) {
1663
+ switch(_state.label){
1664
+ case 0:
1665
+ return [
1666
+ 4,
1667
+ runCommand("Validating commit message", COMMAND.CYBERSKILL.COMMIT_LINT)
1668
+ ];
1669
+ case 1:
1670
+ _state.sent();
1671
+ showCheckResult();
1672
+ return [
1673
+ 2
1674
+ ];
1675
+ }
1676
+ });
1677
+ });
1678
+ return _commitLint.apply(this, arguments);
1679
+ }
1680
+ function setupGitHook() {
1681
+ return _setupGitHook.apply(this, arguments);
1682
+ }
1683
+ function _setupGitHook() {
1684
+ _setupGitHook = _async_to_generator(function() {
1685
+ var hooks, gitIgnoreEntry, gitignore;
1686
+ return _ts_generator(this, function(_state) {
1687
+ switch(_state.label){
1688
+ case 0:
1689
+ return [
1690
+ 4,
1691
+ runCommand("Configuring Git hooks", COMMAND.CONFIGURE_GIT_HOOK)
1692
+ ];
1693
+ case 1:
1694
+ _state.sent();
1695
+ return [
1696
+ 4,
1697
+ resolveCommands(HOOK)
1698
+ ];
1699
+ case 2:
1700
+ hooks = _state.sent();
1701
+ writeFileSync2(PATH.SIMPLE_GIT_HOOKS, hooks, {
1702
+ isJson: true
1703
+ });
1704
+ gitIgnoreEntry = "\n".concat(SIMPLE_GIT_HOOK_JSON, "\n");
1705
+ if (existsSync2(PATH.GIT_IGNORE)) {
1706
+ gitignore = readFileSync2(PATH.GIT_IGNORE).split("\n");
1707
+ if (!gitignore.includes(SIMPLE_GIT_HOOK_JSON)) {
1708
+ appendFileSync2(PATH.GIT_IGNORE, gitIgnoreEntry);
1709
+ }
1710
+ } else {
1711
+ writeFileSync2(PATH.GIT_IGNORE, gitIgnoreEntry);
1712
+ }
1713
+ return [
1714
+ 4,
1715
+ runCommand("Installing simple-git-hooks", COMMAND.SIMPLE_GIT_HOOKS)
1716
+ ];
1717
+ case 3:
1718
+ _state.sent();
1719
+ return [
1720
+ 2
1721
+ ];
1722
+ }
1723
+ });
1724
+ });
1725
+ return _setupGitHook.apply(this, arguments);
1726
+ }
1727
+ function installDependencies() {
1728
+ return _installDependencies.apply(this, arguments);
1729
+ }
1730
+ function _installDependencies() {
1731
+ _installDependencies = _async_to_generator(function() {
1732
+ var strategies, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, command, message, error, err;
1733
+ return _ts_generator(this, function(_state) {
1734
+ switch(_state.label){
1735
+ case 0:
1736
+ strategies = [
1737
+ {
1738
+ command: COMMAND.PNPM_INSTALL_STANDARD,
1739
+ message: "Installing dependencies (standard)"
1740
+ },
1741
+ {
1742
+ command: COMMAND.PNPM_INSTALL_LEGACY,
1743
+ message: "Retrying with legacy peer dependencies"
1744
+ },
1745
+ {
1746
+ command: COMMAND.PNPM_INSTALL_FORCE,
1747
+ message: "Retrying with force install"
1748
+ }
1749
+ ];
1750
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1751
+ _state.label = 1;
1752
+ case 1:
1753
+ _state.trys.push([
1754
+ 1,
1755
+ 8,
1756
+ 9,
1757
+ 10
1758
+ ]);
1759
+ _iterator = strategies[Symbol.iterator]();
1760
+ _state.label = 2;
1761
+ case 2:
1762
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
1763
+ 3,
1764
+ 7
1765
+ ];
1766
+ _step_value = _step.value, command = _step_value.command, message = _step_value.message;
1767
+ _state.label = 3;
1768
+ case 3:
1769
+ _state.trys.push([
1770
+ 3,
1771
+ 5,
1772
+ ,
1773
+ 6
1774
+ ]);
1775
+ return [
1776
+ 4,
1777
+ runCommand("".concat(message, " using: ").concat(command.cmd), command)
1778
+ ];
1779
+ case 4:
1780
+ _state.sent();
1781
+ return [
1782
+ 2
1783
+ ];
1784
+ case 5:
1785
+ error = _state.sent();
1786
+ commandLog.warning("Installation attempt failed: ".concat(command.cmd));
1787
+ commandLog.error("Details: ".concat(error.message));
1788
+ return [
1789
+ 3,
1790
+ 6
1791
+ ];
1792
+ case 6:
1793
+ _iteratorNormalCompletion = true;
1794
+ return [
1795
+ 3,
1796
+ 2
1797
+ ];
1798
+ case 7:
1799
+ return [
1800
+ 3,
1801
+ 10
1802
+ ];
1803
+ case 8:
1804
+ err = _state.sent();
1805
+ _didIteratorError = true;
1806
+ _iteratorError = err;
1807
+ return [
1808
+ 3,
1809
+ 10
1810
+ ];
1811
+ case 9:
1812
+ try {
1813
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1814
+ _iterator.return();
1815
+ }
1816
+ } finally{
1817
+ if (_didIteratorError) {
1818
+ throw _iteratorError;
1819
+ }
1820
+ }
1821
+ return [
1822
+ 7
1823
+ ];
1824
+ case 10:
1825
+ throw new Error("All dependency installation strategies failed.");
1826
+ }
1827
+ });
1828
+ });
1829
+ return _installDependencies.apply(this, arguments);
1830
+ }
1831
+ function updatePackage(packageName) {
1832
+ return _updatePackage.apply(this, arguments);
1833
+ }
1834
+ function _updatePackage() {
1835
+ _updatePackage = _async_to_generator(function(packageName) {
1836
+ var _ref, installedPath, latestVersion, file, error;
1837
+ return _ts_generator(this, function(_state) {
1838
+ switch(_state.label){
1839
+ case 0:
1840
+ _state.trys.push([
1841
+ 0,
1842
+ 4,
1843
+ ,
1844
+ 5
1845
+ ]);
1846
+ return [
1847
+ 4,
1848
+ checkPackage(packageName)
1849
+ ];
1850
+ case 1:
1851
+ _ref = _state.sent(), installedPath = _ref.installedPath, latestVersion = _ref.latestVersion, file = _ref.file;
1852
+ file.dependencies = _object_spread_props(_object_spread({}, file.dependencies), _define_property({}, file.name, latestVersion));
1853
+ writeFileSync2(installedPath, file, {
1854
+ isJson: true
1855
+ });
1856
+ return [
1857
+ 4,
1858
+ installDependencies()
1859
+ ];
1860
+ case 2:
1861
+ _state.sent();
1862
+ return [
1863
+ 4,
1864
+ lintFix()
1865
+ ];
1866
+ case 3:
1867
+ _state.sent();
1868
+ return [
1869
+ 3,
1870
+ 5
1871
+ ];
1872
+ case 4:
1873
+ error = _state.sent();
1874
+ commandLog.error('Failed to update "'.concat(packageName, '": ').concat(error.message));
1875
+ throw error;
1876
+ case 5:
1877
+ return [
1878
+ 2
1879
+ ];
1880
+ }
1881
+ });
1882
+ });
1883
+ return _updatePackage.apply(this, arguments);
1884
+ }
1885
+ function setup() {
1886
+ return _setup.apply(this, arguments);
1887
+ }
1888
+ function _setup() {
1889
+ _setup = _async_to_generator(function() {
1890
+ var _ref, isInstalled, installedVersion, latestVersion, isCurrentProject, isUpToDate, error;
1891
+ return _ts_generator(this, function(_state) {
1892
+ switch(_state.label){
1893
+ case 0:
1894
+ if (!existsSync2(PATH.PACKAGE_JSON)) {
1895
+ commandLog.error("package.json not found. Aborting setup.");
1896
+ return [
1897
+ 2
1898
+ ];
1899
+ }
1900
+ _state.label = 1;
1901
+ case 1:
1902
+ _state.trys.push([
1903
+ 1,
1904
+ 7,
1905
+ ,
1906
+ 8
1907
+ ]);
1908
+ return [
1909
+ 4,
1910
+ checkPackage(CYBERSKILL_PACKAGE_NAME)
1911
+ ];
1912
+ case 2:
1913
+ _ref = _state.sent(), isInstalled = _ref.isInstalled, installedVersion = _ref.installedVersion, latestVersion = _ref.latestVersion, isCurrentProject = _ref.isCurrentProject;
1914
+ isUpToDate = isCurrentProject || isInstalled && installedVersion === latestVersion;
1915
+ if (!isUpToDate) return [
1916
+ 3,
1917
+ 3
1918
+ ];
1919
+ commandLog.success("Cyberskill package is already up to date.");
1920
+ return [
1921
+ 3,
1922
+ 5
1923
+ ];
1924
+ case 3:
1925
+ return [
1926
+ 4,
1927
+ updatePackage(CYBERSKILL_PACKAGE_NAME)
1928
+ ];
1929
+ case 4:
1930
+ _state.sent();
1931
+ _state.label = 5;
1932
+ case 5:
1933
+ return [
1934
+ 4,
1935
+ setupGitHook()
1936
+ ];
1937
+ case 6:
1938
+ _state.sent();
1939
+ return [
1940
+ 3,
1941
+ 8
1942
+ ];
1943
+ case 7:
1944
+ error = _state.sent();
1945
+ commandLog.error("Project setup failed: ".concat(error.message));
1946
+ throw error;
1947
+ case 8:
1948
+ return [
1949
+ 2
1950
+ ];
1951
+ }
1952
+ });
1953
+ });
1954
+ return _setup.apply(this, arguments);
1955
+ }
1956
+ function reset() {
1957
+ return _reset.apply(this, arguments);
1958
+ }
1959
+ function _reset() {
1960
+ _reset = _async_to_generator(function() {
1961
+ return _ts_generator(this, function(_state) {
1962
+ switch(_state.label){
1963
+ case 0:
1964
+ return [
1965
+ 4,
1966
+ runCommand("Resetting project files", COMMAND.RESET)
1967
+ ];
1968
+ case 1:
1969
+ _state.sent();
1970
+ return [
1971
+ 4,
1972
+ installDependencies()
1973
+ ];
1974
+ case 2:
1975
+ _state.sent();
1976
+ return [
1977
+ 4,
1978
+ setupGitHook()
1979
+ ];
1980
+ case 3:
1981
+ _state.sent();
1982
+ return [
1983
+ 2
1984
+ ];
1985
+ }
1986
+ });
1987
+ });
1988
+ return _reset.apply(this, arguments);
1989
+ }
1990
+ function inspect() {
1991
+ return _inspect.apply(this, arguments);
1992
+ }
1993
+ function _inspect() {
1994
+ _inspect = _async_to_generator(function() {
1995
+ return _ts_generator(this, function(_state) {
1996
+ switch(_state.label){
1997
+ case 0:
1998
+ return [
1999
+ 4,
2000
+ runCommand("Inspecting project dependencies", COMMAND.NODE_MODULES_INSPECT)
2001
+ ];
2002
+ case 1:
2003
+ _state.sent();
2004
+ return [
2005
+ 2
2006
+ ];
2007
+ }
2008
+ });
2009
+ });
2010
+ return _inspect.apply(this, arguments);
2011
+ }
2012
+ function testUnit() {
2013
+ return _testUnit.apply(this, arguments);
2014
+ }
2015
+ function _testUnit() {
2016
+ _testUnit = _async_to_generator(function() {
2017
+ return _ts_generator(this, function(_state) {
2018
+ switch(_state.label){
2019
+ case 0:
2020
+ return [
2021
+ 4,
2022
+ runCommand("Running unit tests", COMMAND.CYBERSKILL.TEST_UNIT)
2023
+ ];
2024
+ case 1:
2025
+ _state.sent();
2026
+ return [
2027
+ 2
2028
+ ];
2029
+ }
2030
+ });
2031
+ });
2032
+ return _testUnit.apply(this, arguments);
2033
+ }
2034
+ function testE2E() {
2035
+ return _testE2E.apply(this, arguments);
2036
+ }
2037
+ function _testE2E() {
2038
+ _testE2E = _async_to_generator(function() {
2039
+ return _ts_generator(this, function(_state) {
2040
+ switch(_state.label){
2041
+ case 0:
2042
+ return [
2043
+ 4,
2044
+ runCommand("Running end-to-end tests", COMMAND.CYBERSKILL.TEST_E2E)
2045
+ ];
2046
+ case 1:
2047
+ _state.sent();
2048
+ return [
2049
+ 2
2050
+ ];
2051
+ }
2052
+ });
2053
+ });
2054
+ return _testE2E.apply(this, arguments);
2055
+ }
2056
+ yargs(hideBin(process4.argv)).scriptName(CYBERSKILL_CLI).usage("$0 <command> [options]").command("lint", "Check code for linting issues", lintCheck).command("lint:fix", "Fix linting issues automatically", lintFix).command("lint:inspect", "View active ESLint configuration", inspectLint).command("lint-staged", "Run lint checks on staged files", lintStaged).command("commitlint", "Validate commit message format", commitLint).command("setup", "Initialize project setup and dependencies", setup).command("reset", "Reset the project and reinstall dependencies", reset).command("inspect", "Analyze installed project dependencies", inspect).command("test:unit", "Run unit test suite", testUnit).command("test:e2e", "Run end-to-end test suite", testE2E).demandCommand(1, "Please specify a valid command.").strict().help().alias("h", "help").alias("v", "version").epilog('\u{1F4A1} Tip: Use "--help" with any command to see options\n').parse();
2057
+ export { installDependencies, updatePackage };