@pokit/prompter-clack 0.0.1 → 0.0.2

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.
Files changed (2) hide show
  1. package/package.json +6 -6
  2. package/src/prompter.ts +78 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pokit/prompter-clack",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Clack-based prompter adapter for pok CLI applications",
5
5
  "keywords": [
6
6
  "cli",
@@ -26,9 +26,8 @@
26
26
  "bugs": {
27
27
  "url": "https://github.com/notation-dev/openpok/issues"
28
28
  },
29
- "main": "./src/index.ts",
30
- "module": "./src/index.ts",
31
- "types": "./src/index.ts",
29
+ "main": "./dist/index.js",
30
+ "types": "./dist/index.d.ts",
32
31
  "exports": {
33
32
  ".": {
34
33
  "bun": "./src/index.ts",
@@ -39,7 +38,8 @@
39
38
  "files": [
40
39
  "dist",
41
40
  "README.md",
42
- "LICENSE"
41
+ "LICENSE",
42
+ "src"
43
43
  ],
44
44
  "publishConfig": {
45
45
  "access": "public"
@@ -51,7 +51,7 @@
51
51
  "@types/bun": "latest"
52
52
  },
53
53
  "peerDependencies": {
54
- "@pokit/core": "0.0.1"
54
+ "@pokit/core": "0.0.2"
55
55
  },
56
56
  "engines": {
57
57
  "bun": ">=1.0.0"
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Clack Prompter Implementation
3
+ *
4
+ * Implements the Prompter interface using @clack/prompts.
5
+ */
6
+
7
+ import * as p from '@clack/prompts';
8
+ import type {
9
+ Prompter,
10
+ SelectOptions,
11
+ MultiselectOptions,
12
+ ConfirmOptions,
13
+ TextOptions,
14
+ } from '@pokit/core';
15
+
16
+ /**
17
+ * Create a Prompter using @clack/prompts
18
+ */
19
+ export function createPrompter(): Prompter {
20
+ return {
21
+ async select<T>(options: SelectOptions<T>): Promise<T> {
22
+ const result = await p.select({
23
+ message: options.message,
24
+ options: options.options as Parameters<typeof p.select<T>>[0]['options'],
25
+ initialValue: options.initialValue,
26
+ });
27
+
28
+ if (p.isCancel(result)) {
29
+ process.exit(0);
30
+ }
31
+
32
+ return result as T;
33
+ },
34
+
35
+ async multiselect<T>(options: MultiselectOptions<T>): Promise<T[]> {
36
+ const result = await p.multiselect({
37
+ message: options.message,
38
+ options: options.options as Parameters<typeof p.multiselect<T>>[0]['options'],
39
+ initialValues: options.initialValues,
40
+ required: options.required,
41
+ });
42
+
43
+ if (p.isCancel(result)) {
44
+ process.exit(0);
45
+ }
46
+
47
+ return result as T[];
48
+ },
49
+
50
+ async confirm(options: ConfirmOptions): Promise<boolean> {
51
+ const result = await p.confirm({
52
+ message: options.message,
53
+ initialValue: options.initialValue,
54
+ });
55
+
56
+ if (p.isCancel(result)) {
57
+ process.exit(0);
58
+ }
59
+
60
+ return result;
61
+ },
62
+
63
+ async text(options: TextOptions): Promise<string> {
64
+ const result = await p.text({
65
+ message: options.message,
66
+ placeholder: options.placeholder,
67
+ initialValue: options.initialValue,
68
+ validate: options.validate,
69
+ });
70
+
71
+ if (p.isCancel(result)) {
72
+ process.exit(0);
73
+ }
74
+
75
+ return result;
76
+ },
77
+ };
78
+ }