@initx-plugin/utils 0.1.4 → 0.2.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.
package/dist/gpg.mjs CHANGED
@@ -1 +1 @@
1
- export{g as gpgList}from"./shared/utils.Crl5PLcv.mjs";import"ora";import"tinyexec";import"which";
1
+ export{g as gpgList}from"./shared/utils.Dmh89-WN.mjs";import"ora";import"tinyexec";import"which";
package/dist/index.d.mts CHANGED
@@ -21,13 +21,23 @@ declare const inquirer: {
21
21
  select: typeof select;
22
22
  };
23
23
 
24
- declare const log: {
25
- success: (msg: string) => void;
26
- info: (msg: string) => void;
27
- warn: (msg: string) => void;
28
- error: (msg: string) => void;
29
- };
24
+ type LogLevel = 'debug' | 'info' | 'success' | 'warn' | 'error';
25
+ declare class Logger {
26
+ private level;
27
+ setLevel(level: LogLevel): void;
28
+ private shouldLog;
29
+ debug(msg: string): void;
30
+ info(msg: string): void;
31
+ success(msg: string): void;
32
+ warn(msg: string): void;
33
+ error(msg: string): void;
34
+ }
35
+ declare const logger: Logger;
36
+ /**
37
+ * @deprecated Use `logger` instead
38
+ */
39
+ declare const log: Logger;
30
40
 
31
41
  declare const where: typeof which.sync;
32
42
 
33
- export { c, inquirer, loadingFunction, log, where };
43
+ export { c, inquirer, loadingFunction, log, logger, where };
package/dist/index.d.ts CHANGED
@@ -21,13 +21,23 @@ declare const inquirer: {
21
21
  select: typeof select;
22
22
  };
23
23
 
24
- declare const log: {
25
- success: (msg: string) => void;
26
- info: (msg: string) => void;
27
- warn: (msg: string) => void;
28
- error: (msg: string) => void;
29
- };
24
+ type LogLevel = 'debug' | 'info' | 'success' | 'warn' | 'error';
25
+ declare class Logger {
26
+ private level;
27
+ setLevel(level: LogLevel): void;
28
+ private shouldLog;
29
+ debug(msg: string): void;
30
+ info(msg: string): void;
31
+ success(msg: string): void;
32
+ warn(msg: string): void;
33
+ error(msg: string): void;
34
+ }
35
+ declare const logger: Logger;
36
+ /**
37
+ * @deprecated Use `logger` instead
38
+ */
39
+ declare const log: Logger;
30
40
 
31
41
  declare const where: typeof which.sync;
32
42
 
