Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 FIX: file name & content #537

Merged
merged 2 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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