@initx-plugin/utils 0.1.4 → 0.3.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
@@ -1,6 +1,52 @@
1
1
  export { gpgList } from './gpg.mjs';
2
2
  import which from 'which';
3
3
 
4
+ declare class ColorBuilder {
5
+ private text;
6
+ private fgColor;
7
+ private bgColor;
8
+ private styles;
9
+ constructor(text: string);
10
+ black(): this;
11
+ red(): this;
12
+ green(): this;
13
+ yellow(): this;
14
+ blue(): this;
15
+ white(): this;
16
+ gray(): this;
17
+ bgBlack(): this;
18
+ bgRed(): this;
19
+ bgGreen(): this;
20
+ bgYellow(): this;
21
+ bgBlue(): this;
22
+ bgGray(): this;
23
+ dim(): this;
24
+ bold(): this;
25
+ reset(): this;
26
+ toString(): string;
27
+ valueOf(): string;
28
+ private setColor;
29
+ private setBgColor;
30
+ private addStyle;
31
+ }
32
+ /**
33
+ * Create a color builder for the given text
34
+ * @example
35
+ * useColors('Hello').red().bgBlue()
36
+ * useColors('World').green().bold()
37
+ */
38
+ declare function useColors(text: string): ColorBuilder;
39
+ declare const red: (text: string) => ColorBuilder;
40
+ declare const green: (text: string) => ColorBuilder;
41
+ declare const yellow: (text: string) => ColorBuilder;
42
+ declare const blue: (text: string) => ColorBuilder;
43
+ declare const white: (text: string) => ColorBuilder;
44
+ declare const black: (text: string) => ColorBuilder;
45
+ declare const gray: (text: string) => ColorBuilder;
46
+ declare const dim: (text: string) => ColorBuilder;
47
+ declare const bold: (text: string) => ColorBuilder;
48
+ declare const reset: (text: string) => ColorBuilder;
49
+
4
50
  interface Result {
5
51
  success: boolean;
6
52
  content: string;
@@ -21,13 +67,23 @@ declare const inquirer: {
21
67
  select: typeof select;
22
68
  };
23
69
 
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
- };
70
+ type LogLevel = 'debug' | 'info' | 'success' | 'warn' | 'error';
71
+ declare class Logger {
72
+ private level;
73
+ setLevel(level: LogLevel): void;
74
+ private shouldLog;
75
+ debug(msg: string): void;
76
+ info(msg: string): void;
77
+ success(msg: string): void;
78
+ warn(msg: string): void;
79
+ error(msg: string): void;
80
+ }
81
+ declare const logger: Logger;
82
+ /**
83
+ * @deprecated Use `logger` instead
84
+ */
85
+ declare const log: Logger;
30
86
 
31
87
  declare const where: typeof which.sync;
32
88
 
33
- export { c, inquirer, loadingFunction, log, where };
89
+ export { ColorBuilder, black, blue, bold, c, dim, gray, green, inquirer, loadingFunction, log, logger, red, reset, useColors, where, white, yellow };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,52 @@
1
1
  export { gpgList } from './gpg.js';
2
2
  import which from 'which';
3
3
 
4
+ declare class ColorBuilder {
5
+ private text;
6
+ private fgColor;
7
+ private bgColor;
8
+ private styles;
9
+ constructor(text: string);
10
+ black(): this;
11
+ red(): this;
12
+ green(): this;
13
+ yellow(): this;
14
+ blue(): this;
15
+ white(): this;
16
+ gray(): this;
17
+ bgBlack(): this;
18
+ bgRed(): this;
19
+ bgGreen(): this;
20
+ bgYellow(): this;
21
+ bgBlue(): this;
22
+ bgGray(): this;
23
+ dim(): this;
24
+ bold(): this;
25
+ reset(): this;
26
+ toString(): string;
27
+ valueOf(): string;
28
+ private setColor;
29
+ private setBgColor;
30
+ private addStyle;
31
+ }
32
+ /**
33
+ * Create a color builder for the given text
34
+ * @example
35
+ * useColors('Hello').red().bgBlue()
36
+ * useColors('World').green().bold()
37
+ */
38
+ declare function useColors(text: string): ColorBuilder;
39
+ declare const red: (text: string) => ColorBuilder;
40
+ declare const green: (text: string) => ColorBuilder;
41
+ declare const yellow: (text: string) => ColorBuilder;
42
+ declare const blue: (text: string) => ColorBuilder;
43
+ declare const white: (text: string) => ColorBuilder;
44
+ declare const black: (text: string) => ColorBuilder;
45
+ declare const gray: (text: string) => ColorBuilder;
46
+ declare const dim: (text: string) => ColorBuilder;
47
+ declare const bold: (text: string) => ColorBuilder;
48
+ declare const reset: (text: string) => ColorBuilder;
49
+
4
50
  interface Result {
5
51
  success: boolean;
6
52
  content: string;
@@ -21,13 +67,23 @@ declare const inquirer: {
21
67
  select: typeof select;
22
68
  };
23
69
 
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
- };
70
+ type LogLevel = 'debug' | 'info' | 'success' | 'warn' | 'error';
71
+ declare class Logger {
72
+ private level;
73
+ setLevel(level: LogLevel): void;
74
+ private shouldLog;
75
+ debug(msg: string): void;
76
+ info(msg: string): void;
77
+ success(msg: string): void;
78
+ warn(msg: string): void;
79
+ error(msg: string): void;
80
+ }
81
+ declare const logger: Logger;
82
+ /**
83
+ * @deprecated Use `logger` instead
84
+ */
85
+ declare const log: Logger;
30
86
 