33
- export { c, inquirer, loadingFunction, log, where };
43
+ export { c, inquirer, loadingFunction, log, logger, where };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export{c,g as gpgList,l as loadingFunction,w as where}from"./shared/utils.Crl5PLcv.mjs";import s from"inquirer";import e from"picocolors";import"ora";import"tinyexec";import"which";async function l(o){const{result:t}=await s.prompt([{type:"confirm",name:"result",message:o}]);return t}async function i(o,t){const{result:r}=await s.prompt([{type:"list",name:"result",message:o,choices:t.map((n,c)=>typeof n=="string"?{name:n,value:c}:n)}]);return r}const a={confirm:l,select:i},m={success:o=>console.log(`${e.bgGreen(e.black(" SUCCESS "))} ${o}`),info:o=>console.log(`${e.bgBlue(e.white(" INFO "))} ${o}`),warn:o=>console.log(`${e.bgYellow(e.black(" WARN "))} ${o}`),error:o=>console.log(`${e.bgRed(e.white(" ERROR "))} ${o}`)};export{a as inquirer,m as log};
1
+ export{c,g as gpgList,l as loadingFunction,w as where}from"./shared/utils.Dmh89-WN.mjs";import n from"inquirer";import"ora";import"tinyexec";import"which";async function u(o){const{result:e}=await n.prompt([{type:"confirm",name:"result",message:o}]);return e}async function m(o,e){const{result:l}=await n.prompt([{type:"list",name:"result",message:o,choices:e.map((t,i)=>typeof t=="string"?{name:t,value:i}:t)}]);return l}const a={confirm:u,select:m},r={reset:"\x1B[0m",black:"\x1B[30m",white:"\x1B[37m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",bgBrightBlack:"\x1B[100m",bgGreen:"\x1B[42m",bgBlue:"\x1B[44m",bgYellow:"\x1B[43m",bgRed:"\x1B[41m"},g={debug:0,info:1,success:2,warn:3,error:4};function s(o,e,l){return`${r[l]}${r[e]}${o}${r.reset}`}class h{level="info";setLevel(e){this.level=e}shouldLog(e){return g[e]>=g[this.level]}debug(e){this.shouldLog("debug")&&console.log(`${s(" DEBUG ","black","bgBrightBlack")} ${e}`)}info(e){this.shouldLog("info")&&console.log(`${s(" INFO ","white","bgBlue")} ${e}`)}success(e){this.shouldLog("success")&&console.log(`${s(" SUCCESS ","black","bgGreen")} ${e}`)}warn(e){this.shouldLog("warn")&&console.log(`${s(" WARN ","black","bgYellow")} ${e}`)}error(e){this.shouldLog("error")&&console.log(`${s(" ERROR ","white","bgRed")} ${e}`)}}const c=new h,B=c;export{a as inquirer,B as log,c as logger};
@@ -0,0 +1 @@
1
+ import m from"ora";import{x as l}from"tinyexec";import w from"which";const a=w.sync,c=new Map;async function i(n,e,r={}){const t={success:!1,content:"Unknown error"};try{if(!p(n))return t.content=`Can not find command: ${n}`,t;const s=await l(n,e,r);t.success=s.exitCode===0,t.content=(t.success?s.stdout:s.stderr).trim()}catch(s){t.content=s.message}return t}async function g(n,e){const r=m(n).start();return e().finally(()=>{r.stop()})}function p(n){if(c.has(n))return c.get(n);let e;try{a(n),e=!0}catch{e=!1}return c.set(n,e),e}const h=/\r?\n|\r/,y=/^\s+(\w{40})$/,d=/\s(\w+)\s<([\w-]+@[\w-]+(?:\.[\w-]+)+)>/;async function x(){const n=await i("gpg",["-k"]),e=[],r=n.content.split(h).filter(s=>s.trim()!=="");if(!r||r.length<4)return[];const t={key:"",name:"",email:""};return r.forEach(s=>{const[,o]=y.exec(s)||[];if(o){t.key=o;return}if(s.startsWith("uid")){const[,u,f]=d.exec(s)||[];t.name=u,t.email=f;return}s.startsWith("sub")&&e.push({...t})}),e}export{i as c,x as g,g as l,a as w};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@initx-plugin/utils",
3
3
  "type": "module",
4
- "version": "0.1.4",
4
+ "version": "0.2.0",
5
5
  "description": "A more convenient scripting engine",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/initx-collective/initx#readme",
@@ -32,11 +32,10 @@
32
32
  "dist"
33
33
  ],
34
34
  "dependencies": {
35
- "inquirer": "^13.1.0",
36
- "ora": "^9.0.0",
37
- "picocolors": "^1.1.1",
38
- "tinyexec": "^1.0.2",
39
- "which": "^6.0.0"
35
+ "inquirer": "^13.3.2",
36
+ "ora": "^9.3.0",
37
+ "tinyexec": "^1.0.4",
38
+ "which": "^6.0.1"
40
39
  },
41
40
  "devDependencies": {
42
41
  "@types/which": "^3.0.4"
@@ -1 +0,0 @@
1
- import l from"ora";import{x as w}from"tinyexec";import y from"which";const i=y.sync,o=new Map;async function u(n,e,r={}){const t={success:!1,content:"Unknown error"};try{if(!g(n))return t.content=`Can not find command: ${n}`,t;const s=await w(n,e,r);t.success=s.exitCode===0,t.content=(t.success?s.stdout:s.stderr).trim()}catch(s){t.content=s.message}return t}async function p(n,e){const r=l(n).start();return e().finally(()=>{r.stop()})}function g(n){if(o.has(n))return o.get(n);let e;try{i(n),e=!0}catch{e=!1}return o.set(n,e),e}async function h(){const n=await u("gpg",["-k"]),e=[],r=n.content.split(/\r?\n|\r/).filter(c=>c.trim()!=="");if(!r||r.length<4)return[];const t={key:"",name:"",email:""},s={key:/^\s+(\w{40})$/,user:/\s(\w+)\s<([\w-]+@[\w-]+(?:\.[\w-]+)+)>/};return r.forEach(c=>{const[,a]=s.key.exec(c)||[];if(a){t.key=a;return}if(c.startsWith("uid")){const[,f,m]=s.user.exec(c)||[];t.name=f,t.email=m;return}c.startsWith("sub")&&e.push({...t})}),e}export{u as c,h as g,p as l,i as w};