houdini 0.17.9 → 0.17.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/build/cmd-cjs/index.js +2 -2
- package/build/cmd-esm/index.js +2 -2
- package/package.json +16 -1
- package/.turbo/turbo-compile.log +0 -5
- package/.turbo/turbo-typedefs.log +0 -5
- package/CHANGELOG.md +0 -377
- package/src/cmd/generate.ts +0 -54
- package/src/cmd/index.ts +0 -60
- package/src/cmd/init.ts +0 -637
- package/src/cmd/pullSchema.ts +0 -40
- package/src/codegen/generators/artifacts/artifacts.test.ts +0 -3246
- package/src/codegen/generators/artifacts/fieldKey.ts +0 -60
- package/src/codegen/generators/artifacts/index.ts +0 -330
- package/src/codegen/generators/artifacts/indexFile.ts +0 -24
- package/src/codegen/generators/artifacts/inputs.ts +0 -81
- package/src/codegen/generators/artifacts/operations.ts +0 -281
- package/src/codegen/generators/artifacts/pagination.test.ts +0 -664
- package/src/codegen/generators/artifacts/policy.test.ts +0 -298
- package/src/codegen/generators/artifacts/selection.ts +0 -208
- package/src/codegen/generators/artifacts/utils.test.ts +0 -118
- package/src/codegen/generators/artifacts/utils.ts +0 -108
- package/src/codegen/generators/definitions/enums.test.ts +0 -61
- package/src/codegen/generators/definitions/enums.ts +0 -68
- package/src/codegen/generators/definitions/index.ts +0 -11
- package/src/codegen/generators/definitions/schema.test.ts +0 -236
- package/src/codegen/generators/index.ts +0 -6
- package/src/codegen/generators/indexFile/index.ts +0 -63
- package/src/codegen/generators/indexFile/indexFile.test.ts +0 -72
- package/src/codegen/generators/persistedQueries/index.ts +0 -55
- package/src/codegen/generators/persistedQueries/persistedQuery.test.ts +0 -26
- package/src/codegen/generators/runtime/index.test.ts +0 -74
- package/src/codegen/generators/runtime/index.ts +0 -64
- package/src/codegen/generators/runtime/runtime.test.ts +0 -25
- package/src/codegen/generators/typescript/addReferencedInputTypes.ts +0 -77
- package/src/codegen/generators/typescript/index.ts +0 -412
- package/src/codegen/generators/typescript/inlineType.ts +0 -409
- package/src/codegen/generators/typescript/typeReference.ts +0 -44
- package/src/codegen/generators/typescript/types.ts +0 -81
- package/src/codegen/generators/typescript/typescript.test.ts +0 -1434
- package/src/codegen/index.ts +0 -406
- package/src/codegen/transforms/addID.test.ts +0 -93
- package/src/codegen/transforms/addID.ts +0 -86
- package/src/codegen/transforms/composeQueries.test.ts +0 -50
- package/src/codegen/transforms/composeQueries.ts +0 -154
- package/src/codegen/transforms/fragmentVariables.test.ts +0 -636
- package/src/codegen/transforms/fragmentVariables.ts +0 -417
- package/src/codegen/transforms/index.ts +0 -7
- package/src/codegen/transforms/list.ts +0 -484
- package/src/codegen/transforms/lists.test.ts +0 -530
- package/src/codegen/transforms/paginate.test.ts +0 -1528
- package/src/codegen/transforms/paginate.ts +0 -770
- package/src/codegen/transforms/schema.test.ts +0 -136
- package/src/codegen/transforms/schema.ts +0 -109
- package/src/codegen/transforms/typename.test.ts +0 -125
- package/src/codegen/transforms/typename.ts +0 -55
- package/src/codegen/utils/commonjs.ts +0 -26
- package/src/codegen/utils/flattenSelections.ts +0 -179
- package/src/codegen/utils/graphql.test.ts +0 -35
- package/src/codegen/utils/graphql.ts +0 -79
- package/src/codegen/utils/index.ts +0 -5
- package/src/codegen/utils/moduleExport.ts +0 -27
- package/src/codegen/utils/murmur.ts +0 -79
- package/src/codegen/validators/index.ts +0 -4
- package/src/codegen/validators/noIDAlias.test.ts +0 -71
- package/src/codegen/validators/noIDAlias.ts +0 -39
- package/src/codegen/validators/plugins.ts +0 -25
- package/src/codegen/validators/typeCheck.test.ts +0 -960
- package/src/codegen/validators/typeCheck.ts +0 -1086
- package/src/codegen/validators/uniqueNames.test.ts +0 -59
- package/src/codegen/validators/uniqueNames.ts +0 -39
- package/src/lib/cleanupFiles.ts +0 -20
- package/src/lib/config.test.ts +0 -13
- package/src/lib/config.ts +0 -954
- package/src/lib/constants.ts +0 -11
- package/src/lib/error.ts +0 -24
- package/src/lib/fs.ts +0 -285
- package/src/lib/graphql.test.ts +0 -211
- package/src/lib/graphql.ts +0 -200
- package/src/lib/imports.ts +0 -82
- package/src/lib/index.ts +0 -17
- package/src/lib/introspection.ts +0 -39
- package/src/lib/parse.test.ts +0 -75
- package/src/lib/parse.ts +0 -23
- package/src/lib/path.ts +0 -49
- package/src/lib/pipeline.ts +0 -17
- package/src/lib/types.ts +0 -34
- package/src/lib/walk.ts +0 -104
- package/src/runtime/cache/cache.ts +0 -1026
- package/src/runtime/cache/gc.ts +0 -56
- package/src/runtime/cache/index.ts +0 -3
- package/src/runtime/cache/lists.ts +0 -516
- package/src/runtime/cache/storage.ts +0 -574
- package/src/runtime/cache/stuff.ts +0 -77
- package/src/runtime/cache/subscription.ts +0 -329
- package/src/runtime/cache/tests/availability.test.ts +0 -408
- package/src/runtime/cache/tests/gc.test.ts +0 -319
- package/src/runtime/cache/tests/keys.test.ts +0 -36
- package/src/runtime/cache/tests/list.test.ts +0 -3854
- package/src/runtime/cache/tests/readwrite.test.ts +0 -1201
- package/src/runtime/cache/tests/scalars.test.ts +0 -218
- package/src/runtime/cache/tests/storage.test.ts +0 -426
- package/src/runtime/cache/tests/subscriptions.test.ts +0 -1757
- package/src/runtime/index.ts +0 -29
- package/src/runtime/lib/config.ts +0 -211
- package/src/runtime/lib/constants.ts +0 -17
- package/src/runtime/lib/deepEquals.ts +0 -32
- package/src/runtime/lib/errors.ts +0 -8
- package/src/runtime/lib/index.ts +0 -8
- package/src/runtime/lib/log.ts +0 -69
- package/src/runtime/lib/network.ts +0 -303
- package/src/runtime/lib/networkUtils.ts +0 -151
- package/src/runtime/lib/scalars.test.ts +0 -877
- package/src/runtime/lib/scalars.ts +0 -195
- package/src/runtime/lib/types.ts +0 -195
- package/src/test/index.ts +0 -294
- package/src/vite/ast.ts +0 -107
- package/src/vite/houdini.ts +0 -113
- package/src/vite/imports.ts +0 -129
- package/src/vite/index.ts +0 -55
- package/src/vite/schema.ts +0 -80
package/src/cmd/init.ts
DELETED
|
@@ -1,637 +0,0 @@
|
|
|
1
|
-
import { logGreen } from '@kitql/helper'
|
|
2
|
-
import { execSync } from 'child_process'
|
|
3
|
-
import { getIntrospectionQuery } from 'graphql'
|
|
4
|
-
import fetch from 'node-fetch'
|
|
5
|
-
import prompts from 'prompts'
|
|
6
|
-
|
|
7
|
-
import { fs, parseJSON, path, pullSchema } from '../lib'
|
|
8
|
-
import { ConfigFile } from '../runtime/lib/config'
|
|
9
|
-
|
|
10
|
-
// the init command is responsible for scaffolding a few files
|
|
11
|
-
// as well as pulling down the initial schema representation
|
|
12
|
-
export default async function init(
|
|
13
|
-
_path: string | undefined,
|
|
14
|
-
args: { headers?: string[]; force_remote_endpoint?: boolean }
|
|
15
|
-
): Promise<void> {
|
|
16
|
-
const force_remote_endpoint = args.force_remote_endpoint || false
|
|
17
|
-
|
|
18
|
-
// before we start anything, let's make sure they have initialized their project
|
|
19
|
-
try {
|
|
20
|
-
await fs.stat(path.resolve('./src'))
|
|
21
|
-
} catch {
|
|
22
|
-
throw new Error(
|
|
23
|
-
'Please initialize your project first before running init. For svelte projects, you should follow the instructions here: https://kit.svelte.dev/'
|
|
24
|
-
)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
let headers = {}
|
|
28
|
-
if ((args.headers ?? []).length > 0) {
|
|
29
|
-
headers = args.headers!.reduce((total, header) => {
|
|
30
|
-
const [key, value] = header.split('=')
|
|
31
|
-
return {
|
|
32
|
-
...total,
|
|
33
|
-
[key]: value,
|
|
34
|
-
}
|
|
35
|
-
}, {})
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// if no path was given, we 'll use cwd
|
|
39
|
-
const targetPath = _path ? path.resolve(_path) : process.cwd()
|
|
40
|
-
|
|
41
|
-
// git check
|
|
42
|
-
if (!force_remote_endpoint) {
|
|
43
|
-
// from https://github.com/sveltejs/kit/blob/master/packages/migrate/migrations/routes/index.js#L60
|
|
44
|
-
let use_git = false
|
|
45
|
-
|
|
46
|
-
let dir = targetPath
|
|
47
|
-
do {
|
|
48
|
-
if (fs.existsSync(path.join(dir, '.git'))) {
|
|
49
|
-
use_git = true
|
|
50
|
-
break
|
|
51
|
-
}
|
|
52
|
-
} while (dir !== (dir = path.dirname(dir)))
|
|
53
|
-
|
|
54
|
-
if (use_git) {
|
|
55
|
-
const status = execSync('git status --porcelain', { stdio: 'pipe' }).toString()
|
|
56
|
-
|
|
57
|
-
if (status) {
|
|
58
|
-
const message =
|
|
59
|
-
'Your git working directory is dirty — we recommend committing your changes before running this migration.\n'
|
|
60
|
-
console.error(message)
|
|
61
|
-
|
|
62
|
-
const { confirm } = await prompts({
|
|
63
|
-
message: 'Continue anyway?',
|
|
64
|
-
name: 'confirm',
|
|
65
|
-
type: 'confirm',
|
|
66
|
-
initial: false,
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
if (!confirm) {
|
|
70
|
-
process.exit(1)
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Questions...
|
|
77
|
-
let url = 'http://localhost:5173/api/graphql'
|
|
78
|
-
const { is_remote_endpoint } = force_remote_endpoint
|
|
79
|
-
? { is_remote_endpoint: true }
|
|
80
|
-
: await prompts(
|
|
81
|
-
{
|
|
82
|
-
message: 'Will you use a remote GraphQL API?',
|
|
83
|
-
name: 'is_remote_endpoint',
|
|
84
|
-
type: 'confirm',
|
|
85
|
-
initial: true,
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
onCancel() {
|
|
89
|
-
process.exit(1)
|
|
90
|
-
},
|
|
91
|
-
}
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
let schemaPath = is_remote_endpoint ? './schema.graphql' : 'path/to/src/lib/**/*.graphql'
|
|
95
|
-
|
|
96
|
-
if (is_remote_endpoint) {
|
|
97
|
-
const { url_remote } = await prompts(
|
|
98
|
-
{
|
|
99
|
-
message: "What's the URL for your api?",
|
|
100
|
-
name: 'url_remote',
|
|
101
|
-
type: 'text',
|
|
102
|
-
initial: 'http://localhost:4000/graphql',
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
onCancel() {
|
|
106
|
-
process.exit(1)
|
|
107
|
-
},
|
|
108
|
-
}
|
|
109
|
-
)
|
|
110
|
-
|
|
111
|
-
// set the url for later
|
|
112
|
-
url = url_remote
|
|
113
|
-
try {
|
|
114
|
-
// verify we can send graphql queries to the server
|
|
115
|
-
const response = await fetch(url, {
|
|
116
|
-
method: 'POST',
|
|
117
|
-
headers: {
|
|
118
|
-
'Content-Type': 'application/json',
|
|
119
|
-
...headers,
|
|
120
|
-
},
|
|
121
|
-
body: JSON.stringify({
|
|
122
|
-
query: getIntrospectionQuery(),
|
|
123
|
-
}),
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
// if the response was not a 200, we have a problem
|
|
127
|
-
if (response.status !== 200) {
|
|
128
|
-
console.log('❌ That URL is not accepting GraphQL queries. Please try again.')
|
|
129
|
-
return await init(_path, { ...args, force_remote_endpoint: true })
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// make sure we can parse the response as json
|
|
133
|
-
await response.json()
|
|
134
|
-
} catch (e) {
|
|
135
|
-
console.log('❌ Something went wrong: ' + (e as Error).message)
|
|
136
|
-
return await init(_path, { ...args, force_remote_endpoint: true })
|
|
137
|
-
}
|
|
138
|
-
} else {
|
|
139
|
-
// the schema is local so ask them for the path
|
|
140
|
-
const answers = await prompts(
|
|
141
|
-
{
|
|
142
|
-
message: 'Where is your schema located?',
|
|
143
|
-
name: 'schema_path',
|
|
144
|
-
type: 'text',
|
|
145
|
-
initial: schemaPath,
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
onCancel() {
|
|
149
|
-
process.exit(1)
|
|
150
|
-
},
|
|
151
|
-
}
|
|
152
|
-
)
|
|
153
|
-
|
|
154
|
-
schemaPath = answers.schema_path
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// try to detect which tools they are using
|
|
158
|
-
const { framework, typescript, module, package_manager } = await detectTools(targetPath)
|
|
159
|
-
|
|
160
|
-
// notify the users of what we detected
|
|
161
|
-
console.log()
|
|
162
|
-
console.log("🔎 Here's what we found:")
|
|
163
|
-
|
|
164
|
-
// framework
|
|
165
|
-
if (framework === 'kit') {
|
|
166
|
-
console.log('✨ SvelteKit')
|
|
167
|
-
} else {
|
|
168
|
-
console.log('✨ Svelte')
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// module
|
|
172
|
-
if (module === 'esm') {
|
|
173
|
-
console.log('📦 ES Modules')
|
|
174
|
-
} else {
|
|
175
|
-
console.log('📦 CommonJS')
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// typescript
|
|
179
|
-
if (typescript) {
|
|
180
|
-
console.log('🟦 TypeScript')
|
|
181
|
-
} else {
|
|
182
|
-
console.log('🟨 JavaScript')
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// put some space between discoveries and errors
|
|
186
|
-
console.log()
|
|
187
|
-
|
|
188
|
-
if (framework === 'sapper') {
|
|
189
|
-
console.log(
|
|
190
|
-
'❌ Sorry, Houdini no longer supports Sapper. Please downgrade to v0.15.x or migrate to SvelteKit.'
|
|
191
|
-
)
|
|
192
|
-
process.exit(1)
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// the source directory
|
|
196
|
-
const sourceDir = path.join(targetPath, 'src')
|
|
197
|
-
// the config file path
|
|
198
|
-
const configPath = path.join(targetPath, 'houdini.config.js')
|
|
199
|
-
// where we put the houdiniClient
|
|
200
|
-
const houdiniClientPath = typescript
|
|
201
|
-
? path.join(sourceDir, 'client.ts')
|
|
202
|
-
: path.join(sourceDir, 'client.js')
|
|
203
|
-
// houdini client import path
|
|
204
|
-
const houdiniClientImport = './src/client'
|
|
205
|
-
|
|
206
|
-
console.log('🚧 Generating project files...')
|
|
207
|
-
|
|
208
|
-
await updatePackageJSON(targetPath)
|
|
209
|
-
|
|
210
|
-
// let's pull the schema only when we are using a remote endpoint
|
|
211
|
-
if (is_remote_endpoint) {
|
|
212
|
-
await pullSchema(url, path.join(targetPath, schemaPath), headers)
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
await writeConfigFile({
|
|
216
|
-
configPath,
|
|
217
|
-
schemaPath,
|
|
218
|
-
module,
|
|
219
|
-
url: is_remote_endpoint ? url : null,
|
|
220
|
-
houdiniClientImport,
|
|
221
|
-
})
|
|
222
|
-
await fs.writeFile(houdiniClientPath, networkFile(url, typescript))
|
|
223
|
-
await graphqlRCFile(targetPath)
|
|
224
|
-
await gitIgnore(targetPath)
|
|
225
|
-
|
|
226
|
-
// Config files for:
|
|
227
|
-
// - kit only
|
|
228
|
-
// - svelte only
|
|
229
|
-
// - both (with small variants)
|
|
230
|
-
if (framework === 'kit') {
|
|
231
|
-
await updateSvelteConfig(targetPath)
|
|
232
|
-
} else if (framework === 'svelte') {
|
|
233
|
-
await updateSvelteMainJs(targetPath)
|
|
234
|
-
}
|
|
235
|
-
await updateViteConfig(targetPath, framework, typescript)
|
|
236
|
-
await tjsConfig(targetPath, framework)
|
|
237
|
-
|
|
238
|
-
// we're done!
|
|
239
|
-
console.log()
|
|
240
|
-
console.log('🎩 Welcome to Houdini!')
|
|
241
|
-
let cmd_install = 'npm i'
|
|
242
|
-
let cmd_run = 'npm run dev'
|
|
243
|
-
if (package_manager === 'pnpm') {
|
|
244
|
-
cmd_install = 'pnpm i'
|
|
245
|
-
cmd_run = 'pnpm dev'
|
|
246
|
-
} else if (package_manager === 'yarn') {
|
|
247
|
-
cmd_install = 'yarn'
|
|
248
|
-
cmd_run = 'yarn dev'
|
|
249
|
-
}
|
|
250
|
-
console.log(`
|
|
251
|
-
👉 Next Steps
|
|
252
|
-
1️⃣ Finalize your installation: ${logGreen(cmd_install)}
|
|
253
|
-
2️⃣ Start your application: ${logGreen(cmd_run)}
|
|
254
|
-
`)
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
const networkFile = (url: string, typescript: boolean) => `import { HoudiniClient${
|
|
258
|
-
typescript ? ', type RequestHandlerArgs' : ''
|
|
259
|
-
} } from '$houdini';
|
|
260
|
-
|
|
261
|
-
async function fetchQuery({
|
|
262
|
-
fetch,
|
|
263
|
-
text = '',
|
|
264
|
-
variables = {},
|
|
265
|
-
metadata
|
|
266
|
-
}${typescript ? ': RequestHandlerArgs' : ''}) {
|
|
267
|
-
const url = '${url}';
|
|
268
|
-
const result = await fetch(url, {
|
|
269
|
-
method: 'POST',
|
|
270
|
-
headers: {
|
|
271
|
-
'Content-Type': 'application/json'
|
|
272
|
-
},
|
|
273
|
-
body: JSON.stringify({
|
|
274
|
-
query: text,
|
|
275
|
-
variables
|
|
276
|
-
})
|
|
277
|
-
});
|
|
278
|
-
return await result.json();
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
export default new HoudiniClient(fetchQuery);
|
|
282
|
-
`
|
|
283
|
-
|
|
284
|
-
const writeConfigFile = async ({
|
|
285
|
-
configPath,
|
|
286
|
-
schemaPath,
|
|
287
|
-
module,
|
|
288
|
-
url,
|
|
289
|
-
houdiniClientImport,
|
|
290
|
-
}: {
|
|
291
|
-
configPath: string
|
|
292
|
-
schemaPath: string
|
|
293
|
-
module: 'esm' | 'commonjs'
|
|
294
|
-
url: string | null
|
|
295
|
-
houdiniClientImport: string
|
|
296
|
-
}): Promise<boolean> => {
|
|
297
|
-
const config: ConfigFile = {}
|
|
298
|
-
|
|
299
|
-
// if we have no url, we are using a local schema
|
|
300
|
-
if (url !== null) {
|
|
301
|
-
config.apiUrl = url
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
// if it's different for defaults, write it down
|
|
305
|
-
if (schemaPath !== './schema.graphql') {
|
|
306
|
-
config.schemaPath = schemaPath
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// if it's different for defaults, write it down
|
|
310
|
-
if (module !== 'esm') {
|
|
311
|
-
config.module = module
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// put plugins at the bottom
|
|
315
|
-
config.plugins = {
|
|
316
|
-
'houdini-svelte': {
|
|
317
|
-
client: houdiniClientImport,
|
|
318
|
-
},
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// the actual config contents
|
|
322
|
-
const configObj = JSON.stringify(config, null, 4)
|
|
323
|
-
const content_base = `/// <references types="houdini-svelte">
|
|
324
|
-
|
|
325
|
-
/** @type {import('houdini').ConfigFile} */
|
|
326
|
-
const config = ${configObj}`
|
|
327
|
-
|
|
328
|
-
const content =
|
|
329
|
-
module === 'esm'
|
|
330
|
-
? // ESM default config
|
|
331
|
-
`${content_base}
|
|
332
|
-
|
|
333
|
-
export default config
|
|
334
|
-
`
|
|
335
|
-
: // CommonJS default config
|
|
336
|
-
`${content_base}}
|
|
337
|
-
|
|
338
|
-
module.exports = config
|
|
339
|
-
`
|
|
340
|
-
|
|
341
|
-
await updateFile({
|
|
342
|
-
filepath: configPath,
|
|
343
|
-
content,
|
|
344
|
-
})
|
|
345
|
-
|
|
346
|
-
return false
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
async function tjsConfig(targetPath: string, framework: 'kit' | 'svelte') {
|
|
350
|
-
// if there is no tsconfig.json, there could be a jsconfig.json
|
|
351
|
-
let configFile = path.join(targetPath, 'tsconfig.json')
|
|
352
|
-
try {
|
|
353
|
-
await fs.stat(configFile)
|
|
354
|
-
} catch {
|
|
355
|
-
configFile = path.join(targetPath, 'jsconfig.json')
|
|
356
|
-
try {
|
|
357
|
-
await fs.stat(configFile)
|
|
358
|
-
|
|
359
|
-
// there isn't either a .tsconfig.json or a jsconfig.json, there's nothing to update
|
|
360
|
-
} catch {
|
|
361
|
-
return false
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// check if the tsconfig.json file exists
|
|
366
|
-
try {
|
|
367
|
-
let tjsConfigFile = await fs.readFile(configFile)
|
|
368
|
-
if (tjsConfigFile) {
|
|
369
|
-
var tjsConfig = parseJSON(tjsConfigFile)
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
// new rootDirs (will overwrite the one in "extends": "./.svelte-kit/tsconfig.json")
|
|
373
|
-
if (framework === 'kit') {
|
|
374
|
-
tjsConfig.compilerOptions.rootDirs = ['.', './.svelte-kit/types', './$houdini/types']
|
|
375
|
-
} else {
|
|
376
|
-
tjsConfig.compilerOptions.rootDirs = ['.', './$houdini/types']
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
// In kit, no need to add manually the path. Why? Because:
|
|
380
|
-
// The config [svelte.config.js => kit => alias => $houdini]
|
|
381
|
-
// will make this automatically in "extends": "./.svelte-kit/tsconfig.json"
|
|
382
|
-
// In svelte, we need to add the path manually
|
|
383
|
-
if (framework === 'svelte') {
|
|
384
|
-
tjsConfig.compilerOptions.paths = {
|
|
385
|
-
...tjsConfig.compilerOptions.paths,
|
|
386
|
-
$houdini: ['./$houdini/'],
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
await fs.writeFile(configFile, JSON.stringify(tjsConfig, null, 4))
|
|
391
|
-
} catch {}
|
|
392
|
-
|
|
393
|
-
return false
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
async function updateViteConfig(
|
|
397
|
-
targetPath: string,
|
|
398
|
-
framework: 'kit' | 'svelte',
|
|
399
|
-
typescript: boolean
|
|
400
|
-
) {
|
|
401
|
-
const viteConfigPath = path.join(targetPath, `vite.config${typescript ? '.ts' : '.js'}`)
|
|
402
|
-
|
|
403
|
-
const viteConfigKit = `import { sveltekit } from '@sveltejs/kit/vite';
|
|
404
|
-
import houdini from 'houdini/vite';
|
|
405
|
-
|
|
406
|
-
/** @type {import('vite').UserConfig} */
|
|
407
|
-
const config = {
|
|
408
|
-
plugins: [houdini(), sveltekit()],
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
export default config;
|
|
412
|
-
`
|
|
413
|
-
|
|
414
|
-
const viteConfigKitTs = `import { sveltekit } from '@sveltejs/kit/vite';
|
|
415
|
-
import houdini from 'houdini/vite';
|
|
416
|
-
import type { UserConfig } from "vite";
|
|
417
|
-
|
|
418
|
-
const config: UserConfig = {
|
|
419
|
-
plugins: [houdini(), sveltekit()],
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
export default config;
|
|
423
|
-
`
|
|
424
|
-
|
|
425
|
-
const viteConfigSvelte = `import { svelte } from '@sveltejs/vite-plugin-svelte';
|
|
426
|
-
import houdini from 'houdini/vite';
|
|
427
|
-
|
|
428
|
-
/** @type {import('vite').UserConfig} */
|
|
429
|
-
const config = {
|
|
430
|
-
plugins: [houdini(), svelte()],
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
export default config;
|
|
434
|
-
`
|
|
435
|
-
|
|
436
|
-
const viteConfigSvelteTs = `import { svelte } from '@sveltejs/vite-plugin-svelte';
|
|
437
|
-
import houdini from 'houdini/vite';
|
|
438
|
-
import type { UserConfig } from "vite";
|
|
439
|
-
|
|
440
|
-
const config: UserConfig = {
|
|
441
|
-
plugins: [houdini(), svelte()],
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
export default config;
|
|
445
|
-
`
|
|
446
|
-
|
|
447
|
-
let content = 'NOTHING!'
|
|
448
|
-
if (framework === 'kit' && typescript) {
|
|
449
|
-
content = viteConfigKitTs
|
|
450
|
-
} else if (framework === 'kit' && !typescript) {
|
|
451
|
-
content = viteConfigKit
|
|
452
|
-
} else if (framework === 'svelte' && typescript) {
|
|
453
|
-
content = viteConfigSvelteTs
|
|
454
|
-
} else if (framework === 'svelte' && !typescript) {
|
|
455
|
-
content = viteConfigSvelte
|
|
456
|
-
} else {
|
|
457
|
-
throw new Error('Unknown updateViteConfig()')
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
if (typescript) {
|
|
461
|
-
await updateFile({
|
|
462
|
-
filepath: viteConfigPath,
|
|
463
|
-
content: framework === 'kit' ? viteConfigKitTs : viteConfigSvelteTs,
|
|
464
|
-
})
|
|
465
|
-
} else {
|
|
466
|
-
await updateFile({
|
|
467
|
-
filepath: viteConfigPath,
|
|
468
|
-
content: framework === 'kit' ? viteConfigKit : viteConfigSvelte,
|
|
469
|
-
})
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
async function updateSvelteConfig(targetPath: string) {
|
|
474
|
-
const svelteConfigPath = path.join(targetPath, 'svelte.config.js')
|
|
475
|
-
|
|
476
|
-
const newContent = `import adapter from '@sveltejs/adapter-auto';
|
|
477
|
-
import preprocess from 'svelte-preprocess';
|
|
478
|
-
|
|
479
|
-
/** @type {import('@sveltejs/kit').Config} */
|
|
480
|
-
const config = {
|
|
481
|
-
// Consult https://github.com/sveltejs/svelte-preprocess
|
|
482
|
-
// for more information about preprocessors
|
|
483
|
-
preprocess: preprocess(),
|
|
484
|
-
|
|
485
|
-
kit: {
|
|
486
|
-
adapter: adapter(),
|
|
487
|
-
alias: {
|
|
488
|
-
$houdini: './$houdini',
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
export default config;
|
|
494
|
-
`
|
|
495
|
-
|
|
496
|
-
// write the svelte config file
|
|
497
|
-
await updateFile({
|
|
498
|
-
filepath: svelteConfigPath,
|
|
499
|
-
content: newContent,
|
|
500
|
-
})
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
async function updateSvelteMainJs(targetPath: string) {
|
|
504
|
-
const svelteMainJsPath = path.join(targetPath, 'main.js')
|
|
505
|
-
|
|
506
|
-
const newContent = `import client from "../client";
|
|
507
|
-
import './app.css'
|
|
508
|
-
import App from './App.svelte'
|
|
509
|
-
import { logGreen } from '@kitql/helper'
|
|
510
|
-
|
|
511
|
-
client.init();
|
|
512
|
-
|
|
513
|
-
const app = new App({
|
|
514
|
-
target: document.getElementById('app')
|
|
515
|
-
})
|
|
516
|
-
|
|
517
|
-
export default app
|
|
518
|
-
`
|
|
519
|
-
|
|
520
|
-
await updateFile({
|
|
521
|
-
filepath: svelteMainJsPath,
|
|
522
|
-
content: newContent,
|
|
523
|
-
})
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
async function updatePackageJSON(targetPath: string) {
|
|
527
|
-
let packageJSON: Record<string, any> = {}
|
|
528
|
-
|
|
529
|
-
const packagePath = path.join(targetPath, 'package.json')
|
|
530
|
-
const packageFile = await fs.readFile(packagePath)
|
|
531
|
-
if (packageFile) {
|
|
532
|
-
packageJSON = JSON.parse(packageFile)
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
// houdini & graphql should be a dev dependencies
|
|
536
|
-
packageJSON.devDependencies = {
|
|
537
|
-
...packageJSON.devDependencies,
|
|
538
|
-
houdini: '^PACKAGE_VERSION',
|
|
539
|
-
'houdini-svelte': '^PACKAGE_VERSION',
|
|
540
|
-
graphql: '^15.8.0',
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
await fs.writeFile(packagePath, JSON.stringify(packageJSON, null, 4))
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
async function graphqlRCFile(targetPath: string) {
|
|
547
|
-
// the filepath for the rcfile
|
|
548
|
-
const target = path.join(targetPath, '.graphqlrc.yaml')
|
|
549
|
-
|
|
550
|
-
const content = `projects:
|
|
551
|
-
default:
|
|
552
|
-
schema:
|
|
553
|
-
- ./schema.graphql
|
|
554
|
-
- ./$houdini/graphql/schema.graphql
|
|
555
|
-
documents:
|
|
556
|
-
- '**/*.gql'
|
|
557
|
-
- ./$houdini/graphql/documents.gql
|
|
558
|
-
`
|
|
559
|
-
|
|
560
|
-
await updateFile({
|
|
561
|
-
filepath: target,
|
|
562
|
-
content,
|
|
563
|
-
})
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
async function gitIgnore(targetPath: string) {
|
|
567
|
-
const filepath = path.join(targetPath, '.gitignore')
|
|
568
|
-
const existing = (await fs.readFile(filepath)) || ''
|
|
569
|
-
|
|
570
|
-
if (!existing.includes('\n$houdini\n')) {
|
|
571
|
-
await fs.writeFile(filepath, existing + '\n$houdini\n')
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
type DetectedTools = {
|
|
576
|
-
typescript: boolean
|
|
577
|
-
framework: 'kit' | 'sapper' | 'svelte'
|
|
578
|
-
module: 'esm' | 'commonjs'
|
|
579
|
-
package_manager: 'npm' | 'yarn' | 'pnpm'
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
async function detectTools(cwd: string): Promise<DetectedTools> {
|
|
583
|
-
// if there's no package.json then there's nothing we can detect
|
|
584
|
-
try {
|
|
585
|
-
const packageJSONFile = await fs.readFile(path.join(cwd, 'package.json'))
|
|
586
|
-
if (packageJSONFile) {
|
|
587
|
-
var packageJSON = JSON.parse(packageJSONFile)
|
|
588
|
-
} else {
|
|
589
|
-
throw new Error('not found')
|
|
590
|
-
}
|
|
591
|
-
} catch {
|
|
592
|
-
throw new Error(
|
|
593
|
-
'❌ houdini init must target an existing node project (with a package.json)'
|
|
594
|
-
)
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
// grab the dev dependencies
|
|
598
|
-
const { devDependencies, dependencies } = packageJSON
|
|
599
|
-
|
|
600
|
-
const hasDependency = (dep: string) => Boolean(devDependencies?.[dep] || dependencies?.[dep])
|
|
601
|
-
|
|
602
|
-
let framework: ConfigFile['framework'] = 'svelte'
|
|
603
|
-
if (hasDependency('@sveltejs/kit')) {
|
|
604
|
-
framework = 'kit'
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
let typescript = false
|
|
608
|
-
try {
|
|
609
|
-
await fs.stat(path.join(cwd, 'tsconfig.json'))
|
|
610
|
-
typescript = true
|
|
611
|
-
} catch {}
|
|
612
|
-
|
|
613
|
-
// package manager?
|
|
614
|
-
let package_manager: 'npm' | 'yarn' | 'pnpm' = 'npm'
|
|
615
|
-
let dir = cwd
|
|
616
|
-
do {
|
|
617
|
-
if (fs.existsSync(path.join(dir, 'pnpm-lock.yaml'))) {
|
|
618
|
-
package_manager = 'pnpm'
|
|
619
|
-
break
|
|
620
|
-
}
|
|
621
|
-
if (fs.existsSync(path.join(dir, 'yarn.lock'))) {
|
|
622
|
-
package_manager = 'yarn'
|
|
623
|
-
break
|
|
624
|
-
}
|
|
625
|
-
} while (dir !== (dir = path.dirname(dir)))
|
|
626
|
-
|
|
627
|
-
return {
|
|
628
|
-
typescript,
|
|
629
|
-
framework,
|
|
630
|
-
module: packageJSON['type'] === 'module' ? 'esm' : 'commonjs',
|
|
631
|
-
package_manager,
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
async function updateFile({ filepath, content }: { filepath: string; content: string }) {
|
|
636
|
-
await fs.writeFile(filepath, content)
|
|
637
|
-
}
|
package/src/cmd/pullSchema.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { getConfig, pullSchema, path } from '../lib'
|
|
2
|
-
|
|
3
|
-
export default async function (args: { headers: string[] }) {
|
|
4
|
-
const config = await getConfig({ noSchema: true })
|
|
5
|
-
|
|
6
|
-
// Check if apiUrl is set in config
|
|
7
|
-
if (!config.apiUrl) {
|
|
8
|
-
console.log(
|
|
9
|
-
'❌ Your project does not have a remote endpoint configured. Please provide one with the `apiUrl` value in your houdini.config.js file.'
|
|
10
|
-
)
|
|
11
|
-
process.exit(1)
|
|
12
|
-
return
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// The target path -> current working directory by default. Should we allow passing custom paths?
|
|
16
|
-
const targetPath = process.cwd()
|
|
17
|
-
|
|
18
|
-
let headers = config.pullHeaders
|
|
19
|
-
let headerStrings: string[] = []
|
|
20
|
-
|
|
21
|
-
if (args.headers) {
|
|
22
|
-
headerStrings = args.headers
|
|
23
|
-
}
|
|
24
|
-
if (headerStrings.length > 0) {
|
|
25
|
-
headers = headerStrings.reduce((total, header) => {
|
|
26
|
-
const [key, value] = header.split('=')
|
|
27
|
-
return {
|
|
28
|
-
...total,
|
|
29
|
-
[key]: value,
|
|
30
|
-
}
|
|
31
|
-
}, headers)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Write the schema
|
|
35
|
-
await pullSchema(
|
|
36
|
-
config.apiUrl,
|
|
37
|
-
config.schemaPath ? config.schemaPath : path.resolve(targetPath, 'schema.json'),
|
|
38
|
-
headers
|
|
39
|
-
)
|
|
40
|
-
}
|