Skip to content

Commit 60e2dcd

Browse files
committed
feat: tauri integration
1 parent 263396e commit 60e2dcd

2 files changed

Lines changed: 62 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ A custom-built CLI for creating and managing SolidJS apps and projects.
2929
- [x] UnoCSS
3030
- [ ] Vanilla Extract
3131
- [x] Vitest
32-
- [ ] Tauri
32+
- [x] Tauri
3333
- [ ] Playwright
3434
- [ ] Utilities
3535
- [ ] eslint-plugin-solid

packages/commands/src/lib/integrations.ts

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,14 @@ export const integrations: Record<string, IntegrationsValue> = {
125125
p.log.info("Adding test script to package.json");
126126
const packageJsonString = await readFile("package.json", "utf8");
127127
const packageJson = JSON.parse(packageJsonString);
128+
if (!packageJson.scripts) { packageJson.scripts = {}; }
128129
if (!/\bvitest\b/.test(packageJson.scripts.test || "")) {
129130
packageJson.scripts.test = "vitest";
130-
await writeFile("package.json", JSON.stringify(packageJson, null, 2) + "\n", "utf8");
131+
await writeFile(
132+
"package.json",
133+
JSON.stringify(packageJson, null, /^(\t|\s+)/m.exec(packageJsonString)?.[0] || 2) + "\n",
134+
"utf8"
135+
);
131136
}
132137
const hasTs = fileExists("tsconfig.json");
133138
if (hasTs) {
@@ -140,7 +145,11 @@ export const integrations: Record<string, IntegrationsValue> = {
140145
tsConfig.compilerOptions.types = [
141146
...new Set([...(tsConfig.compilerOptions.types || []), "vite/client", "@testing-library/jest-dom"]),
142147
];
143-
await writeFile("tsconfig.json", JSON.stringify(tsConfig, null, 2) + "\n", "utf8");
148+
await writeFile(
149+
"tsconfig.json",
150+
JSON.stringify(tsConfig, null, /^(\t|\s+)/m.exec(tsConfigString)?.[0] || 2) + "\n",
151+
"utf8"
152+
);
144153
}
145154
if (
146155
packageJson.dependencies["@solidjs/start"] &&
@@ -170,4 +179,54 @@ export default defineConfig({
170179
}
171180
},
172181
},
182+
"tauri-v1.x": {
183+
installs: ["@tauri-apps/cli"],
184+
postInstall: async () => {
185+
try {
186+
const packageJsonString = await readFile("package.json", "utf8");
187+
const packageJson = JSON.parse(packageJsonString);
188+
if (!packageJson.scripts) { packageJson.scripts = {}; }
189+
packageJson.scripts.tauri = "tauri";
190+
await writeFile(
191+
"package.json",
192+
JSON.stringify(packageJson, null, /^(\t|\s+)/m.exec(packageJsonString)?.[0] || 2) + "\n",
193+
"utf8"
194+
);
195+
await flushQueue();
196+
const name = packageJson.name;
197+
const pM = detectPackageManager();
198+
await $`${getRunnerCommand(pM)} tauri init --ci -A ${name} -W ${name} -D ../dist -P http://localhost:3000`;
199+
p.outro(`Make sure you have installed all prerequisites: https://tauri.app/v1/guides/getting-started/prerequisites
200+
201+
Start tauri development with ${color.bold(pM.name)} ${color.bold(pM.runScriptCommand("tauri dev"))}`);
202+
} catch (err) {
203+
console.error(err);
204+
}
205+
},
206+
},
207+
"tauri-v2.x": {
208+
installs: ["@tauri-apps/cli@next"],
209+
postInstall: async () => {
210+
try {
211+
const packageJsonString = await readFile("package.json", "utf8");
212+
const packageJson = JSON.parse(packageJsonString);
213+
if (!packageJson.scripts) { packageJson.scripts = {}; }
214+
packageJson.scripts.tauri = "tauri";
215+
await writeFile(
216+
"package.json",
217+
JSON.stringify(packageJson, null, /^(\t|\s+)/m.exec(packageJsonString)?.[0] || 2) + "\n",
218+
"utf8"
219+
);
220+
await flushQueue();
221+
const name = packageJson.name;
222+
const pM = detectPackageManager();
223+
await $`${getRunnerCommand(pM)} tauri init --ci -A ${name} -W ${name} -D ../dist -P http://localhost:3000`;
224+
p.outro(`Make sure you have installed all prerequisites: https://v2.tauri.app/start/prerequisites/
225+
226+
Start tauri development with ${color.bold(pM.name)} ${color.bold(pM.runScriptCommand("tauri dev"))}`);
227+
} catch (err) {
228+
console.error(err);
229+
}
230+
},
231+
},
173232
};

0 commit comments

Comments
 (0)