create-slotkit-app 0.1.7 → 0.3.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 CHANGED
@@ -1,319 +1,319 @@
1
- # create-slotkit-app
2
-
3
- [English](#english) | [中文](#中文)
4
-
5
- ---
6
-
7
- ## English
8
-
9
- ### Scaffold Tool for SlotKit Applications
10
-
11
- `create-slotkit-app` is a CLI tool that helps you quickly create a new SlotKit application with all the necessary configuration and boilerplate code.
12
-
13
- ### Features
14
-
15
- - **Quick Setup**: Create a new SlotKit project in seconds
16
- - **Vite Integration**: Uses Vite for fast development and building
17
- - **TypeScript Support**: Full TypeScript configuration included
18
- - **Plugin System Ready**: Pre-configured plugin directory structure with a default helloworld plugin
19
- - **Auto Import Generation**: `slotkit generate-imports` runs automatically before `pnpm dev` and `pnpm build`
20
- - **Zero Configuration**: Works out of the box with sensible defaults
21
-
22
- ### Installation
23
-
24
- ```bash
25
- npm install -g create-slotkit-app
26
- # or
27
- yarn global add create-slotkit-app
28
- # or
29
- pnpm add -g create-slotkit-app
30
- ```
31
-
32
- Or use it directly with npx/pnpm create:
33
-
34
- ```bash
35
- npx create-slotkit-app my-app
36
- # or
37
- pnpm create slotkit-app my-app
38
- ```
39
-
40
- ### Usage
41
-
42
- ```bash
43
- create-slotkit-app <project-name> [options]
44
- ```
45
-
46
- **Options:**
47
-
48
- - `--template <template>` - Vite template to use (default: `react-ts`)
49
- - Available templates: `react`, `react-ts`, `vue`, `vue-ts`, `vanilla`, `vanilla-ts`
50
-
51
- ### Quick Start
52
-
53
- ```bash
54
- # Create a new SlotKit project
55
- create-slotkit-app my-slotkit-app
56
-
57
- # Navigate to the project
58
- cd my-slotkit-app
59
-
60
- # Install dependencies
61
- pnpm install
62
-
63
- # Start development server (generate-imports runs automatically)
64
- pnpm dev
65
- ```
66
-
67
- ### What Gets Created
68
-
69
- When you run `create-slotkit-app`, it creates:
70
-
71
- ```
72
- my-slotkit-app/
73
- ├── src/
74
- │ ├── App.tsx # Main app component with plugin loading
75
- │ ├── app/
76
- │ │ ├── AppLayout.tsx # Layout with Slot components
77
- │ │ └── AppLayout.css # Layout styles
78
- │ └── main.tsx # Entry point
79
- ├── plugins/
80
- │ └── helloworld/ # Default sample plugin
81
- ├── slotkit.config.ts # SlotKit configuration
82
- ├── vite.config.ts # Vite configuration
83
- ├── package.json # Project dependencies
84
- └── tsconfig.json # TypeScript configuration
85
- ```
86
-
87
- ### Project Structure
88
-
89
- The generated project includes:
90
-
91
- 1. **App.tsx**: Automatically loads and registers plugins on mount
92
- 2. **AppLayout.tsx**: Pre-configured layout with Slot components for:
93
- - `header` slot
94
- - `sidebar` slot
95
- - `content` slot
96
- - `footer` slot
97
- 3. **slotkit.config.ts**: Basic configuration pointing to `./plugins`
98
- 4. **helloworld plugin**: Located at `plugins/helloworld/` as a ready-to-run example
99
- 5. **vite.config.ts**: Vite configuration with plugin directory access
100
-
101
- ### Creating Plugins
102
-
103
- After creating your project, you can create plugins:
104
-
105
- ```bash
106
- # Create a plugin
107
- slotkit create-plugin my-plugin --slots content,sidebar
108
-
109
- # Generate import mappings (required after creating plugins)
110
- slotkit generate-imports
111
-
112
- # List all plugins
113
- slotkit list
114
-
115
- # Enable/disable plugins
116
- slotkit enable my-plugin
117
- slotkit disable my-plugin
118
- ```
119
-
120
- ### Next Steps
121
-
122
- 1. Install dependencies: `pnpm install`
123
- 2. Start the dev server: `pnpm dev` (runs `slotkit generate-imports` automatically)
124
- 3. Create additional plugins: `slotkit create-plugin my-plugin --slots content`
125
- 4. Whenever you create/modify plugins outside the dev flow, run `pnpm slotkit generate-imports`
126
-
127
- ### Configuration
128
-
129
- The generated `slotkit.config.ts` file:
130
-
131
- ```typescript
132
- import { defineConfig } from '@slotkitjs/core'
133
-
134
- export default defineConfig({
135
- pluginsDir: './plugins',
136
- // Add more configuration here
137
- })
138
- ```
139
-
140
- ### Development
141
-
142
- ```bash
143
- # Clone the repository
144
- git clone <repository-url>
145
- cd create-slotkit-app
146
-
147
- # Install dependencies
148
- pnpm install
149
-
150
- # Build
151
- pnpm build
152
-
153
- # Development mode (watch)
154
- pnpm dev
155
- ```
156
-
157
- ### License
158
-
159
- MIT
160
-
161
- ---
162
-
163
- ## 中文
164
-
165
- ### SlotKit 应用脚手架工具
166
-
167
- `create-slotkit-app` 是一个 CLI 工具,帮助你快速创建一个新的 SlotKit 应用,包含所有必要的配置和样板代码。
168
-
169
- ### 特性
170
-
171
- - **快速设置**:几秒钟内创建新的 SlotKit 项目
172
- - **Vite 集成**:使用 Vite 进行快速开发和构建
173
- - **TypeScript 支持**:包含完整的 TypeScript 配置
174
- - **插件系统就绪**:预配置的插件目录结构
175
- - **零配置**:开箱即用,使用合理的默认值
176
-
177
- ### 安装
178
-
179
- ```bash
180
- npm install -g create-slotkit-app
181
- # 或
182
- yarn global add create-slotkit-app
183
- # 或
184
- pnpm add -g create-slotkit-app
185
- ```
186
-
187
- 或者直接使用 npx/pnpm create:
188
-
189
- ```bash
190
- npx create-slotkit-app my-app
191
- # 或
192
- pnpm create slotkit-app my-app
193
- ```
194
-
195
- ### 使用
196
-
197
- ```bash
198
- create-slotkit-app <project-name> [options]
199
- ```
200
-
201
- **选项:**
202
-
203
- - `--template <template>` - 使用的 Vite 模板(默认:`react-ts`)
204
- - 可用模板:`react`, `react-ts`, `vue`, `vue-ts`, `vanilla`, `vanilla-ts`
205
-
206
- ### 快速开始
207
-
208
- ```bash
209
- # 创建新的 SlotKit 项目
210
- create-slotkit-app my-slotkit-app
211
-
212
- # 进入项目目录
213
- cd my-slotkit-app
214
-
215
- # 安装依赖
216
- pnpm install
217
-
218
- # 创建第一个插件
219
- slotkit create-plugin my-first-plugin --slots content
220
-
221
- # 生成插件导入映射
222
- slotkit generate-imports
223
-
224
- # 启动开发服务器
225
- slotkit dev
226
- ```
227
-
228
- ### 创建的内容
229
-
230
- 运行 `create-slotkit-app` 后,会创建:
231
-
232
- ```
233
- my-slotkit-app/
234
- ├── src/
235
- │ ├── App.tsx # 主应用组件,自动加载插件
236
- │ ├── app/
237
- │ │ ├── AppLayout.tsx # 包含 Slot 组件的布局
238
- │ │ └── AppLayout.css # 布局样式
239
- │ └── main.tsx # 入口文件
240
- ├── plugins/ # 插件目录(初始为空)
241
- ├── slotkit.config.ts # SlotKit 配置
242
- ├── vite.config.ts # Vite 配置
243
- ├── package.json # 项目依赖
244
- └── tsconfig.json # TypeScript 配置
245
- ```
246
-
247
- ### 项目结构
248
-
249
- 生成的项目包括:
250
-
251
- 1. **App.tsx**: 在挂载时自动加载并注册插件
252
- 2. **AppLayout.tsx**: 预配置的布局,包含以下插槽的 Slot 组件:
253
- - `header` 插槽
254
- - `sidebar` 插槽
255
- - `content` 插槽
256
- - `footer` 插槽
257
- 3. **slotkit.config.ts**: 指向 `./plugins` 目录的基本配置
258
- 4. **vite.config.ts**: Vite 配置,包含插件文件系统访问权限
259
-
260
- ### 创建插件
261
-
262
- 创建项目后,你可以创建插件:
263
-
264
- ```bash
265
- # 创建插件
266
- slotkit create-plugin my-plugin --slots content,sidebar
267
-
268
- # 生成导入映射(创建插件后必需)
269
- slotkit generate-imports
270
-
271
- # 列出所有插件
272
- slotkit list
273
-
274
- # 启用/禁用插件
275
- slotkit enable my-plugin
276
- slotkit disable my-plugin
277
- ```
278
-
279
- ### 下一步
280
-
281
- 1. **创建插件**:使用 `slotkit create-plugin` 搭建新插件
282
- 2. **生成导入**:创建插件后运行 `slotkit generate-imports`
283
- 3. **开始开发**:运行 `slotkit dev` 启动开发服务器
284
- 4. **构建**:准备生产构建时运行 `slotkit build`
285
-
286
- ### 配置
287
-
288
- 生成的 `slotkit.config.ts` 文件:
289
-
290
- ```typescript
291
- import { defineConfig } from '@slotkitjs/core'
292
-
293
- export default defineConfig({
294
- pluginsDir: './plugins',
295
- // 在这里添加更多配置
296
- })
297
- ```
298
-
299
- ### 开发
300
-
301
- ```bash
302
- # 克隆仓库
303
- git clone <repository-url>
304
- cd create-slotkit-app
305
-
306
- # 安装依赖
307
- pnpm install
308
-
309
- # 构建
310
- pnpm build
311
-
312
- # 开发模式(监听)
313
- pnpm dev
314
- ```
315
-
316
- ### 许可证
317
-
318
- MIT
319
-
1
+ # create-slotkit-app
2
+
3
+ [English](#english) | [中文](#中文)
4
+
5
+ ---
6
+
7
+ ## English
8
+
9
+ ### Scaffold Tool for SlotKit Applications
10
+
11
+ `create-slotkit-app` is a CLI tool that helps you quickly create a new SlotKit application with all the necessary configuration and boilerplate code.
12
+
13
+ ### Features
14
+
15
+ - **Quick Setup**: Create a new SlotKit project in seconds
16
+ - **Vite Integration**: Uses Vite for fast development and building
17
+ - **TypeScript Support**: Full TypeScript configuration included
18
+ - **Plugin System Ready**: Pre-configured plugin directory structure with a default helloworld plugin
19
+ - **Auto Import Generation**: `slotkit generate-imports` runs automatically before `pnpm dev` and `pnpm build`
20
+ - **Zero Configuration**: Works out of the box with sensible defaults
21
+
22
+ ### Installation
23
+
24
+ ```bash
25
+ npm install -g create-slotkit-app
26
+ # or
27
+ yarn global add create-slotkit-app
28
+ # or
29
+ pnpm add -g create-slotkit-app
30
+ ```
31
+
32
+ Or use it directly with npx/pnpm create:
33
+
34
+ ```bash
35
+ npx create-slotkit-app my-app
36
+ # or
37
+ pnpm create slotkit-app my-app
38
+ ```
39
+
40
+ ### Usage
41
+
42
+ ```bash
43
+ create-slotkit-app <project-name> [options]
44
+ ```
45
+
46
+ **Options:**
47
+
48
+ - `--template <template>` - Vite template to use (default: `react-ts`)
49
+ - Available templates: `react`, `react-ts`, `vue`, `vue-ts`, `vanilla`, `vanilla-ts`
50
+
51
+ ### Quick Start
52
+
53
+ ```bash
54
+ # Create a new SlotKit project
55
+ create-slotkit-app my-slotkit-app
56
+
57
+ # Navigate to the project
58
+ cd my-slotkit-app
59
+
60
+ # Install dependencies
61
+ pnpm install
62
+
63
+ # Start development server (generate-imports runs automatically)
64
+ pnpm dev
65
+ ```
66
+
67
+ ### What Gets Created
68
+
69
+ When you run `create-slotkit-app`, it creates:
70
+
71
+ ```
72
+ my-slotkit-app/
73
+ ├── src/
74
+ │ ├── App.tsx # Main app component with plugin loading
75
+ │ ├── app/
76
+ │ │ ├── AppLayout.tsx # Layout with Slot components
77
+ │ │ └── AppLayout.css # Layout styles
78
+ │ └── main.tsx # Entry point
79
+ ├── plugins/
80
+ │ └── helloworld/ # Default sample plugin
81
+ ├── slotkit.config.ts # SlotKit configuration
82
+ ├── vite.config.ts # Vite configuration
83
+ ├── package.json # Project dependencies
84
+ └── tsconfig.json # TypeScript configuration
85
+ ```
86
+
87
+ ### Project Structure
88
+
89
+ The generated project includes:
90
+
91
+ 1. **App.tsx**: Automatically loads and registers plugins on mount
92
+ 2. **AppLayout.tsx**: Pre-configured layout with Slot components for:
93
+ - `header` slot
94
+ - `sidebar` slot
95
+ - `content` slot
96
+ - `footer` slot
97
+ 3. **slotkit.config.ts**: Basic configuration pointing to `./plugins`
98
+ 4. **helloworld plugin**: Located at `plugins/helloworld/` as a ready-to-run example
99
+ 5. **vite.config.ts**: Vite configuration with plugin directory access
100
+
101
+ ### Creating Plugins
102
+
103
+ After creating your project, you can create plugins:
104
+
105
+ ```bash
106
+ # Create a plugin
107
+ slotkit create-plugin my-plugin --slots content,sidebar
108
+
109
+ # Generate import mappings (required after creating plugins)
110
+ slotkit generate-imports
111
+
112
+ # List all plugins
113
+ slotkit list
114
+
115
+ # Enable/disable plugins
116
+ slotkit enable my-plugin
117
+ slotkit disable my-plugin
118
+ ```
119
+
120
+ ### Next Steps
121
+
122
+ 1. Install dependencies: `pnpm install`
123
+ 2. Start the dev server: `pnpm dev` (runs `slotkit generate-imports` automatically)
124
+ 3. Create additional plugins: `slotkit create-plugin my-plugin --slots content`
125
+ 4. Whenever you create/modify plugins outside the dev flow, run `pnpm slotkit generate-imports`
126
+
127
+ ### Configuration
128
+
129
+ The generated `slotkit.config.ts` file:
130
+
131
+ ```typescript
132
+ import { defineConfig } from '@slotkitjs/core'
133
+
134
+ export default defineConfig({
135
+ pluginsDir: './plugins',
136
+ // Add more configuration here
137
+ })
138
+ ```
139
+
140
+ ### Development
141
+
142
+ ```bash
143
+ # Clone the repository
144
+ git clone <repository-url>
145
+ cd create-slotkit-app
146
+
147
+ # Install dependencies
148
+ pnpm install
149
+
150
+ # Build
151
+ pnpm build
152
+
153
+ # Development mode (watch)
154
+ pnpm dev
155
+ ```
156
+
157
+ ### License
158
+
159
+ MIT
160
+
161
+ ---
162
+
163
+ ## 中文
164
+
165
+ ### SlotKit 应用脚手架工具
166
+
167
+ `create-slotkit-app` 是一个 CLI 工具,帮助你快速创建一个新的 SlotKit 应用,包含所有必要的配置和样板代码。
168
+
169
+ ### 特性
170
+
171
+ - **快速设置**:几秒钟内创建新的 SlotKit 项目
172
+ - **Vite 集成**:使用 Vite 进行快速开发和构建
173
+ - **TypeScript 支持**:包含完整的 TypeScript 配置
174
+ - **插件系统就绪**:预配置的插件目录结构
175
+ - **零配置**:开箱即用,使用合理的默认值
176
+
177
+ ### 安装
178
+
179
+ ```bash
180
+ npm install -g create-slotkit-app
181
+ # 或
182
+ yarn global add create-slotkit-app
183
+ # 或
184
+ pnpm add -g create-slotkit-app
185
+ ```
186
+
187
+ 或者直接使用 npx/pnpm create:
188
+
189
+ ```bash
190
+ npx create-slotkit-app my-app
191
+ # 或
192
+ pnpm create slotkit-app my-app
193
+ ```
194
+
195
+ ### 使用
196
+
197
+ ```bash
198
+ create-slotkit-app <project-name> [options]
199
+ ```
200
+
201
+ **选项:**
202
+
203
+ - `--template <template>` - 使用的 Vite 模板(默认:`react-ts`)
204
+ - 可用模板:`react`, `react-ts`, `vue`, `vue-ts`, `vanilla`, `vanilla-ts`
205
+
206
+ ### 快速开始
207
+
208
+ ```bash
209
+ # 创建新的 SlotKit 项目
210
+ create-slotkit-app my-slotkit-app
211
+
212
+ # 进入项目目录
213
+ cd my-slotkit-app
214
+
215
+ # 安装依赖
216
+ pnpm install
217
+
218
+ # 创建第一个插件
219
+ slotkit create-plugin my-first-plugin --slots content
220
+
221
+ # 生成插件导入映射
222
+ slotkit generate-imports
223
+
224
+ # 启动开发服务器
225
+ slotkit dev
226
+ ```
227
+
228
+ ### 创建的内容
229
+
230
+ 运行 `create-slotkit-app` 后,会创建:
231
+
232
+ ```
233
+ my-slotkit-app/
234
+ ├── src/
235
+ │ ├── App.tsx # 主应用组件,自动加载插件
236
+ │ ├── app/
237
+ │ │ ├── AppLayout.tsx # 包含 Slot 组件的布局
238
+ │ │ └── AppLayout.css # 布局样式
239
+ │ └── main.tsx # 入口文件
240
+ ├── plugins/ # 插件目录(初始为空)
241
+ ├── slotkit.config.ts # SlotKit 配置
242
+ ├── vite.config.ts # Vite 配置
243
+ ├── package.json # 项目依赖
244
+ └── tsconfig.json # TypeScript 配置
245
+ ```
246
+
247
+ ### 项目结构
248
+
249
+ 生成的项目包括:
250
+
251
+ 1. **App.tsx**: 在挂载时自动加载并注册插件
252
+ 2. **AppLayout.tsx**: 预配置的布局,包含以下插槽的 Slot 组件:
253
+ - `header` 插槽
254
+ - `sidebar` 插槽
255
+ - `content` 插槽
256
+ - `footer` 插槽
257
+ 3. **slotkit.config.ts**: 指向 `./plugins` 目录的基本配置
258
+ 4. **vite.config.ts**: Vite 配置,包含插件文件系统访问权限
259
+
260
+ ### 创建插件
261
+
262
+ 创建项目后,你可以创建插件:
263
+
264
+ ```bash
265
+ # 创建插件
266
+ slotkit create-plugin my-plugin --slots content,sidebar
267
+
268
+ # 生成导入映射(创建插件后必需)
269
+ slotkit generate-imports
270
+
271
+ # 列出所有插件
272
+ slotkit list
273
+
274
+ # 启用/禁用插件
275
+ slotkit enable my-plugin
276
+ slotkit disable my-plugin
277
+ ```
278
+
279
+ ### 下一步
280
+
281
+ 1. **创建插件**:使用 `slotkit create-plugin` 搭建新插件
282
+ 2. **生成导入**:创建插件后运行 `slotkit generate-imports`
283
+ 3. **开始开发**:运行 `slotkit dev` 启动开发服务器
284
+ 4. **构建**:准备生产构建时运行 `slotkit build`
285
+
286
+ ### 配置
287
+
288
+ 生成的 `slotkit.config.ts` 文件:
289
+
290
+ ```typescript
291
+ import { defineConfig } from '@slotkitjs/core'
292
+
293
+ export default defineConfig({
294
+ pluginsDir: './plugins',
295
+ // 在这里添加更多配置
296
+ })
297
+ ```
298
+
299
+ ### 开发
300
+
301
+ ```bash
302
+ # 克隆仓库
303
+ git clone <repository-url>
304
+ cd create-slotkit-app
305
+
306
+ # 安装依赖
307
+ pnpm install
308
+
309
+ # 构建
310
+ pnpm build
311
+
312
+ # 开发模式(监听)
313
+ pnpm dev
314
+ ```
315
+
316
+ ### 许可证
317
+
318
+ MIT
319
+
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
2
-
3
- import '../dist/index.js'
4
-
1
+ #!/usr/bin/env node
2
+
3
+ import '../dist/index.js'
4
+
package/package.json CHANGED
@@ -1,31 +1,31 @@
1
- {
2
- "name": "create-slotkit-app",
3
- "version": "0.1.7",
4
- "type": "module",
5
- "description": "Create a new SlotKit application",
6
- "bin": {
7
- "create-slotkit-app": "./bin/create-slotkit-app.js"
8
- },
9
- "files": [
10
- "bin",
11
- "dist"
12
- ],
13
- "scripts": {
14
- "build": "tsc",
15
- "dev": "tsc --watch"
16
- },
17
- "keywords": [
18
- "slotkit",
19
- "create-app",
20
- "scaffold"
21
- ],
22
- "author": "liusnew <liushuinew@gmail.com>",
23
- "license": "MIT",
24
- "dependencies": {
25
- "commander": "^12.1.0"
26
- },
27
- "devDependencies": {
28
- "@types/node": "^24.6.0",
29
- "typescript": "~5.9.3"
30
- }
31
- }
1
+ {
2
+ "name": "create-slotkit-app",
3
+ "version": "0.3.0",
4
+ "type": "module",
5
+ "description": "Create a new SlotKit application",
6
+ "bin": {
7
+ "create-slotkit-app": "./bin/create-slotkit-app.js"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "dist"
12
+ ],
13
+ "scripts": {
14
+ "build": "tsc",
15
+ "dev": "tsc --watch"
16
+ },
17
+ "keywords": [
18
+ "slotkit",
19
+ "create-app",
20
+ "scaffold"
21
+ ],
22
+ "author": "liusnew <liushuinew@gmail.com>",
23
+ "license": "MIT",
24
+ "dependencies": {
25
+ "commander": "^12.1.0"
26
+ },
27
+ "devDependencies": {
28
+ "@types/node": "^24.6.0",
29
+ "typescript": "~5.9.3"
30
+ }
31
+ }
package/dist/index.js DELETED
@@ -1,494 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * create-slotkit-app - Initialize a new SlotKit project using Vite
4
- */
5
- import { Command } from 'commander';
6
- import { spawn, execSync } from 'child_process';
7
- import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
8
- import { resolve, join } from 'path';
9
- const program = new Command();
10
- /**
11
- * Execute command and wait for completion
12
- */
13
- function execCommand(command, args, cwd) {
14
- return new Promise((resolve, reject) => {
15
- const child = spawn(command, args, {
16
- cwd,
17
- stdio: 'inherit',
18
- shell: true
19
- });
20
- child.on('error', reject);
21
- child.on('exit', (code) => {
22
- if (code === 0) {
23
- resolve();
24
- }
25
- else {
26
- reject(new Error(`Command failed with exit code ${code}`));
27
- }
28
- });
29
- });
30
- }
31
- /**
32
- * Get latest version of a package from npm
33
- */
34
- function getLatestVersion(packageName) {
35
- try {
36
- // Try to get latest version from npm
37
- const result = execSync(`npm view ${packageName} version`, { encoding: 'utf-8', stdio: 'pipe' }).trim();
38
- return `^${result}`;
39
- }
40
- catch (error) {
41
- // If failed, use 'latest' tag to let npm resolve it
42
- console.warn(`[WARN] Could not fetch latest version of ${packageName}, using 'latest' tag`);
43
- return 'latest';
44
- }
45
- }
46
- /**
47
- * Create SlotKit-specific files
48
- */
49
- function createSlotKitFiles(projectDir) {
50
- // Replace Vite's default App.tsx with SlotKit App
51
- // This way we don't need to modify main.tsx
52
- const appFilePath = join(projectDir, 'src', 'App.tsx');
53
- // Create src/app directory for AppLayout
54
- const appDir = join(projectDir, 'src', 'app');
55
- mkdirSync(appDir, { recursive: true });
56
- // Create App.tsx (replaces Vite's default)
57
- const appTsx = `import React, { useEffect, useState } from 'react'
58
- import { AppLayout } from './app/AppLayout'
59
- import { pluginRegistry, pluginLoader, setPluginImportFunctions } from '@slotkitjs/core'
60
-
61
- // Import generated plugin import mappings
62
- // This file is generated by 'slotkit generate-imports'
63
- import * as pluginImports from './core/plugin/loader/plugin-imports.generated'
64
-
65
- // Initialize plugin import mappings
66
- if (pluginImports.getPluginImport && pluginImports.getAvailablePluginIds) {
67
- setPluginImportFunctions({
68
- getPluginImport: (pluginId: string) => {
69
- const importFn = pluginImports.getPluginImport(pluginId)
70
- if (!importFn) return undefined
71
- return () => Promise.resolve(importFn())
72
- },
73
- getAvailablePluginIds: pluginImports.getAvailablePluginIds,
74
- getAllPluginManifests: pluginImports.getAllPluginManifests,
75
- getPluginManifest: pluginImports.getPluginManifest
76
- })
77
- } else {
78
- console.warn('[WARN] Plugin import functions not found in generated file')
79
- }
80
-
81
- // Load all plugins
82
- const loadPlugins = async () => {
83
- try {
84
- const plugins = await pluginLoader.loadAllPlugins()
85
-
86
- plugins.forEach(plugin => {
87
- pluginRegistry.register(plugin)
88
- })
89
-
90
- return plugins
91
- } catch (error) {
92
- console.error('[ERROR] Failed to load plugins:', error)
93
- return []
94
- }
95
- }
96
-
97
- const App: React.FC = () => {
98
- const [pluginsLoaded, setPluginsLoaded] = useState(false)
99
- const [loadedPlugins, setLoadedPlugins] = useState<any[]>([])
100
-
101
- useEffect(() => {
102
- loadPlugins()
103
- .then((plugins) => {
104
- setPluginsLoaded(true)
105
- setLoadedPlugins(plugins)
106
- })
107
- .catch((error) => {
108
- console.error('[ERROR] Failed to load plugins:', error)
109
- })
110
- }, [])
111
-
112
- return (
113
- <div className="app">
114
- <AppLayout />
115
-
116
- {/* Plugin loading status indicator */}
117
- <div style={{
118
- position: 'fixed',
119
- top: '10px',
120
- right: '10px',
121
- background: pluginsLoaded ? '#e8f5e8' : '#fff3cd',
122
- padding: '10px',
123
- borderRadius: '4px',
124
- fontSize: '12px',
125
- border: pluginsLoaded ? '1px solid #4caf50' : '1px solid #ffc107',
126
- zIndex: 1000
127
- }}>
128
- {pluginsLoaded ? '[OK] Plugins loaded' : '[INFO] Loading plugins...'}
129
- </div>
130
-
131
- {/* Loaded plugins list */}
132
- {loadedPlugins.length > 0 && (
133
- <div style={{
134
- position: 'fixed',
135
- top: '50px',
136
- right: '10px',
137
- background: '#f3e5f5',
138
- padding: '10px',
139
- borderRadius: '4px',
140
- fontSize: '11px',
141
- border: '1px solid #9c27b0',
142
- zIndex: 1000,
143
- maxWidth: '200px'
144
- }}>
145
- <div style={{ fontWeight: 'bold', marginBottom: '5px' }}>Loaded Plugins:</div>
146
- {loadedPlugins.map(plugin => (
147
- <div key={plugin.id} style={{ marginBottom: '2px' }}>
148
- • {plugin.name} v{plugin.version}
149
- </div>
150
- ))}
151
- </div>
152
- )}
153
- </div>
154
- )
155
- }
156
-
157
- export default App;
158
- `;
159
- writeFileSync(appFilePath, appTsx, 'utf-8');
160
- // Create AppLayout.tsx
161
- const appLayoutTsx = `import React from 'react'
162
- import { Slot } from '@slotkitjs/react'
163
- import './AppLayout.css'
164
-
165
- export const AppLayout: React.FC = () => {
166
- return (
167
- <div className="app-layout">
168
- <header className="app-header">
169
- <h1>SlotKit App</h1>
170
- <Slot name="header" />
171
- </header>
172
-
173
- <main className="app-main">
174
- <aside className="app-sidebar">
175
- <h3>Sidebar</h3>
176
- <Slot name="sidebar">
177
- <p style={{ color: '#666', fontSize: '14px' }}>Waiting for plugins...</p>
178
- </Slot>
179
- </aside>
180
-
181
- <section className="app-content">
182
- <h3>Main Content</h3>
183
- <Slot name="content">
184
- <p style={{ color: '#666', fontSize: '14px' }}>Waiting for plugins...</p>
185
- </Slot>
186
- </section>
187
- </main>
188
-
189
- <footer className="app-footer">
190
- <Slot name="footer" />
191
- </footer>
192
- </div>
193
- )
194
- }
195
- `;
196
- writeFileSync(join(appDir, 'AppLayout.tsx'), appLayoutTsx, 'utf-8');
197
- // Create AppLayout.css
198
- const appLayoutCss = `.app-layout {
199
- display: flex;
200
- flex-direction: column;
201
- min-height: 100vh;
202
- }
203
-
204
- .app-header {
205
- background: #2196f3;
206
- color: white;
207
- padding: 1rem 2rem;
208
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
209
- }
210
-
211
- .app-header h1 {
212
- margin: 0;
213
- font-size: 1.5rem;
214
- }
215
-
216
- .app-main {
217
- display: flex;
218
- flex: 1;
219
- gap: 1rem;
220
- padding: 1rem;
221
- }
222
-
223
- .app-sidebar {
224
- width: 250px;
225
- background: #f5f5f5;
226
- padding: 1rem;
227
- border-radius: 8px;
228
- border: 1px solid #ddd;
229
- }
230
-
231
- .app-sidebar h3 {
232
- margin: 0 0 1rem 0;
233
- font-size: 1.1rem;
234
- color: #333;
235
- }
236
-
237
- .app-content {
238
- flex: 1;
239
- background: white;
240
- padding: 1rem;
241
- border-radius: 8px;
242
- border: 1px solid #ddd;
243
- }
244
-
245
- .app-content h3 {
246
- margin: 0 0 1rem 0;
247
- font-size: 1.1rem;
248
- color: #333;
249
- }
250
-
251
- .app-footer {
252
- background: #f5f5f5;
253
- padding: 1rem 2rem;
254
- border-top: 1px solid #ddd;
255
- text-align: center;
256
- color: #666;
257
- }
258
- `;
259
- writeFileSync(join(appDir, 'AppLayout.css'), appLayoutCss, 'utf-8');
260
- // No need to modify main.tsx - Vite's default already imports './App'
261
- // We replaced src/App.tsx above, so it will automatically work
262
- // Create slotkit.config.ts
263
- const slotkitConfig = `import { defineConfig } from '@slotkitjs/core'
264
-
265
- export default defineConfig({
266
- pluginsDir: './plugins',
267
- // Add more configuration here
268
- })
269
- `;
270
- writeFileSync(join(projectDir, 'slotkit.config.ts'), slotkitConfig, 'utf-8');
271
- // Create plugins directory and default hello-world plugin
272
- const pluginsDir = join(projectDir, 'plugins');
273
- mkdirSync(pluginsDir, { recursive: true });
274
- const helloWorldDir = join(pluginsDir, 'helloworld');
275
- const helloWorldSrcDir = join(helloWorldDir, 'src');
276
- mkdirSync(helloWorldSrcDir, { recursive: true });
277
- const helloWorldManifest = `{
278
- "id": "helloworld",
279
- "name": "Hello-world Plugin",
280
- "version": "1.0.0",
281
- "description": "A built-in hello-world plugin",
282
- "author": "SlotKit Team",
283
- "entry": "./src/index.tsx",
284
- "slots": [
285
- "content"
286
- ],
287
- "enabled": true
288
- }`;
289
- writeFileSync(join(helloWorldDir, 'manifest.json'), helloWorldManifest + '\n', 'utf-8');
290
- const helloWorldPackageJson = `{
291
- "name": "plugin-helloworld",
292
- "version": "1.0.0",
293
- "main": "src/index.tsx",
294
- "private": true
295
- }`;
296
- writeFileSync(join(helloWorldDir, 'package.json'), helloWorldPackageJson + '\n', 'utf-8');
297
- const helloWorldTsconfig = `{
298
- "extends": "../../tsconfig.json",
299
- "compilerOptions": {
300
- "jsx": "react-jsx"
301
- },
302
- "include": [
303
- "src/**/*"
304
- ]
305
- }`;
306
- writeFileSync(join(helloWorldDir, 'tsconfig.json'), helloWorldTsconfig + '\n', 'utf-8');
307
- const helloWorldIndexTsx = `import React from 'react'
308
-
309
- const HelloWorldComponent: React.FC = () => {
310
- return (
311
- <div
312
- style={{
313
- padding: '1rem',
314
- background: '#f5f5f5',
315
- border: '1px solid #ddd',
316
- borderRadius: '8px',
317
- margin: '0.5rem 0'
318
- }}
319
- >
320
- <h3>Hello-world Plugin</h3>
321
- <p>This is the default hello-world plugin generated by create-slotkit-app.</p>
322
- </div>
323
- )
324
- }
325
-
326
- const helloworldPlugin = {
327
- id: 'helloworld',
328
- name: 'Hello-world Plugin',
329
- version: '1.0.0',
330
- component: HelloWorldComponent,
331
- slots: ['content']
332
- }
333
-
334
- export { helloworldPlugin }
335
- export default helloworldPlugin
336
- `;
337
- writeFileSync(join(helloWorldSrcDir, 'index.tsx'), helloWorldIndexTsx, 'utf-8');
338
- // Create or update vite.config.ts with SlotKit-specific configuration
339
- const viteConfigPath = join(projectDir, 'vite.config.ts');
340
- const viteConfigJsPath = join(projectDir, 'vite.config.js');
341
- // Check if vite.config.ts or vite.config.js exists
342
- const existingConfigPath = existsSync(viteConfigPath) ? viteConfigPath :
343
- (existsSync(viteConfigJsPath) ? viteConfigJsPath : null);
344
- if (existingConfigPath) {
345
- // Update existing config
346
- let viteConfig = readFileSync(existingConfigPath, 'utf-8');
347
- // Add server configuration if not present
348
- if (!viteConfig.includes('server:')) {
349
- // Find the defineConfig call and add server config inside it
350
- if (viteConfig.includes('export default defineConfig')) {
351
- viteConfig = viteConfig.replace(/export default defineConfig\(\{/, `export default defineConfig({
352
- server: {
353
- fs: {
354
- // Allow access to plugin directory
355
- allow: ['..', '../..', '../../..']
356
- }
357
- },`);
358
- writeFileSync(existingConfigPath, viteConfig, 'utf-8');
359
- }
360
- }
361
- }
362
- else {
363
- // Create new vite.config.ts
364
- const viteConfigContent = `import { defineConfig } from 'vite'
365
- import react from '@vitejs/plugin-react'
366
-
367
- export default defineConfig({
368
- plugins: [react()],
369
- server: {
370
- fs: {
371
- // Allow access to plugin directory
372
- allow: ['..', '../..', '../../..']
373
- }
374
- }
375
- })
376
- `;
377
- writeFileSync(viteConfigPath, viteConfigContent, 'utf-8');
378
- }
379
- }
380
- program
381
- .name('create-slotkit-app')
382
- .description('Create a new SlotKit application')
383
- .argument('<project-name>', 'Project name')
384
- .option('--template <template>', 'Vite template to use', 'react-ts')
385
- .action(async (projectName, options) => {
386
- const projectDir = resolve(process.cwd(), projectName);
387
- if (existsSync(projectDir)) {
388
- console.error(`[ERROR] Directory "${projectName}" already exists`);
389
- process.exit(1);
390
- }
391
- // Extract just the project name (last part of path)
392
- const actualProjectName = projectName.split(/[/\\]/).pop() || projectName;
393
- const packageName = actualProjectName.toLowerCase().replace(/[^a-z0-9-]/g, '-');
394
- console.log(`[INFO] Creating SlotKit app: ${actualProjectName}`);
395
- console.log(`[INFO] Using Vite template: ${options.template || 'react'}`);
396
- try {
397
- // Step 1: Use Vite to create the base project
398
- // Vite creates the project in a subdirectory, so we need to extract just the name
399
- console.log('[INFO] Step 1: Creating Vite project...');
400
- // Create parent directory if needed (e.g., examples/test-project -> create examples first)
401
- const parentDir = resolve(projectDir, '..');
402
- if (!existsSync(parentDir)) {
403
- mkdirSync(parentDir, { recursive: true });
404
- }
405
- // Try pnpm first, fallback to npm if pnpm fails
406
- // Use non-interactive flags to skip prompts
407
- const createCommand = 'pnpm';
408
- const createArgs = [
409
- 'create', 'vite', actualProjectName,
410
- '--template', options.template || 'react-ts',
411
- '--yes' // Skip prompts
412
- ];
413
- try {
414
- // Run in the parent directory so Vite creates the project in the right place
415
- await execCommand(createCommand, createArgs, parentDir);
416
- }
417
- catch (error) {
418
- // If pnpm fails, try npm
419
- console.log('[INFO] pnpm create vite failed, trying npm...');
420
- const npmArgs = [
421
- 'create', 'vite@latest', actualProjectName,
422
- '--', '--template', options.template || 'react-ts'
423
- ];
424
- await execCommand('npm', npmArgs, parentDir);
425
- }
426
- // Step 2: Update package.json with SlotKit dependencies
427
- console.log('[INFO] Step 2: Adding SlotKit dependencies...');
428
- const packageJsonPath = join(projectDir, 'package.json');
429
- if (existsSync(packageJsonPath)) {
430
- const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
431
- // Update package name
432
- packageJson.name = packageName;
433
- // Ensure dependencies object exists
434
- if (!packageJson.dependencies) {
435
- packageJson.dependencies = {};
436
- }
437
- // Add SlotKit dependencies (merge with existing)
438
- // Use latest versions
439
- const slotkitCoreVersion = getLatestVersion('@slotkitjs/core');
440
- const slotkitReactVersion = getLatestVersion('@slotkitjs/react');
441
- packageJson.dependencies = {
442
- ...packageJson.dependencies,
443
- '@slotkitjs/core': slotkitCoreVersion,
444
- '@slotkitjs/react': slotkitReactVersion
445
- };
446
- // Ensure React dependencies are present (for React templates)
447
- if (options.template?.includes('react')) {
448
- packageJson.dependencies['react'] = packageJson.dependencies['react'] || '^19.1.1';
449
- packageJson.dependencies['react-dom'] = packageJson.dependencies['react-dom'] || '^19.1.1';
450
- // Add React types to devDependencies if not present
451
- if (!packageJson.devDependencies) {
452
- packageJson.devDependencies = {};
453
- }
454
- packageJson.devDependencies['@types/react'] = packageJson.devDependencies['@types/react'] || '^19.1.16';
455
- packageJson.devDependencies['@types/react-dom'] = packageJson.devDependencies['@types/react-dom'] || '^19.1.9';
456
- // Ensure @vitejs/plugin-react is in devDependencies
457
- packageJson.devDependencies['@vitejs/plugin-react'] = packageJson.devDependencies['@vitejs/plugin-react'] || '^5.0.4';
458
- }
459
- // Ensure scripts object exists
460
- if (!packageJson.scripts) {
461
- packageJson.scripts = {};
462
- }
463
- packageJson.scripts.dev = 'slotkit generate-imports && slotkit dev';
464
- packageJson.scripts.build = 'slotkit generate-imports && slotkit build';
465
- packageJson.scripts.preview = packageJson.scripts.preview || 'slotkit preview';
466
- packageJson.scripts['generate-imports'] = packageJson.scripts['generate-imports'] || 'slotkit generate-imports';
467
- writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n', 'utf-8');
468
- }
469
- // Step 3: Create SlotKit-specific files
470
- console.log('[INFO] Step 3: Creating SlotKit-specific files...');
471
- createSlotKitFiles(projectDir);
472
- // Step 4: Create .gitignore entry for generated files
473
- const gitignorePath = join(projectDir, '.gitignore');
474
- if (existsSync(gitignorePath)) {
475
- const gitignore = readFileSync(gitignorePath, 'utf-8');
476
- if (!gitignore.includes('plugin-imports.generated.ts')) {
477
- writeFileSync(gitignorePath, gitignore + '\n# Generated files\nsrc/core/plugin/loader/plugin-imports.generated.ts\n', 'utf-8');
478
- }
479
- }
480
- console.log('[OK] Project created successfully!');
481
- console.log(`[INFO] Project location: ${projectDir}`);
482
- console.log('\n[INFO] Next steps:');
483
- console.log(` cd ${projectName}`);
484
- console.log(' pnpm install');
485
- console.log(' pnpm dev');
486
- console.log(' # Optional: pnpm slotkit create-plugin <name> --slots <slots>');
487
- console.log(' # predev/prebuild will automatically run slotkit generate-imports');
488
- }
489
- catch (error) {
490
- console.error('[ERROR] Failed to create project:', error.message);
491
- process.exit(1);
492
- }
493
- });
494
- program.parse();