Skip to content

Commit

Permalink
Update init templates (#620)
Browse files Browse the repository at this point in the history
* better error message

* init api url

* make sure api response can be parsed as json before continuing

* changeset
  • Loading branch information
AlecAivazis authored Oct 21, 2022
1 parent 6c69ff8 commit b742d75
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .changeset/young-beans-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'houdini': patch
'houdini-svelte': patch
---

update templates
10 changes: 2 additions & 8 deletions packages/houdini-svelte/src/plugin/fsPatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,12 @@ filesystem.statSync = function (filepath: string, options: Parameters<filesystem

// we want to fake +layout.js if there is a +layout.svelte
else if (filepath.endsWith('+layout.js')) {
try {
_statSync(filepath.replace('+layout.js', '+layout.svelte'))
return mock
} catch (e) {}
return mock
}

// we want to fake +page.js if there is a +page.svelte
else if (filepath.endsWith('+page.js')) {
try {
_statSync(filepath.replace('+page.js', '+page.svelte'))
return mock
} catch (e) {}
return mock
}

// if we got this far we didn't fake the file
Expand Down
14 changes: 13 additions & 1 deletion packages/houdini/src/cmd/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ export default async function init(
args: { headers?: string[]; yes: boolean },
withRunningCheck = true
): Promise<void> {
// before we start anything, let's make sure they have initialized their project
try {
await fs.stat(path.resolve('./src'))
} catch {
throw new Error(
'Please initialize your project first before running init. For svelte projects, you should follow the instructions here: https://kit.svelte.dev/'
)
}

let headers = {}
if ((args.headers ?? []).length > 0) {
headers = args.headers!.reduce((total, header) => {
Expand Down Expand Up @@ -48,7 +57,7 @@ export default async function init(
message: "What's the URL for your api?",
name: 'url',
type: 'text',
initial: 'http://localhost:4000/api/graphql',
initial: 'http://localhost:4000/graphql',
},
{
onCancel() {
Expand All @@ -75,6 +84,9 @@ export default async function init(
console.log('❌ That URL is not accepting GraphQL queries. Please try again.')
return await init(_path, args, false)
}

// make sure we can parse the response as json
await response.json()
} catch (e) {
console.log('❌ Something went wrong: ' + (e as Error).message)
return await init(_path, args, false)
Expand Down
5 changes: 2 additions & 3 deletions packages/houdini/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,9 +775,8 @@ export async function getConfig({
// if there is a framework specified, tell them they need to change things
if (!configFile.plugins) {
throw new HoudiniError({
message: 'framework config value has been removed.',
description:
'Please visit the release notes here: http://www.houdinigraphql.com/guide/release-notes#0170',
message:
'Welcome to 0.17.0! Please following the migration guide here: http://www.houdinigraphql.com/guide/release-notes#0170',
})
}

Expand Down

1 comment on commit b742d75

@vercel
Copy link

@vercel vercel bot commented on b742d75 Oct 21, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.