@cloudflare/cli-shared-helpers 0.0.1

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.
@@ -0,0 +1,25 @@
1
+ import { Prompt, SelectPrompt } from "@clack/core";
2
+
3
+ //#region select-list.d.ts
4
+ type Option = {
5
+ label: string;
6
+ value: string;
7
+ };
8
+ type OptionWithDetails = Option & {
9
+ details: string[];
10
+ };
11
+ type SelectRefreshableOptions = ConstructorParameters<typeof SelectPrompt<Option>>[0] & {
12
+ onRefresh: () => Promise<OptionWithDetails[]>;
13
+ } & {
14
+ options: OptionWithDetails[];
15
+ };
16
+ declare class SelectRefreshablePrompt extends Prompt {
17
+ options: OptionWithDetails[];
18
+ cursor: number;
19
+ private get _value();
20
+ private changeValue;
21
+ constructor(opts: SelectRefreshableOptions);
22
+ }
23
+ //#endregion
24
+ export { OptionWithDetails, SelectRefreshablePrompt };
25
+ //# sourceMappingURL=select-list.d.mts.map
@@ -0,0 +1,47 @@
1
+ import { Prompt } from "@clack/core";
2
+
3
+ //#region select-list.ts
4
+ var SelectRefreshablePrompt = class extends Prompt {
5
+ options;
6
+ cursor = 0;
7
+ get _value() {
8
+ return this.options[this.cursor];
9
+ }
10
+ changeValue() {
11
+ this.value = this._value.value;
12
+ }
13
+ constructor(opts) {
14
+ super(opts, false);
15
+ this.options = opts.options;
16
+ this.cursor = this.options.findIndex(({ value }) => value === opts.initialValue);
17
+ if (this.cursor === -1) this.cursor = 0;
18
+ this.changeValue();
19
+ this.on("key", (c) => {
20
+ if (c !== "r") return;
21
+ opts.onRefresh().then((newOptions) => {
22
+ this.options = [...newOptions];
23
+ this.cursor = 0;
24
+ this.changeValue();
25
+ const that = this;
26
+ if ("render" in that && typeof that.render === "function") that.render();
27
+ }).catch(() => {});
28
+ });
29
+ this.on("cursor", (key) => {
30
+ switch (key) {
31
+ case "left":
32
+ case "up":
33
+ this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
34
+ break;
35
+ case "down":
36
+ case "right":
37
+ this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
38
+ break;
39
+ }
40
+ this.changeValue();
41
+ });
42
+ }
43
+ };
44
+
45
+ //#endregion
46
+ export { SelectRefreshablePrompt as default };
47
+ //# sourceMappingURL=select-list.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select-list.mjs","names":[],"sources":["../select-list.ts"],"sourcesContent":["import { Prompt } from \"@clack/core\";\nimport type { SelectPrompt } from \"@clack/core\";\n\nexport type Option = {\n\tlabel: string;\n\tvalue: string;\n};\n\nexport type OptionWithDetails = Option & {\n\tdetails: string[];\n};\n\nexport type SelectRefreshableOptions = ConstructorParameters<\n\ttypeof SelectPrompt<Option>\n>[0] & {\n\tonRefresh: () => Promise<OptionWithDetails[]>;\n} & {\n\toptions: OptionWithDetails[];\n};\n\nexport default class SelectRefreshablePrompt extends Prompt {\n\toptions: OptionWithDetails[];\n\tcursor = 0;\n\n\tprivate get _value() {\n\t\treturn this.options[this.cursor];\n\t}\n\n\tprivate changeValue() {\n\t\tthis.value = this._value.value;\n\t}\n\n\tconstructor(opts: SelectRefreshableOptions) {\n\t\tsuper(opts, false);\n\n\t\tthis.options = opts.options;\n\t\tthis.cursor = this.options.findIndex(\n\t\t\t({ value }) => value === opts.initialValue\n\t\t);\n\t\tif (this.cursor === -1) {\n\t\t\tthis.cursor = 0;\n\t\t}\n\t\tthis.changeValue();\n\n\t\tthis.on(\"key\", (c) => {\n\t\t\tif (c !== \"r\") {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tvoid opts\n\t\t\t\t.onRefresh()\n\t\t\t\t.then((newOptions) => {\n\t\t\t\t\tthis.options = [...newOptions];\n\t\t\t\t\tthis.cursor = 0;\n\t\t\t\t\tthis.changeValue();\n\t\t\t\t\t// Workaround: so 'render' is private in Prompt, but we know what we're doing here (right?) so\n\t\t\t\t\t// let's just access it anyway.\n\t\t\t\t\tconst that = this as Record<string, unknown>;\n\t\t\t\t\tif (\"render\" in that && typeof that.render === \"function\") {\n\t\t\t\t\t\tthat.render();\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch(() => {});\n\t\t});\n\n\t\tthis.on(\"cursor\", (key) => {\n\t\t\tswitch (key) {\n\t\t\t\tcase \"left\":\n\t\t\t\tcase \"up\":\n\t\t\t\t\tthis.cursor =\n\t\t\t\t\t\tthis.cursor === 0 ? this.options.length - 1 : this.cursor - 1;\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"down\":\n\t\t\t\tcase \"right\":\n\t\t\t\t\tthis.cursor =\n\t\t\t\t\t\tthis.cursor === this.options.length - 1 ? 0 : this.cursor + 1;\n\t\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tthis.changeValue();\n\t\t});\n\t}\n}\n"],"mappings":";;;AAoBA,IAAqB,0BAArB,cAAqD,OAAO;CAC3D;CACA,SAAS;CAET,IAAY,SAAS;AACpB,SAAO,KAAK,QAAQ,KAAK;;CAG1B,AAAQ,cAAc;AACrB,OAAK,QAAQ,KAAK,OAAO;;CAG1B,YAAY,MAAgC;AAC3C,QAAM,MAAM,MAAM;AAElB,OAAK,UAAU,KAAK;AACpB,OAAK,SAAS,KAAK,QAAQ,WACzB,EAAE,YAAY,UAAU,KAAK,aAC9B;AACD,MAAI,KAAK,WAAW,GACnB,MAAK,SAAS;AAEf,OAAK,aAAa;AAElB,OAAK,GAAG,QAAQ,MAAM;AACrB,OAAI,MAAM,IACT;AAED,GAAK,KACH,WAAW,CACX,MAAM,eAAe;AACrB,SAAK,UAAU,CAAC,GAAG,WAAW;AAC9B,SAAK,SAAS;AACd,SAAK,aAAa;IAGlB,MAAM,OAAO;AACb,QAAI,YAAY,QAAQ,OAAO,KAAK,WAAW,WAC9C,MAAK,QAAQ;KAEb,CACD,YAAY,GAAG;IAChB;AAEF,OAAK,GAAG,WAAW,QAAQ;AAC1B,WAAQ,KAAR;IACC,KAAK;IACL,KAAK;AACJ,UAAK,SACJ,KAAK,WAAW,IAAI,KAAK,QAAQ,SAAS,IAAI,KAAK,SAAS;AAC7D;IACD,KAAK;IACL,KAAK;AACJ,UAAK,SACJ,KAAK,WAAW,KAAK,QAAQ,SAAS,IAAI,IAAI,KAAK,SAAS;AAC7D;;AAGF,QAAK,aAAa;IACjB"}
@@ -0,0 +1,16 @@
1
+ //#region streams.d.ts
2
+ /**
3
+ * This file simply re-exports the process's writeable streams
4
+ * The intention is to provide a boundary to mock in tests
5
+ * Anywhere in this package that writes to stdout/stderr,
6
+ * should use this module to get references to them.
7
+ */
8
+ declare const stdout: NodeJS.WriteStream & {
9
+ fd: 1;
10
+ };
11
+ declare const stderr: NodeJS.WriteStream & {
12
+ fd: 2;
13
+ };
14
+ //#endregion
15
+ export { stderr, stdout };
16
+ //# sourceMappingURL=streams.d.mts.map
@@ -0,0 +1,13 @@
1
+ //#region streams.ts
2
+ /**
3
+ * This file simply re-exports the process's writeable streams
4
+ * The intention is to provide a boundary to mock in tests
5
+ * Anywhere in this package that writes to stdout/stderr,
6
+ * should use this module to get references to them.
7
+ */
8
+ const stdout = process.stdout;
9
+ const stderr = process.stderr;
10
+
11
+ //#endregion
12
+ export { stderr, stdout };
13
+ //# sourceMappingURL=streams.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streams.mjs","names":[],"sources":["../streams.ts"],"sourcesContent":["/**\n * This file simply re-exports the process's writeable streams\n * The intention is to provide a boundary to mock in tests\n * Anywhere in this package that writes to stdout/stderr,\n * should use this module to get references to them.\n */\n\nexport const stdout = process.stdout;\nexport const stderr = process.stderr;\n"],"mappings":";;;;;;;AAOA,MAAa,SAAS,QAAQ;AAC9B,MAAa,SAAS,QAAQ"}
package/package.json ADDED
@@ -0,0 +1,86 @@
1
+ {
2
+ "name": "@cloudflare/cli-shared-helpers",
3
+ "version": "0.0.1",
4
+ "description": "Internal shared CLI helpers for workers-sdk. Not intended for external use — APIs may change without notice.",
5
+ "keywords": [
6
+ "cli",
7
+ "cloudflare",
8
+ "cloudflare workers",
9
+ "workers"
10
+ ],
11
+ "homepage": "https://github.com/cloudflare/workers-sdk/tree/main/packages/cli#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/cloudflare/workers-sdk/issues"
14
+ },
15
+ "license": "MIT OR Apache-2.0",
16
+ "author": "wrangler@cloudflare.com",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/cloudflare/workers-sdk.git",
20
+ "directory": "packages/cli"
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.mts",
28
+ "import": "./dist/index.mjs"
29
+ },
30
+ "./args": {
31
+ "types": "./dist/args.d.mts",
32
+ "import": "./dist/args.mjs"
33
+ },
34
+ "./colors": {
35
+ "types": "./dist/colors.d.mts",
36
+ "import": "./dist/colors.mjs"
37
+ },
38
+ "./command": {
39
+ "types": "./dist/command.d.mts",
40
+ "import": "./dist/command.mjs"
41
+ },
42
+ "./error": {
43
+ "types": "./dist/error.d.mts",
44
+ "import": "./dist/error.mjs"
45
+ },
46
+ "./gitignore": {
47
+ "types": "./dist/gitignore.d.mts",
48
+ "import": "./dist/gitignore.mjs"
49
+ },
50
+ "./interactive": {
51
+ "types": "./dist/interactive.d.mts",
52
+ "import": "./dist/interactive.mjs"
53
+ },
54
+ "./packages": {
55
+ "types": "./dist/packages.d.mts",
56
+ "import": "./dist/packages.mjs"
57
+ },
58
+ "./streams": {
59
+ "types": "./dist/streams.d.mts",
60
+ "import": "./dist/streams.mjs"
61
+ }
62
+ },
63
+ "dependencies": {
64
+ "@clack/core": "^1.2.0",
65
+ "chalk": "^5.2.0",
66
+ "ci-info": "^4.4.0",
67
+ "cross-spawn": "^7.0.3",
68
+ "log-update": "^5.0.1",
69
+ "@cloudflare/workers-utils": "0.18.0"
70
+ },
71
+ "devDependencies": {
72
+ "@types/cross-spawn": "^6.0.2",
73
+ "tsdown": "^0.15.9",
74
+ "@cloudflare/workers-tsconfig": "0.0.0"
75
+ },
76
+ "volta": {
77
+ "extends": "../../package.json"
78
+ },
79
+ "scripts": {
80
+ "build": "tsdown",
81
+ "check:type": "tsc",
82
+ "deploy": "echo 'no deploy'",
83
+ "dev": "tsdown --watch",
84
+ "test:ci": "vitest run"
85
+ }
86
+ }