@initx-plugin/utils 0.0.7 → 0.0.8

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.cjs ADDED
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ const node_os = require('node:os');
4
+ const index = require('./index.cjs');
5
+ require('execa');
6
+ require('picocolors');
7
+ require('which');
8
+
9
+ async function gpgList() {
10
+ const result = await index.c("gpg", ["-k"]);
11
+ const keys = [];
12
+ const lines = result.stdout.split(node_os.EOL).filter((str) => str.trim() !== "");
13
+ if (!lines || lines.length < 4) {
14
+ return [];
15
+ }
16
+ const data = {
17
+ key: "",
18
+ name: "",
19
+ email: ""
20
+ };
21
+ lines.forEach((line) => {
22
+ const [, key] = /^\s+(\w{40})$/.exec(line) || [];
23
+ if (key) {
24
+ data.key = key;
25
+ return;
26
+ }
27
+ if (line.startsWith("uid")) {
28
+ const [, name, email] = /\s(\w+)\s<([\w-]+@[\w-]+(?:\.[\w-]+)+)>/.exec(line) || [];
29
+ data.name = name;
30
+ data.email = email;
31
+ return;
32
+ }
33
+ if (line.startsWith("sub")) {
34
+ keys.push({
35
+ ...data
36
+ });
37
+ }
38
+ });
39
+ return keys;
40
+ }
41
+
42
+ exports.gpgList = gpgList;
package/dist/gpg.d.cts ADDED
@@ -0,0 +1,8 @@
1
+ interface GpgInfo {
2
+ key: string;
3
+ name: string;
4
+ email: string;
5
+ }
6
+ declare function gpgList(): Promise<GpgInfo[]>;
7
+
8
+ export { gpgList };
package/dist/gpg.d.mts ADDED
@@ -0,0 +1,8 @@
1
+ interface GpgInfo {
2
+ key: string;
3
+ name: string;
4
+ email: string;
5
+ }
6
+ declare function gpgList(): Promise<GpgInfo[]>;
7
+
8
+ export { gpgList };
package/dist/gpg.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ interface GpgInfo {
2
+ key: string;
3
+ name: string;
4
+ email: string;
5
+ }
6
+ declare function gpgList(): Promise<GpgInfo[]>;
7
+
8
+ export { gpgList };
package/dist/gpg.mjs ADDED
@@ -0,0 +1,40 @@
1
+ import { EOL } from 'node:os';
2
+ import { c } from './index.mjs';
3
+ import 'execa';
4
+ import 'picocolors';
5
+ import 'which';
6
+
7
+ async function gpgList() {
8
+ const result = await c("gpg", ["-k"]);
9
+ const keys = [];
10
+ const lines = result.stdout.split(EOL).filter((str) => str.trim() !== "");
11
+ if (!lines || lines.length < 4) {
12
+ return [];
13
+ }
14
+ const data = {
15
+ key: "",
16
+ name: "",
17
+ email: ""
18
+ };
19
+ lines.forEach((line) => {
20
+ const [, key] = /^\s+(\w{40})$/.exec(line) || [];
21
+ if (key) {
22
+ data.key = key;
23
+ return;
24
+ }
25
+ if (line.startsWith("uid")) {
26
+ const [, name, email] = /\s(\w+)\s<([\w-]+@[\w-]+(?:\.[\w-]+)+)>/.exec(line) || [];
27
+ data.name = name;
28
+ data.email = email;
29
+ return;
30
+ }
31
+ if (line.startsWith("sub")) {
32
+ keys.push({
33
+ ...data
34
+ });
35
+ }
36
+ });
37
+ return keys;
38
+ }
39
+
40
+ export { gpgList };
package/dist/index.cjs ADDED
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ const execa = require('execa');
4
+ const c$1 = require('picocolors');
5
+ const which = require('which');
6
+
7
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
8
+
9
+ const c__default = /*#__PURE__*/_interopDefaultCompat(c$1);
10
+ const which__default = /*#__PURE__*/_interopDefaultCompat(which);
11
+
12
+ const log = {
13
+ success: (msg) => console.log(`${c__default.bgGreen(c__default.black(" SUCCESS "))} ${msg}`),
14
+ info: (msg) => console.log(`${c__default.bgBlue(c__default.white(" INFO "))} ${msg}`),
15
+ warn: (msg) => console.log(`${c__default.bgYellow(c__default.black(" WARN "))} ${msg}`),
16
+ error: (msg) => console.log(`${c__default.bgRed(c__default.white(" ERROR "))} ${msg}`)
17
+ };
18
+
19
+ const where = which__default.sync;
20
+
21
+ async function c(command, options) {
22
+ try {
23
+ where(command);
24
+ return await execa.execa(command, options);
25
+ } catch (e) {
26
+ if (e.message && e.message.startsWith("not found")) {
27
+ log.error(`"${command}" is not installed`);
28
+ }
29
+ return e;
30
+ }
31
+ }
32
+
33
+ exports.c = c;
34
+ exports.log = log;
35
+ exports.where = where;
@@ -0,0 +1,15 @@
1
+ import { Result } from 'execa';
2
+ import which from 'which';
3
+
4
+ declare function c(command: string, options?: string[]): Promise<Result>;
5
+
6
+ declare const log: {
7
+ success: (msg: string) => void;
8
+ info: (msg: string) => void;
9
+ warn: (msg: string) => void;
10
+ error: (msg: string) => void;
11
+ };
12
+
13
+ declare const where: typeof which.sync;
14
+
15
+ export { c, log, where };
package/dist/index.d.mts CHANGED
@@ -1,6 +1,7 @@
1
- import * as execa from 'execa';
1
+ import { Result } from 'execa';
2
+ import which from 'which';
2
3
 
