From 191c7750a33b11cdbc8f5e7b9719641d5b0a21c5 Mon Sep 17 00:00:00 2001 From: JYC Date: Mon, 12 Sep 2022 18:27:21 +0200 Subject: [PATCH] Fix error in init scaffolding (#537) * :bug: FIX: file name & content * :pencil2: NEW: changset --- .changeset/red-jokes-invent.md | 5 ++ src/cmd/init.ts | 87 +++++++++++++++++++++++++++------- 2 files changed, 74 insertions(+), 18 deletions(-) create mode 100644 .changeset/red-jokes-invent.md diff --git a/.changeset/red-jokes-invent.md b/.changeset/red-jokes-invent.md new file mode 100644 index 0000000000..6efba2e469 --- /dev/null +++ b/.changeset/red-jokes-invent.md @@ -0,0 +1,5 @@ +--- +'houdini': patch +--- + +fix - init cmd, vite.config.ts generated file diff --git a/src/cmd/init.ts b/src/cmd/init.ts index 900dc3a3a7..0fc1794920 100644 --- a/src/cmd/init.ts +++ b/src/cmd/init.ts @@ -305,7 +305,7 @@ async function updateViteConfig( framework: 'kit' | 'svelte', typescript: boolean ) { - const viteConfigPath = path.join(targetPath, 'vite.config' + typescript ? '.ts' : '.js') + const viteConfigPath = path.join(targetPath, `vite.config${typescript ? '.ts' : '.js'}`) const oldViteConfig1 = `import { sveltekit } from '@sveltejs/kit/vite'; @@ -336,6 +336,17 @@ const config = { plugins: [houdini(), sveltekit()], } +export default config; +` + + const viteConfigKitTs = `import { sveltekit } from '@sveltejs/kit/vite'; +import houdini from 'houdini/vite'; +import type { UserConfig } from "vite"; + +const config: UserConfig = { + plugins: [houdini(), sveltekit()], +} + export default config; ` @@ -350,36 +361,76 @@ const config = { export default config; ` + const viteConfigSvelteTs = `import { svelte } from '@sveltejs/vite-plugin-svelte'; +import houdini from 'houdini/vite'; +import type { UserConfig } from "vite"; + +const config: UserConfig = { + plugins: [houdini(), svelte()], +} + +export default config; +` + + let content = 'NOTHING!' + if (framework === 'kit' && typescript) { + content = viteConfigKitTs + } else if (framework === 'kit' && !typescript) { + content = viteConfigKit + } else if (framework === 'svelte' && typescript) { + content = viteConfigSvelteTs + } else if (framework === 'svelte' && !typescript) { + content = viteConfigSvelte + } else { + throw new Error('Unknown updateViteConfig()') + } + // write the vite config file await updateFile({ projectPath: targetPath, filepath: viteConfigPath, - content: framework === 'kit' ? viteConfigKit : viteConfigSvelte, + content, old: [oldViteConfig1, oldViteConfig2], }) + + if (typescript) { + await updateFile({ + projectPath: targetPath, + filepath: viteConfigPath, + content: framework === 'kit' ? viteConfigKitTs : viteConfigSvelteTs, + old: [oldViteConfig1, oldViteConfig2], + }) + } else { + await updateFile({ + projectPath: targetPath, + filepath: viteConfigPath, + content: framework === 'kit' ? viteConfigKit : viteConfigSvelte, + old: [oldViteConfig1, oldViteConfig2], + }) + } } async function updateSvelteConfig(targetPath: string) { const svelteConfigPath = path.join(targetPath, 'svelte.config.js') const newContent = `import adapter from '@sveltejs/adapter-auto'; - import preprocess from 'svelte-preprocess'; - - /** @type {import('@sveltejs/kit').Config} */ - const config = { - // Consult https://github.com/sveltejs/svelte-preprocess - // for more information about preprocessors - preprocess: preprocess(), - - kit: { - adapter: adapter(), - alias: { - $houdini: './$houdini', - } +import preprocess from 'svelte-preprocess'; + +/** @type {import('@sveltejs/kit').Config} */ +const config = { + // Consult https://github.com/sveltejs/svelte-preprocess + // for more information about preprocessors + preprocess: preprocess(), + + kit: { + adapter: adapter(), + alias: { + $houdini: './$houdini', } - }; - - export default config; + } +}; + +export default config; ` const oldSvelteConfig1 = `import adapter from '@sveltejs/adapter-auto';