Skip to content

Commit

Permalink
Fix error in init scaffolding (#537)
Browse files Browse the repository at this point in the history
* 🐛 FIX: file name & content

* ✏️ NEW: changset
  • Loading branch information
jycouet authored Sep 12, 2022
1 parent 68f1fd6 commit 191c775
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/red-jokes-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'houdini': patch
---

fix - init cmd, vite.config.ts generated file
87 changes: 69 additions & 18 deletions src/cmd/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
`

Expand All @@ -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';
Expand Down

2 comments on commit 191c775

@vercel
Copy link

@vercel vercel bot commented on 191c775 Sep 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 191c775 Sep 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs-next – ./site

docs-next-houdinigraphql.vercel.app
docs-next-kohl.vercel.app
docs-next-git-main-houdinigraphql.vercel.app

Please sign in to comment.