@initx-plugin/utils 0.0.26 → 0.0.28

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,5 +1 @@
1
- export { g as gpgList } from './shared/utils.7b284c15.mjs';
2
- import 'node:os';
3
- import 'ora';
4
- import 'tinyexec';
5
- import 'which';
1
+ export{g as gpgList}from"./shared/utils.BoT6_OSW.mjs";import"ora";import"tinyexec";import"which";
package/dist/index.mjs CHANGED
@@ -1,47 +1 @@
1
- export { c, g as gpgList, l as loadingFunction, w as where } from './shared/utils.7b284c15.mjs';
2
- import _inquirer from 'inquirer';
3
- import c from 'picocolors';
4
- import 'node:os';
5
- import 'ora';
6
- import 'tinyexec';
7
- import 'which';
8
-
9
- async function confirm(message) {
10
- const { result } = await _inquirer.prompt([
11
- {
12
- type: "confirm",
13
- name: "result",
14
- message
15
- }
16
- ]);
17
- return result;
18
- }
19
- async function select(message, options) {
20
- const { result } = await _inquirer.prompt([
21
- {
22
- type: "list",
23
- name: "result",
24
- message,
25
- choices: options.map((option, index) => {
26
- return typeof option === "string" ? {
27
- name: option,
28
- value: index
29
- } : option;
30
- })
31
- }
32
- ]);
33
- return result;
34
- }
35
- const inquirer = {
36
- confirm,
37
- select
38
- };
39
-
40
- const log = {
41
- success: (msg) => console.log(`${c.bgGreen(c.black(" SUCCESS "))} ${msg}`),
42
- info: (msg) => console.log(`${c.bgBlue(c.white(" INFO "))} ${msg}`),
43
- warn: (msg) => console.log(`${c.bgYellow(c.black(" WARN "))} ${msg}`),
44
- error: (msg) => console.log(`${c.bgRed(c.white(" ERROR "))} ${msg}`)
45
- };
46
-
47
- export { inquirer, log };
1
+ export{c,g as gpgList,l as loadingFunction,w as where}from"./shared/utils.BoT6_OSW.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};
@@ -0,0 +1 @@
1
+ import f from"ora";import{x as g}from"tinyexec";import l from"which";const a=l.sync;async function i(s,o,e={}){const t={success:!1,content:"Unknown error"};try{a(s);const n=await g(s,o,e);t.success=n.exitCode===0,t.content=(t.success?n.stdout:n.stderr).trim()}catch(n){n.message&&n.message.startsWith("not found")?t.content=`can not find command: ${s}`:t.content=n.message}return t}async function w(s,o){const e=f(s).start();return o().finally(()=>{e.stop()})}async function y(){const s=await i("gpg",["-k"]),o=[],e=s.content.split(/\r?\n|\r/).filter(r=>r.trim()!=="");if(!e||e.length<4)return[];const t={key:"",name:"",email:""},n={key:/^\s+(\w{40})$/,user:/\s(\w+)\s<([\w-]+@[\w-]+(?:\.[\w-]+)+)>/};return e.forEach(r=>{const[,c]=n.key.exec(r)||[];if(c){t.key=c;return}if(r.startsWith("uid")){const[,u,m]=n.user.exec(r)||[];t.name=u,t.email=m;return}r.startsWith("sub")&&o.push({...t})}),o}export{i as c,y as g,w 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.0.26",
4
+ "version": "0.0.28",
5
5
  "description": "A more convenient scripting engine",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/initx-collective/initx#readme",
@@ -32,10 +32,10 @@
32
32
  "dist"
33
33
  ],
34
34
  "dependencies": {
35
- "inquirer": "^12.1.0",
35
+ "inquirer": "^12.3.0",
36
36
  "ora": "^8.1.1",
37
37
  "picocolors": "^1.1.1",
38
- "tinyexec": "^0.3.1",
38
+ "tinyexec": "^0.3.2",
39
39
  "which": "^5.0.0"
40
40
  },
41
41
  "devDependencies": {
@@ -1,67 +0,0 @@
1
- import { EOL } from 'node:os';
2
- import ora from 'ora';
3
- import { x } from 'tinyexec';
4
- import which from 'which';
5
-
6
- const where = which.sync;
7
-
8
- async function c(command, options, execaOptions = {}) {
9
- const result = {
10
- success: false,
11
- content: "Unknown error"
12
- };
13
- try {
14
- where(command);
15
- const xResult = await x(command, options, execaOptions);
16
- result.success = xResult.exitCode === 0;
17
- result.content = (result.success ? xResult.stdout : xResult.stderr).trim();
18
- } catch (e) {
19
- if (e.message && e.message.startsWith("not found")) {
20
- result.content = `can not find command: ${command}`;
21
- } else {
22
- result.content = e.message;
23
- }
24
- }
25
- return result;
26
- }
27
- async function loadingFunction(message, fn) {
28
- const spinner = ora(message).start();
29
- return fn().finally(() => {
30
- spinner.stop();
31
- });
32
- }
33
-
34
- async function gpgList() {
35
- const result = await c("gpg", ["-k"]);
36
- const keys = [];
37
- const lines = result.content.split(EOL).filter((str) => str.trim() !== "");
38
- if (!lines || lines.length < 4) {
39
- return [];
40
- }
41
- const data = {
42
- key: "",
43
- name: "",
44
- email: ""
45
- };
46
- lines.forEach((line) => {
47
- const [, key] = /^\s+(\w{40})$/.exec(line) || [];
48
- if (key) {
49
- data.key = key;
50
- return;
51
- }
52
- if (line.startsWith("uid")) {
53
- const [, name, email] = /\s(\w+)\s<([\w-]+@[\w-]+(?:\.[\w-]+)+)>/.exec(line) || [];
54
- data.name = name;
55
- data.email = email;
56
- return;
57
- }
58
- if (line.startsWith("sub")) {
59
- keys.push({
60
- ...data
61
- });
62
- }
63
- });
64
- return keys;
65
- }
66
-
67
- export { c, gpgList as g, loadingFunction as l, where as w };