create-slotkit-app 0.1.1 → 0.1.3

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 (3) hide show
  1. package/README.md +322 -0
  2. package/dist/index.js +34 -41
  3. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,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
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
+
package/dist/index.js CHANGED
@@ -3,8 +3,8 @@
3
3
  * create-slotkit-app - Initialize a new SlotKit project using Vite
4
4
  */
5
5
  import { Command } from 'commander';
6
- import { spawn } from 'child_process';
7
- import { existsSync, readFileSync, writeFileSync, mkdirSync, unlinkSync } from 'fs';
6
+ import { spawn, execSync } from 'child_process';
7
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
8
8
  import { resolve, join } from 'path';
9
9
  const program = new Command();
10
10
  /**
@@ -28,16 +28,34 @@ function execCommand(command, args, cwd) {
28
28
  });
29
29
  });
30
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
+ }
31
46
  /**
32
47
  * Create SlotKit-specific files
33
48
  */
34
49
  function createSlotKitFiles(projectDir) {
35
- // Create src/app directory
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
36
54
  const appDir = join(projectDir, 'src', 'app');
37
55
  mkdirSync(appDir, { recursive: true });
38
- // Create App.tsx
56
+ // Create App.tsx (replaces Vite's default)
39
57
  const appTsx = `import React, { useEffect, useState } from 'react'
40
- import { AppLayout } from './AppLayout'
58
+ import { AppLayout } from './app/AppLayout'
41
59
  import { pluginRegistry, pluginLoader } from '@slotkitjs/core'
42
60
 
43
61
  /**
@@ -66,7 +84,7 @@ const loadPlugins = async () => {
66
84
  }
67
85
  }
68
86
 
69
- export const App: React.FC = () => {
87
+ const App: React.FC = () => {
70
88
  const [pluginsLoaded, setPluginsLoaded] = useState(false)
71
89
  const [loadedPlugins, setLoadedPlugins] = useState<any[]>([])
72
90
 
@@ -123,8 +141,10 @@ export const App: React.FC = () => {
123
141
  </div>
124
142
  )
125
143
  }
144
+
145
+ export default App;
126
146
  `;
127
- writeFileSync(join(appDir, 'App.tsx'), appTsx, 'utf-8');
147
+ writeFileSync(appFilePath, appTsx, 'utf-8');
128
148
  // Create AppLayout.tsx
129
149
  const appLayoutTsx = `import React from 'react'
130
150
  import { Slot } from '@slotkitjs/react'
@@ -225,38 +245,8 @@ export const AppLayout: React.FC = () => {
225
245
  }
226
246
  `;
227
247
  writeFileSync(join(appDir, 'AppLayout.css'), appLayoutCss, 'utf-8');
228
- // Update main.tsx or main.ts to use SlotKit App
229
- // Check for both .tsx and .ts extensions, and rename .ts to .tsx if needed
230
- const mainTsxPath = join(projectDir, 'src', 'main.tsx');
231
- const mainTsPath = join(projectDir, 'src', 'main.ts');
232
- let mainPath = mainTsxPath;
233
- if (existsSync(mainTsPath)) {
234
- // If main.ts exists, we need to rename it to .tsx since it will contain JSX
235
- // But first check if main.tsx already exists
236
- if (!existsSync(mainTsxPath)) {
237
- // Rename main.ts to main.tsx
238
- const mainTsContent = readFileSync(mainTsPath, 'utf-8');
239
- writeFileSync(mainTsxPath, mainTsContent, 'utf-8');
240
- // Delete the old main.ts
241
- unlinkSync(mainTsPath);
242
- }
243
- mainPath = mainTsxPath;
244
- }
245
- if (existsSync(mainPath)) {
246
- // Update existing main file
247
- const mainContent = `import React from 'react'
248
- import ReactDOM from 'react-dom/client'
249
- import { App } from './app/App'
250
- import './style.css'
251
-
252
- ReactDOM.createRoot(document.getElementById('root')!).render(
253
- <React.StrictMode>
254
- <App />
255
- </React.StrictMode>,
256
- )
257
- `;
258
- writeFileSync(mainPath, mainContent, 'utf-8');
259
- }
248
+ // No need to modify main.tsx - Vite's default already imports './App'
249
+ // We replaced src/App.tsx above, so it will automatically work
260
250
  // Create slotkit.config.ts
261
251
  const slotkitConfig = `import { defineConfig } from '@slotkitjs/core'
262
252
 
@@ -368,10 +358,13 @@ program
368
358
  packageJson.dependencies = {};
369
359
  }
370
360
  // Add SlotKit dependencies (merge with existing)
361
+ // Use latest versions
362
+ const slotkitCoreVersion = getLatestVersion('@slotkitjs/core');
363
+ const slotkitReactVersion = getLatestVersion('@slotkitjs/react');
371
364
  packageJson.dependencies = {
372
365
  ...packageJson.dependencies,
373
- '@slotkitjs/core': '^0.1.0',
374
- '@slotkitjs/react': '^0.1.0'
366
+ '@slotkitjs/core': slotkitCoreVersion,
367
+ '@slotkitjs/react': slotkitReactVersion
375
368
  };
376
369
  // Ensure React dependencies are present (for React templates)
377
370
  if (options.template?.includes('react')) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-slotkit-app",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "description": "Create a new SlotKit application",
6
6
  "bin": {