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