@zappdev/cli 0.5.0-alpha.6 → 0.5.0-alpha.7
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/package.json +1 -1
- package/src/init.ts +40 -4
package/package.json
CHANGED
package/src/init.ts
CHANGED
|
@@ -137,16 +137,52 @@ export default defineConfig({
|
|
|
137
137
|
|
|
138
138
|
await Bun.write(pkgPath, JSON.stringify(pkgObj, null, 2));
|
|
139
139
|
|
|
140
|
-
// 5.
|
|
141
|
-
//
|
|
142
|
-
//
|
|
143
|
-
|
|
140
|
+
// 5. Inject zappWorkers() into the template's vite.config.ts
|
|
141
|
+
// Templates like svelte-ts ship their own vite.config.ts with framework
|
|
142
|
+
// plugins (e.g. svelte()). We must preserve those and append ours.
|
|
143
|
+
const viteConfigPath = path.join(projectDir, "vite.config.ts");
|
|
144
|
+
// Also check .js — some templates use vite.config.js
|
|
145
|
+
const viteConfigJsPath = path.join(projectDir, "vite.config.js");
|
|
146
|
+
const configPath = existsSync(viteConfigPath) ? viteConfigPath
|
|
147
|
+
: existsSync(viteConfigJsPath) ? viteConfigJsPath
|
|
148
|
+
: null;
|
|
149
|
+
|
|
150
|
+
if (configPath) {
|
|
151
|
+
let viteConfig = await Bun.file(configPath).text();
|
|
152
|
+
|
|
153
|
+
// Add our import at the top (after existing imports)
|
|
154
|
+
const importLine = `import { zappWorkers } from "@zappdev/vite";\n`;
|
|
155
|
+
if (!viteConfig.includes("@zappdev/vite")) {
|
|
156
|
+
// Insert after the last import statement
|
|
157
|
+
const lastImportIdx = viteConfig.lastIndexOf("\nimport ");
|
|
158
|
+
if (lastImportIdx >= 0) {
|
|
159
|
+
const endOfLine = viteConfig.indexOf("\n", lastImportIdx + 1);
|
|
160
|
+
viteConfig = viteConfig.slice(0, endOfLine + 1) + importLine + viteConfig.slice(endOfLine + 1);
|
|
161
|
+
} else {
|
|
162
|
+
viteConfig = importLine + viteConfig;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Append zappWorkers() to the plugins array
|
|
167
|
+
if (!viteConfig.includes("zappWorkers()")) {
|
|
168
|
+
// Match plugins: [...] and append inside the array
|
|
169
|
+
viteConfig = viteConfig.replace(
|
|
170
|
+
/plugins:\s*\[/,
|
|
171
|
+
"plugins: [zappWorkers(), "
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
await Bun.write(configPath, viteConfig);
|
|
176
|
+
} else {
|
|
177
|
+
// No vite.config found — create a minimal one
|
|
178
|
+
await Bun.write(viteConfigPath, `import { defineConfig } from "vite";
|
|
144
179
|
import { zappWorkers } from "@zappdev/vite";
|
|
145
180
|
|
|
146
181
|
export default defineConfig({
|
|
147
182
|
plugins: [zappWorkers()],
|
|
148
183
|
});
|
|
149
184
|
`);
|
|
185
|
+
}
|
|
150
186
|
|
|
151
187
|
// 6. Add .zapp/ to .gitignore
|
|
152
188
|
const gitignorePath = path.join(projectDir, ".gitignore");
|