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