create-pokit 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Daniel Grant
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # create-pokit
2
+
3
+ Project scaffolding CLI for pok.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ bun create pokit my-project
9
+ # or
10
+ npx create-pokit my-project
11
+
12
+ cd my-project
13
+ pok
14
+ ```
15
+
16
+ ## What's Created
17
+
18
+ ```
19
+ my-project/
20
+ ├── commands/
21
+ │ ├── hello.ts
22
+ │ └── build.ts
23
+ ├── pok
24
+ ├── package.json
25
+ ├── tsconfig.json
26
+ └── .gitignore
27
+ ```
28
+
29
+ ## Documentation
30
+
31
+ See the [full documentation](https://github.com/openpok/pok/blob/main/docs/packages/create.md).
package/bin/create.ts ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * create-pokit - Scaffold a new pok project
4
+ *
5
+ * Usage:
6
+ * bun create pokit my-project
7
+ * npx create-pokit my-project
8
+ * bunx create-pokit my-project
9
+ *
10
+ * This is a pok app itself, using @pokit/core for the CLI framework.
11
+ */
12
+
13
+ import * as path from 'path';
14
+ import { runCli } from '@pokit/core';
15
+
16
+ const __dirname = path.dirname(new URL(import.meta.url).pathname);
17
+ const packageRoot = path.resolve(__dirname, '..');
18
+ const commandsDir = path.join(packageRoot, 'commands');
19
+
20
+ runCli(process.argv.slice(2), {
21
+ projectRoot: packageRoot,
22
+ commandsDir,
23
+ appName: 'create-pokit',
24
+ }).catch((err) => {
25
+ console.error(err);
26
+ process.exit(1);
27
+ });
@@ -0,0 +1,201 @@
1
+ /**
2
+ * Initialize/scaffold a new pok project
3
+ *
4
+ * This is the default command when running:
5
+ * bun create pokit my-project
6
+ */
7
+
8
+ import * as fs from 'fs';
9
+ import * as path from 'path';
10
+ import { spawn } from 'bun';
11
+ import { z } from 'zod';
12
+ import { defineCommand, type SelectOption } from '@pokit/core';
13
+ import {
14
+ generatePackageJson,
15
+ generateTsConfig,
16
+ generateExampleCommand,
17
+ generateBuildCommand,
18
+ generateGitignore,
19
+ TEMPLATES,
20
+ TEMPLATE_NAMES,
21
+ AVAILABLE_PLUGINS,
22
+ type TemplateName,
23
+ } from '../src/templates';
24
+
25
+ // =============================================================================
26
+ // Install Options
27
+ // =============================================================================
28
+
29
+ const INSTALL_OPTIONS: SelectOption<'install' | 'skip'>[] = [
30
+ {
31
+ value: 'install',
32
+ label: 'Yes, install globally',
33
+ hint: 'bun add -g pokit',
34
+ },
35
+ {
36
+ value: 'skip',
37
+ label: 'No, skip for now',
38
+ hint: 'Use "bun pok" instead',
39
+ },
40
+ ];
41
+
42
+ export const command = defineCommand({
43
+ label: 'Create a new pok project',
44
+ context: {
45
+ name: {
46
+ from: 'flag',
47
+ schema: z.string().min(1),
48
+ description: 'Project name',
49
+ },
50
+ template: {
51
+ from: 'flag',
52
+ schema: z.enum(TEMPLATE_NAMES).optional(),
53
+ description: 'Project template (starter, minimal, full, custom)',
54
+ },
55
+ },
56
+ run: async (r, ctx) => {
57
+ const projectName = ctx.context.name;
58
+ const projectPath = path.resolve(process.cwd(), projectName);
59
+
60
+ // Check if directory already exists
61
+ if (fs.existsSync(projectPath)) {
62
+ r.reporter.error(`Directory "${projectName}" already exists`);
63
+ process.exit(1);
64
+ }
65
+
66
+ // Determine plugins based on template selection
67
+ let selectedPlugins: string[];
68
+
69
+ if (ctx.context.template) {
70
+ // Template specified via flag - use it directly
71
+ const template = TEMPLATES.find((t) => t.name === ctx.context.template);
72
+ if (ctx.context.template === 'custom') {
73
+ // Custom template: still prompt for plugins
74
+ selectedPlugins = await r.prompter.multiselect({
75
+ message: 'Select plugins to install:',
76
+ options: AVAILABLE_PLUGINS,
77
+ initialValues: ['@pokit/prompter-clack', '@pokit/reporter-clack'],
78
+ required: false,
79
+ });
80
+ } else {
81
+ selectedPlugins = template?.plugins ?? [];
82
+ }
83
+ } else {
84
+ // Interactive template selection
85
+ const templateChoice = await r.prompter.select({
86
+ message: 'Choose a template:',
87
+ options: TEMPLATES.map((t) => ({
88
+ value: t.name as TemplateName,
89
+ label: t.label,
90
+ hint: t.hint,
91
+ })),
92
+ initialValue: 'starter' as TemplateName,
93
+ });
94
+
95
+ if (templateChoice === 'custom') {
96
+ // Custom template: prompt for individual plugins
97
+ selectedPlugins = await r.prompter.multiselect({
98
+ message: 'Select plugins to install:',
99
+ options: AVAILABLE_PLUGINS,
100
+ initialValues: ['@pokit/prompter-clack', '@pokit/reporter-clack'],
101
+ required: false,
102
+ });
103
+ } else {
104
+ const template = TEMPLATES.find((t) => t.name === templateChoice);
105
+ selectedPlugins = template?.plugins ?? [];
106
+ }
107
+ }
108
+
109
+ // Create project structure
110
+ await r.group('Creating project', { layout: 'sequence' }, async (grp) => {
111
+ // Create directory
112
+ await grp.activity('Create project directory', async () => {
113
+ fs.mkdirSync(projectPath, { recursive: true });
114
+ fs.mkdirSync(path.join(projectPath, 'commands'), { recursive: true });
115
+ });
116
+
117
+ // Generate files
118
+ await grp.activity('Generate project files', async () => {
119
+ const config = {
120
+ name: projectName,
121
+ plugins: selectedPlugins as string[],
122
+ };
123
+
124
+ // package.json
125
+ fs.writeFileSync(path.join(projectPath, 'package.json'), generatePackageJson(config));
126
+
127
+ // tsconfig.json
128
+ fs.writeFileSync(path.join(projectPath, 'tsconfig.json'), generateTsConfig());
129
+
130
+ // .gitignore
131
+ fs.writeFileSync(path.join(projectPath, '.gitignore'), generateGitignore());
132
+
133
+ // Example commands
134
+ fs.writeFileSync(path.join(projectPath, 'commands', 'hello.ts'), generateExampleCommand());
135
+
136
+ fs.writeFileSync(path.join(projectPath, 'commands', 'build.ts'), generateBuildCommand());
137
+ });
138
+
139
+ // Install dependencies
140
+ await grp.activity('Install dependencies', async () => {
141
+ const proc = spawn(['bun', 'install'], {
142
+ cwd: projectPath,
143
+ stdio: ['inherit', 'pipe', 'pipe'],
144
+ });
145
+ const exitCode = await proc.exited;
146
+ if (exitCode !== 0) {
147
+ throw new Error(`bun install failed with exit code ${exitCode}`);
148
+ }
149
+ });
150
+ });
151
+
152
+ // Check if pok command is available globally
153
+ let pokAvailable = false;
154
+ try {
155
+ const proc = spawn(['which', 'pok'], {
156
+ stdio: ['pipe', 'pipe', 'pipe'],
157
+ });
158
+ const exitCode = await proc.exited;
159
+ pokAvailable = exitCode === 0;
160
+ } catch {
161
+ pokAvailable = false;
162
+ }
163
+
164
+ // If pok is not available globally, ask user if they want to install it
165
+ if (!pokAvailable) {
166
+ const installChoice = await r.prompter.select({
167
+ message: 'Install global pok command?',
168
+ options: INSTALL_OPTIONS,
169
+ });
170
+
171
+ if (installChoice === 'install') {
172
+ await r.group('Installing global CLI', { layout: 'sequence' }, async (grp) => {
173
+ await grp.activity('Install pokit globally', async () => {
174
+ const proc = spawn(['bun', 'add', '-g', 'pokit'], {
175
+ stdio: ['inherit', 'pipe', 'pipe'],
176
+ });
177
+ const exitCode = await proc.exited;
178
+ if (exitCode !== 0) {
179
+ throw new Error(`Global install failed with exit code ${exitCode}`);
180
+ }
181
+ });
182
+ });
183
+ pokAvailable = true;
184
+ }
185
+ }
186
+
187
+ // Show next steps
188
+ r.reporter.success(`Project "${projectName}" created successfully!`);
189
+ r.reporter.info('');
190
+ r.reporter.info('Next steps:');
191
+ r.reporter.step(` cd ${projectName}`);
192
+ if (pokAvailable) {
193
+ r.reporter.step(' pok');
194
+ } else {
195
+ r.reporter.step(' bun pok');
196
+ r.reporter.info('');
197
+ r.reporter.info('To install the global pok command later:');
198
+ r.reporter.step(' bun add -g pokit');
199
+ }
200
+ },
201
+ });
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "create-pokit",
3
+ "version": "0.0.1",
4
+ "description": "Scaffold a new pok project",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/notation-dev/openpok.git",
10
+ "directory": "packages/create"
11
+ },
12
+ "homepage": "https://github.com/notation-dev/openpok#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/notation-dev/openpok/issues"
15
+ },
16
+ "bin": {
17
+ "create-pokit": "./bin/create.ts"
18
+ },
19
+ "files": [
20
+ "bin",
21
+ "commands",
22
+ "templates",
23
+ "src"
24
+ ],
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "dependencies": {
29
+ "@clack/prompts": "^0.11.0",
30
+ "zod": "^4.0.0",
31
+ "@pokit/core": "0.0.1",
32
+ "@pokit/prompter-clack": "0.0.1",
33
+ "@pokit/reporter-clack": "0.0.1"
34
+ },
35
+ "devDependencies": {
36
+ "@types/bun": "latest"
37
+ },
38
+ "engines": {
39
+ "bun": ">=1.0.0"
40
+ },
41
+ "keywords": [
42
+ "cli",
43
+ "create",
44
+ "scaffold",
45
+ "pok",
46
+ "pokit"
47
+ ]
48
+ }
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Template generators for scaffolding
3
+ */
4
+
5
+ import type { MultiselectOption } from '@pokit/core';
6
+
7
+ export type ProjectConfig = {
8
+ name: string;
9
+ plugins: string[];
10
+ };
11
+
12
+ // =============================================================================
13
+ // Template Definitions
14
+ // =============================================================================
15
+
16
+ export type Template = {
17
+ name: string;
18
+ label: string;
19
+ hint: string;
20
+ plugins: string[];
21
+ };
22
+
23
+ export const TEMPLATE_NAMES = ['starter', 'minimal', 'full', 'custom'] as const;
24
+ export type TemplateName = (typeof TEMPLATE_NAMES)[number];
25
+
26
+ export const TEMPLATES: Template[] = [
27
+ {
28
+ name: 'starter',
29
+ label: 'Starter (recommended)',
30
+ hint: 'Interactive prompts + beautiful output',
31
+ plugins: ['@pokit/prompter-clack', '@pokit/reporter-clack'],
32
+ },
33
+ {
34
+ name: 'minimal',
35
+ label: 'Minimal',
36
+ hint: 'Core only - add adapters later',
37
+ plugins: [],
38
+ },
39
+ {
40
+ name: 'full',
41
+ label: 'Full',
42
+ hint: 'All plugins including tabbed UI',
43
+ plugins: ['@pokit/prompter-clack', '@pokit/reporter-clack', '@pokit/tabs-ink'],
44
+ },
45
+ {
46
+ name: 'custom',
47
+ label: 'Custom',
48
+ hint: 'Choose plugins individually',
49
+ plugins: [], // Will prompt separately
50
+ },
51
+ ];
52
+
53
+ // =============================================================================
54
+ // Plugin Options (for custom template)
55
+ // =============================================================================
56
+
57
+ export const AVAILABLE_PLUGINS: MultiselectOption<string>[] = [
58
+ {
59
+ value: '@pokit/prompter-clack',
60
+ label: 'Prompter (clack)',
61
+ hint: 'Interactive prompts for user input',
62
+ },
63
+ {
64
+ value: '@pokit/reporter-clack',
65
+ label: 'Reporter (clack)',
66
+ hint: 'Beautiful CLI output and spinners',
67
+ },
68
+ {
69
+ value: '@pokit/tabs-ink',
70
+ label: 'Tabs (ink)',
71
+ hint: 'Tabbed UI for parallel processes',
72
+ },
73
+ ];
74
+
75
+ // =============================================================================
76
+ // File Generators
77
+ // =============================================================================
78
+
79
+ export function generatePackageJson(config: ProjectConfig): string {
80
+ const deps: Record<string, string> = {
81
+ '@pokit/core': 'latest',
82
+ };
83
+
84
+ // Add selected plugins
85
+ for (const plugin of config.plugins) {
86
+ deps[plugin] = 'latest';
87
+ }
88
+
89
+ const pkg = {
90
+ name: config.name,
91
+ version: '0.0.1',
92
+ type: 'module',
93
+ scripts: {
94
+ pok: 'bun pok',
95
+ },
96
+ dependencies: deps,
97
+ devDependencies: {
98
+ '@types/bun': 'latest',
99
+ },
100
+ };
101
+
102
+ return JSON.stringify(pkg, null, 2) + '\n';
103
+ }
104
+
105
+ export function generateTsConfig(): string {
106
+ const config = {
107
+ compilerOptions: {
108
+ target: 'ESNext',
109
+ module: 'ESNext',
110
+ moduleResolution: 'bundler',
111
+ types: ['bun'],
112
+ strict: true,
113
+ skipLibCheck: true,
114
+ noEmit: true,
115
+ },
116
+ include: ['commands/**/*', 'src/**/*'],
117
+ };
118
+
119
+ return JSON.stringify(config, null, 2) + '\n';
120
+ }
121
+
122
+ export function generateExampleCommand(): string {
123
+ return `/**
124
+ * Example command
125
+ *
126
+ * Run with: pok hello
127
+ */
128
+
129
+ import { defineCommand } from '@pokit/core';
130
+
131
+ export const command = defineCommand({
132
+ label: 'Say hello',
133
+ run: async (r) => {
134
+ r.reporter.info('Hello from pok!');
135
+ },
136
+ });
137
+ `;
138
+ }
139
+
140
+ export function generateBuildCommand(): string {
141
+ return `/**
142
+ * Build command
143
+ */
144
+
145
+ import { defineCommand } from '@pokit/core';
146
+
147
+ export const command = defineCommand({
148
+ label: 'Build project',
149
+ run: async (r) => {
150
+ await r.exec('bun tsc --noEmit');
151
+ },
152
+ });
153
+ `;
154
+ }
155
+
156
+ export function generateGitignore(): string {
157
+ return `node_modules/
158
+ dist/
159
+ .DS_Store
160
+ `;
161
+ }