31
87
  declare const where: typeof which.sync;
32
88
 
33
- export { c, inquirer, loadingFunction, log, where };
89
+ export { ColorBuilder, black, blue, bold, c, dim, gray, green, inquirer, loadingFunction, log, logger, red, reset, useColors, where, white, yellow };
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 g from"inquirer";import"ora";import"tinyexec";import"which";const s={reset:"\x1B[0m",black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",white:"\x1B[37m",gray:"\x1B[90m",bgBlack:"\x1B[40m",bgRed:"\x1B[41m",bgGreen:"\x1B[42m",bgYellow:"\x1B[43m",bgBlue:"\x1B[44m",bgGray:"\x1B[100m",dim:"\x1B[2m",bold:"\x1B[1m"};class u{constructor(e){this.text=e}fgColor="";bgColor="";styles=[];black(){return this.setColor("black")}red(){return this.setColor("red")}green(){return this.setColor("green")}yellow(){return this.setColor("yellow")}blue(){return this.setColor("blue")}white(){return this.setColor("white")}gray(){return this.setColor("gray")}bgBlack(){return this.setBgColor("bgBlack")}bgRed(){return this.setBgColor("bgRed")}bgGreen(){return this.setBgColor("bgGreen")}bgYellow(){return this.setBgColor("bgYellow")}bgBlue(){return this.setBgColor("bgBlue")}bgGray(){return this.setBgColor("bgGray")}dim(){return this.addStyle("dim")}bold(){return this.addStyle("bold")}reset(){return this.fgColor="",this.bgColor="",this.styles=[],this}toString(){const e=[...this.styles,this.fgColor,this.bgColor].filter(Boolean).join("");return e?`${e}${this.text}${s.reset}`:this.text}valueOf(){return this.toString()}setColor(e){return this.fgColor=s[e],this}setBgColor(e){return this.bgColor=s[e],this}addStyle(e){return this.styles.push(s[e]),this}}function r(t){return new u(t)}const a=t=>r(t).red(),B=t=>r(t).green(),m=t=>r(t).yellow(),d=t=>r(t).blue(),x=t=>r(t).white(),w=t=>r(t).black(),C=t=>r(t).gray(),y=t=>r(t).dim(),f=t=>r(t).bold(),$=t=>r(t).reset();async function p(t){const{result:e}=await g.prompt([{type:"confirm",name:"result",message:t}]);return e}async function k(t,e){const{result:l}=await g.prompt([{type:"list",name:"result",message:t,choices:e.map((n,c)=>typeof n=="string"?{name:n,value:c}:n)}]);return l}const G={confirm:p,select:k},i={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"},h={debug:0,info:1,success:2,warn:3,error:4};function o(t,e,l){return`${i[l]}${i[e]}${t}${i.reset}`}class R{level="info";setLevel(e){this.level=e}shouldLog(e){return h[e]>=h[this.level]}debug(e){this.shouldLog("debug")&&console.log(`${o(" DEBUG ","black","bgBrightBlack")} ${e}`)}info(e){this.shouldLog("info")&&console.log(`${o(" INFO ","white","bgBlue")} ${e}`)}success(e){this.shouldLog("success")&&console.log(`${o(" SUCCESS ","black","bgGreen")} ${e}`)}warn(e){this.shouldLog("warn")&&console.log(`${o(" WARN ","black","bgYellow")} ${e}`)}error(e){this.shouldLog("error")&&console.log(`${o(" ERROR ","white","bgRed")} ${e}`)}}const b=new R,L=b;export{u as ColorBuilder,w as black,d as blue,f as bold,y as dim,C as gray,B as green,G as inquirer,L as log,b as logger,a as red,$ as reset,r as useColors,x as white,m as yellow};
@@ -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.3.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};