@nocoo/zhe 1.11.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/README.md +57 -0
- package/dist/api/client.d.ts +45 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +145 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/types.d.ts +45 -0
- package/dist/api/types.d.ts.map +1 -0
- package/dist/api/types.js +5 -0
- package/dist/api/types.js.map +1 -0
- package/dist/commands/create.d.ts +43 -0
- package/dist/commands/create.d.ts.map +1 -0
- package/dist/commands/create.js +173 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/delete.d.ts +20 -0
- package/dist/commands/delete.d.ts.map +1 -0
- package/dist/commands/delete.js +93 -0
- package/dist/commands/delete.js.map +1 -0
- package/dist/commands/get.d.ts +15 -0
- package/dist/commands/get.d.ts.map +1 -0
- package/dist/commands/get.js +67 -0
- package/dist/commands/get.js.map +1 -0
- package/dist/commands/list.d.ts +29 -0
- package/dist/commands/list.d.ts.map +1 -0
- package/dist/commands/list.js +90 -0
- package/dist/commands/list.js.map +1 -0
- package/dist/commands/login.d.ts +5 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +112 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts +5 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/logout.js +21 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/open.d.ts +11 -0
- package/dist/commands/open.d.ts.map +1 -0
- package/dist/commands/open.js +53 -0
- package/dist/commands/open.js.map +1 -0
- package/dist/commands/update.d.ts +40 -0
- package/dist/commands/update.d.ts.map +1 -0
- package/dist/commands/update.js +134 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/config.d.ts +38 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +66 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/utils.d.ts +41 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +105 -0
- package/dist/utils.js.map +1 -0
- package/package.json +47 -0
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration management for zhe CLI
|
|
3
|
+
*/
|
|
4
|
+
import { ConfigManager } from "@nocoo/cli-base";
|
|
5
|
+
export interface ZheConfig extends Record<string, unknown> {
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
defaultFolderId?: string;
|
|
8
|
+
outputFormat?: "table" | "json" | "minimal";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Create a ConfigManager instance. Exported for testing.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createConfigManager(configDir?: string, isDev?: boolean): ConfigManager<ZheConfig>;
|
|
14
|
+
/**
|
|
15
|
+
* For testing: reset the singleton config instance
|
|
16
|
+
*/
|
|
17
|
+
export declare function _resetConfig(): void;
|
|
18
|
+
/**
|
|
19
|
+
* For testing: set a custom config instance
|
|
20
|
+
*/
|
|
21
|
+
export declare function _setConfig(config: ConfigManager<ZheConfig>): void;
|
|
22
|
+
/**
|
|
23
|
+
* Get the API key from config
|
|
24
|
+
*/
|
|
25
|
+
export declare function getApiKey(): string | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Save the API key to config
|
|
28
|
+
*/
|
|
29
|
+
export declare function saveApiKey(apiKey: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Clear the API key from config
|
|
32
|
+
*/
|
|
33
|
+
export declare function clearApiKey(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Get output format from config
|
|
36
|
+
*/
|
|
37
|
+
export declare function getOutputFormat(): "table" | "json" | "minimal";
|
|
38
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,WAAW,SAAU,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACzD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;CAC5C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAClC,SAAS,CAAC,EAAE,MAAM,EAClB,KAAK,CAAC,EAAE,OAAO,GACb,aAAa,CAAC,SAAS,CAAC,CAI1B;AAYD;;GAEG;AACH,wBAAgB,YAAY,IAAI,IAAI,CAEnC;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,aAAa,CAAC,SAAS,CAAC,GAAG,IAAI,CAEjE;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI,MAAM,GAAG,SAAS,CAE9C;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAE/C;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,IAAI,CASlC;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,OAAO,GAAG,MAAM,GAAG,SAAS,CAE9D"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration management for zhe CLI
|
|
3
|
+
*/
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { ConfigManager } from "@nocoo/cli-base";
|
|
7
|
+
/**
|
|
8
|
+
* Create a ConfigManager instance. Exported for testing.
|
|
9
|
+
*/
|
|
10
|
+
export function createConfigManager(configDir, isDev) {
|
|
11
|
+
const dir = configDir ?? join(homedir(), ".config", "zhe");
|
|
12
|
+
const dev = isDev ?? process.env.ZHE_DEV === "1";
|
|
13
|
+
return new ConfigManager(dir, dev);
|
|
14
|
+
}
|
|
15
|
+
// Default singleton instance
|
|
16
|
+
let _config = null;
|
|
17
|
+
function getConfig() {
|
|
18
|
+
if (!_config) {
|
|
19
|
+
_config = createConfigManager();
|
|
20
|
+
}
|
|
21
|
+
return _config;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* For testing: reset the singleton config instance
|
|
25
|
+
*/
|
|
26
|
+
export function _resetConfig() {
|
|
27
|
+
_config = null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* For testing: set a custom config instance
|
|
31
|
+
*/
|
|
32
|
+
export function _setConfig(config) {
|
|
33
|
+
_config = config;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get the API key from config
|
|
37
|
+
*/
|
|
38
|
+
export function getApiKey() {
|
|
39
|
+
return getConfig().get("apiKey");
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Save the API key to config
|
|
43
|
+
*/
|
|
44
|
+
export function saveApiKey(apiKey) {
|
|
45
|
+
getConfig().set("apiKey", apiKey);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Clear the API key from config
|
|
49
|
+
*/
|
|
50
|
+
export function clearApiKey() {
|
|
51
|
+
const config = getConfig();
|
|
52
|
+
const current = config.read();
|
|
53
|
+
const { apiKey: _, ...rest } = current;
|
|
54
|
+
// Delete and rewrite without apiKey
|
|
55
|
+
config.delete();
|
|
56
|
+
if (Object.keys(rest).length > 0) {
|
|
57
|
+
config.write(rest);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get output format from config
|
|
62
|
+
*/
|
|
63
|
+
export function getOutputFormat() {
|
|
64
|
+
return getConfig().get("outputFormat") || "table";
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"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M,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IACvC,oCAAoC;IACpC,MAAM,CAAC,MAAM,EAAE,CAAC;IAChB,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,CAAC,KAAK,CAAC,IAAiB,CAAC,CAAC;IACjC,CAAC;AACF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe;IAC9B,OAAO,SAAS,EAAE,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,OAAO,CAAC;AACnD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;GAEG"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* zhe CLI — Manage zhe.to short links
|
|
4
|
+
*/
|
|
5
|
+
import { defineCommand, runMain } from "@nocoo/cli-base";
|
|
6
|
+
import { createCommand } from "./commands/create.js";
|
|
7
|
+
import { deleteCommand } from "./commands/delete.js";
|
|
8
|
+
import { getCommand } from "./commands/get.js";
|
|
9
|
+
import { listCommand } from "./commands/list.js";
|
|
10
|
+
import { loginCommand } from "./commands/login.js";
|
|
11
|
+
import { logoutCommand } from "./commands/logout.js";
|
|
12
|
+
import { openCommand } from "./commands/open.js";
|
|
13
|
+
import { updateCommand } from "./commands/update.js";
|
|
14
|
+
const main = defineCommand({
|
|
15
|
+
meta: {
|
|
16
|
+
name: "zhe",
|
|
17
|
+
version: "1.0.0",
|
|
18
|
+
description: "CLI for managing zhe.to short links",
|
|
19
|
+
},
|
|
20
|
+
subCommands: {
|
|
21
|
+
login: loginCommand,
|
|
22
|
+
logout: logoutCommand,
|
|
23
|
+
list: listCommand,
|
|
24
|
+
create: createCommand,
|
|
25
|
+
get: getCommand,
|
|
26
|
+
update: updateCommand,
|
|
27
|
+
delete: deleteCommand,
|
|
28
|
+
open: openCommand,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
runMain(main);
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,MAAM,IAAI,GAAG,aAAa,CAAC;IAC1B,IAAI,EAAE;QACL,IAAI,EAAE,KAAK;QACX,OAAO,EAAE,OAAO;QAChB,WAAW,EAAE,qCAAqC;KAClD;IACD,WAAW,EAAE;QACZ,KAAK,EAAE,YAAY;QACnB,MAAM,EAAE,aAAa;QACrB,IAAI,EAAE,WAAW;QACjB,MAAM,EAAE,aAAa;QACrB,GAAG,EAAE,UAAU;QACf,MAAM,EAAE,aAAa;QACrB,MAAM,EAAE,aAAa;QACrB,IAAI,EAAE,WAAW;KACjB;CACD,CAAC,CAAC;AAEH,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities for zhe CLI
|
|
3
|
+
*/
|
|
4
|
+
import type { Link } from "./api/types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Mask an API key for display: zhe_abcd...wxyz
|
|
7
|
+
*/
|
|
8
|
+
export declare function maskApiKey(apiKey: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Validate API key format: must start with zhe_ and be non-empty
|
|
11
|
+
*/
|
|
12
|
+
export declare function isValidApiKeyFormat(apiKey: string): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Format a date string for display
|
|
15
|
+
*/
|
|
16
|
+
export declare function formatDate(isoDate: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Format a date string with time
|
|
19
|
+
*/
|
|
20
|
+
export declare function formatDateTime(isoDate: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Truncate a string to a max length with ellipsis
|
|
23
|
+
*/
|
|
24
|
+
export declare function truncate(str: string, maxLength: number): string;
|
|
25
|
+
/**
|
|
26
|
+
* Format links as a table
|
|
27
|
+
*/
|
|
28
|
+
export declare function formatLinksTable(links: Link[]): string;
|
|
29
|
+
/**
|
|
30
|
+
* Format links as minimal output (just short URLs)
|
|
31
|
+
*/
|
|
32
|
+
export declare function formatLinksMinimal(links: Link[]): string;
|
|
33
|
+
/**
|
|
34
|
+
* Format a single link for detailed display
|
|
35
|
+
*/
|
|
36
|
+
export declare function formatLinkDetail(link: Link): string;
|
|
37
|
+
/**
|
|
38
|
+
* Parse a link ID from string, return null if invalid
|
|
39
|
+
*/
|
|
40
|
+
export declare function parseLinkId(input: string): number | null;
|
|
41
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAE3C;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAOjD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE3D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAIlD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGtD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAK/D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,CAmBtD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,CAKxD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAwBnD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAMxD"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities for zhe CLI
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Mask an API key for display: zhe_abcd...wxyz
|
|
6
|
+
*/
|
|
7
|
+
export function maskApiKey(apiKey) {
|
|
8
|
+
if (!apiKey || apiKey.length < 12) {
|
|
9
|
+
return apiKey;
|
|
10
|
+
}
|
|
11
|
+
const prefix = apiKey.slice(0, 8);
|
|
12
|
+
const suffix = apiKey.slice(-4);
|
|
13
|
+
return `${prefix}...${suffix}`;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Validate API key format: must start with zhe_ and be non-empty
|
|
17
|
+
*/
|
|
18
|
+
export function isValidApiKeyFormat(apiKey) {
|
|
19
|
+
return apiKey.startsWith("zhe_") && apiKey.length > 4;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Format a date string for display
|
|
23
|
+
*/
|
|
24
|
+
export function formatDate(isoDate) {
|
|
25
|
+
const date = new Date(isoDate);
|
|
26
|
+
const parts = date.toISOString().split("T");
|
|
27
|
+
return parts[0] ?? "";
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Format a date string with time
|
|
31
|
+
*/
|
|
32
|
+
export function formatDateTime(isoDate) {
|
|
33
|
+
const date = new Date(isoDate);
|
|
34
|
+
return date.toISOString().replace("T", " ").slice(0, 19);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Truncate a string to a max length with ellipsis
|
|
38
|
+
*/
|
|
39
|
+
export function truncate(str, maxLength) {
|
|
40
|
+
if (str.length <= maxLength) {
|
|
41
|
+
return str;
|
|
42
|
+
}
|
|
43
|
+
return `${str.slice(0, maxLength - 3)}...`;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Format links as a table
|
|
47
|
+
*/
|
|
48
|
+
export function formatLinksTable(links) {
|
|
49
|
+
if (links.length === 0) {
|
|
50
|
+
return "No links found.";
|
|
51
|
+
}
|
|
52
|
+
const header = "ID SLUG URL CLICKS CREATED";
|
|
53
|
+
const separator = "─".repeat(header.length);
|
|
54
|
+
const rows = links.map((link) => {
|
|
55
|
+
const id = String(link.id).padEnd(6);
|
|
56
|
+
const slug = truncate(link.slug, 10).padEnd(11);
|
|
57
|
+
const url = truncate(link.originalUrl, 32).padEnd(32);
|
|
58
|
+
const clicks = String(link.clicks).padEnd(7);
|
|
59
|
+
const created = formatDate(link.createdAt);
|
|
60
|
+
return `${id} ${slug} ${url} ${clicks} ${created}`;
|
|
61
|
+
});
|
|
62
|
+
return [header, separator, ...rows].join("\n");
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Format links as minimal output (just short URLs)
|
|
66
|
+
*/
|
|
67
|
+
export function formatLinksMinimal(links) {
|
|
68
|
+
if (links.length === 0) {
|
|
69
|
+
return "";
|
|
70
|
+
}
|
|
71
|
+
return links.map((link) => `zhe.to/${link.slug}`).join("\n");
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Format a single link for detailed display
|
|
75
|
+
*/
|
|
76
|
+
export function formatLinkDetail(link) {
|
|
77
|
+
const lines = [
|
|
78
|
+
`Link #${link.id}`,
|
|
79
|
+
"",
|
|
80
|
+
` Short URL: ${link.shortUrl}`,
|
|
81
|
+
` Original: ${link.originalUrl}`,
|
|
82
|
+
` Slug: ${link.slug}${link.isCustom ? " (custom)" : ""}`,
|
|
83
|
+
` Clicks: ${link.clicks}`,
|
|
84
|
+
];
|
|
85
|
+
if (link.folderId) {
|
|
86
|
+
lines.push(` Folder: ${link.folderId}`);
|
|
87
|
+
}
|
|
88
|
+
if (link.note) {
|
|
89
|
+
lines.push(` Note: ${link.note}`);
|
|
90
|
+
}
|
|
91
|
+
lines.push(` Expires: ${link.expiresAt ? formatDateTime(link.expiresAt) : "Never"}`);
|
|
92
|
+
lines.push(` Created: ${formatDateTime(link.createdAt)}`);
|
|
93
|
+
return lines.join("\n");
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Parse a link ID from string, return null if invalid
|
|
97
|
+
*/
|
|
98
|
+
export function parseLinkId(input) {
|
|
99
|
+
const id = Number.parseInt(input, 10);
|
|
100
|
+
if (Number.isNaN(id) || id <= 0) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
return id;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,MAAc;IACxC,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;QACnC,OAAO,MAAM,CAAC;IACf,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,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": "@nocoo/zhe",
|
|
3
|
+
"version": "1.11.0",
|
|
4
|
+
"description": "CLI for managing zhe.to short links",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"zhe": "dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"dev": "tsc --watch",
|
|
17
|
+
"test": "vitest run",
|
|
18
|
+
"test:watch": "vitest",
|
|
19
|
+
"test:coverage": "vitest run --coverage",
|
|
20
|
+
"lint": "tsc --noEmit && biome check src/",
|
|
21
|
+
"lint:fix": "biome check --write src/",
|
|
22
|
+
"release": "bun scripts/release.ts"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@nocoo/cli-base": "^0.2.3"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@biomejs/biome": "^1.9.0",
|
|
29
|
+
"@types/node": "^22.0.0",
|
|
30
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
31
|
+
"typescript": "^5.7.0",
|
|
32
|
+
"vitest": "^3.2.4"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"zhe",
|
|
36
|
+
"short-links",
|
|
37
|
+
"url-shortener",
|
|
38
|
+
"cli"
|
|
39
|
+
],
|
|
40
|
+
"author": "nocoo",
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "https://github.com/nocoo/zhe.git",
|
|
45
|
+
"directory": "cli"
|
|
46
|
+
}
|
|
47
|
+
}
|