create-slotkit-app 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +10 -37
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { Command } from 'commander';
|
|
6
6
|
import { spawn } from 'child_process';
|
|
7
|
-
import { existsSync, readFileSync, writeFileSync, mkdirSync
|
|
7
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
|
|
8
8
|
import { resolve, join } from 'path';
|
|
9
9
|
const program = new Command();
|
|
10
10
|
/**
|
|
@@ -32,12 +32,15 @@ function execCommand(command, args, cwd) {
|
|
|
32
32
|
* Create SlotKit-specific files
|
|
33
33
|
*/
|
|
34
34
|
function createSlotKitFiles(projectDir) {
|
|
35
|
-
//
|
|
35
|
+
// Replace Vite's default App.tsx with SlotKit App
|
|
36
|
+
// This way we don't need to modify main.tsx
|
|
37
|
+
const appFilePath = join(projectDir, 'src', 'App.tsx');
|
|
38
|
+
// Create src/app directory for AppLayout
|
|
36
39
|
const appDir = join(projectDir, 'src', 'app');
|
|
37
40
|
mkdirSync(appDir, { recursive: true });
|
|
38
|
-
// Create App.tsx
|
|
41
|
+
// Create App.tsx (replaces Vite's default)
|
|
39
42
|
const appTsx = `import React, { useEffect, useState } from 'react'
|
|
40
|
-
import { AppLayout } from './AppLayout'
|
|
43
|
+
import { AppLayout } from './app/AppLayout'
|
|
41
44
|
import { pluginRegistry, pluginLoader } from '@slotkitjs/core'
|
|
42
45
|
|
|
43
46
|
/**
|
|
@@ -124,7 +127,7 @@ export const App: React.FC = () => {
|
|
|
124
127
|
)
|
|
125
128
|
}
|
|
126
129
|
`;
|
|
127
|
-
writeFileSync(
|
|
130
|
+
writeFileSync(appFilePath, appTsx, 'utf-8');
|
|
128
131
|
// Create AppLayout.tsx
|
|
129
132
|
const appLayoutTsx = `import React from 'react'
|
|
130
133
|
import { Slot } from '@slotkitjs/react'
|
|
@@ -225,38 +228,8 @@ export const AppLayout: React.FC = () => {
|
|
|
225
228
|
}
|
|
226
229
|
`;
|
|
227
230
|
writeFileSync(join(appDir, 'AppLayout.css'), appLayoutCss, 'utf-8');
|
|
228
|
-
//
|
|
229
|
-
//
|
|
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
|
-
}
|
|
231
|
+
// No need to modify main.tsx - Vite's default already imports './App'
|
|
232
|
+
// We replaced src/App.tsx above, so it will automatically work
|
|
260
233
|
// Create slotkit.config.ts
|
|
261
234
|
const slotkitConfig = `import { defineConfig } from '@slotkitjs/core'
|
|
262
235
|
|