3
- declare function c(command: string, options?: string[]): Promise<execa.Result<{}> | undefined>;
4
+ declare function c(command: string, options?: string[]): Promise<Result>;
4
5
 
5
6
  declare const log: {
6
7
  success: (msg: string) => void;
@@ -9,4 +10,6 @@ declare const log: {
9
10
  error: (msg: string) => void;
10
11
  };
11
12
 
12
- export { c, log };
13
+ declare const where: typeof which.sync;
14
+
15
+ export { c, log, where };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import * as execa from 'execa';
1
+ import { Result } from 'execa';
2
+ import which from 'which';
2
3
 
3
- declare function c(command: string, options?: string[]): Promise<execa.Result<{}> | undefined>;
4
+ declare function c(command: string, options?: string[]): Promise<Result>;
4
5
 
5
6
  declare const log: {
6
7
  success: (msg: string) => void;
@@ -9,4 +10,6 @@ declare const log: {
9
10
  error: (msg: string) => void;
10
11
  };
11
12
 
12
- export { c, log };
13
+ declare const where: typeof which.sync;
14
+
15
+ export { c, log, where };
package/dist/index.mjs CHANGED
@@ -1,12 +1,6 @@
1
1
  import { execa } from 'execa';
2
2
  import c$1 from 'picocolors';
3
-
4
- async function c(command, options) {
5
- try {
6
- return await execa(command, options);
7
- } catch (e) {
8
- }
9
- }
3
+ import which from 'which';
10
4
 
11
5
  const log = {
12
6
  success: (msg) => console.log(`${c$1.bgGreen(c$1.black(" SUCCESS "))} ${msg}`),
@@ -15,4 +9,18 @@ const log = {
15
9
  error: (msg) => console.log(`${c$1.bgRed(c$1.white(" ERROR "))} ${msg}`)
16
10
  };
17
11
 
18
- export { c, log };
12
+ const where = which.sync;
13
+
14
+ async function c(command, options) {
15
+ try {
16
+ where(command);
17
+ return await execa(command, options);
18
+ } catch (e) {
19
+ if (e.message && e.message.startsWith("not found")) {
20
+ log.error(`"${command}" is not installed`);
21
+ }
22
+ return e;
23
+ }
24
+ }
25
+
26
+ export { c, log, where };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@initx-plugin/utils",
3
3
  "type": "module",
4
- "version": "0.0.7",
4
+ "version": "0.0.8",
5
5
  "description": "More convenient initialization tool",
6
6
  "author": "imba97",
7
7
  "license": "MIT",
@@ -16,7 +16,19 @@
16
16
  "keywords": [
17
17
  "initx"
18
18
  ],
19
- "main": "dist/index.mjs",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.mjs",
23
+ "require": "./dist/index.cjs"
24
+ },
25
+ "./gpg": {
26
+ "types": "./dist/gpg.d.ts",
27
+ "import": "./dist/gpg.mjs",
28
+ "require": "./dist/gpg.cjs"
29
+ }
30
+ },
31
+ "main": "dist/index.cjs",
20
32
  "module": "dist/index.mjs",
21
33
  "types": "dist/index.d.ts",
22
34
  "files": [
@@ -24,7 +36,11 @@
24
36
  ],
25
37
  "dependencies": {
26
38
  "execa": "^9.4.1",
27
- "picocolors": "^1.1.1"
39
+ "picocolors": "^1.1.1",
40
+ "which": "^5.0.0"
41
+ },
42
+ "devDependencies": {
43
+ "@types/which": "^3.0.4"
28
44
  },
29
45
  "scripts": {
30
46
  "stub": "unbuild --stub",