@zappdev/cli 0.5.0-alpha.5 → 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 +4 -1
- package/src/init.ts +45 -7
package/package.json
CHANGED
package/src/init.ts
CHANGED
|
@@ -102,13 +102,15 @@ fn main() -> int {
|
|
|
102
102
|
}
|
|
103
103
|
`);
|
|
104
104
|
|
|
105
|
-
// 3. Add zapp.config.ts
|
|
105
|
+
// 3. Add zapp.config.ts — typed via defineConfig for autocomplete
|
|
106
106
|
const identifier = `com.zapp.${name.toLowerCase().replace(/[^a-z0-9]/g, "")}`;
|
|
107
|
-
await Bun.write(path.join(projectDir, "zapp.config.ts"), `
|
|
107
|
+
await Bun.write(path.join(projectDir, "zapp.config.ts"), `import { defineConfig } from "@zappdev/cli/config";
|
|
108
|
+
|
|
109
|
+
export default defineConfig({
|
|
108
110
|
name: "${name}",
|
|
109
111
|
identifier: "${identifier}",
|
|
110
112
|
version: "0.1.0",
|
|
111
|
-
};
|
|
113
|
+
});
|
|
112
114
|
`);
|
|
113
115
|
|
|
114
116
|
// 4. Update package.json — add deps and scripts
|
|
@@ -135,16 +137,52 @@ fn main() -> int {
|
|
|
135
137
|
|
|
136
138
|
await Bun.write(pkgPath, JSON.stringify(pkgObj, null, 2));
|
|
137
139
|
|
|
138
|
-
// 5.
|
|
139
|
-
//
|
|
140
|
-
//
|
|
141
|
-
|
|
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";
|
|
142
179
|
import { zappWorkers } from "@zappdev/vite";
|
|
143
180
|
|
|
144
181
|
export default defineConfig({
|
|
145
182
|
plugins: [zappWorkers()],
|
|
146
183
|
});
|
|
147
184
|
`);
|
|
185
|
+
}
|
|
148
186
|
|
|
149
187
|
// 6. Add .zapp/ to .gitignore
|
|
150
188
|
const gitignorePath = path.join(projectDir, ".gitignore");
|