create-houdini 2.0.0-next.11 → 2.0.0-next.12
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/bin.js +97 -10
- package/package.json +1 -1
package/bin.js
CHANGED
|
@@ -62,12 +62,11 @@ p.intro('🎩 Welcome to Houdini!')
|
|
|
62
62
|
|
|
63
63
|
// if we weren't given a directory, then we should ask
|
|
64
64
|
if (!projectDir) {
|
|
65
|
-
const dir = await
|
|
65
|
+
const dir = await pathInput({
|
|
66
66
|
message: `Where should we create your project?`,
|
|
67
|
-
placeholder: ' (press Enter to use the current directory)',
|
|
68
67
|
})
|
|
69
68
|
|
|
70
|
-
if (
|
|
69
|
+
if (dir === null) {
|
|
71
70
|
process.exit(1)
|
|
72
71
|
}
|
|
73
72
|
|
|
@@ -141,13 +140,46 @@ let apiUrl = options_cli.schema?.startsWith('http') ? options_cli.schema : templ
|
|
|
141
140
|
if (!localSchema) {
|
|
142
141
|
let pullSchema_content = ''
|
|
143
142
|
if (apiUrl === '') {
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
143
|
+
const apiRunning = await p.confirm({
|
|
144
|
+
message: 'Is your API currently running?',
|
|
145
|
+
initialValue: true,
|
|
146
|
+
})
|
|
147
|
+
if (p.isCancel(apiRunning)) pCancel()
|
|
148
|
+
|
|
149
|
+
if (apiRunning) {
|
|
150
|
+
const { apiUrl: apiUrlCli, pullSchema_content: pullSchema_content_cli } =
|
|
151
|
+
await pullSchemaCli()
|
|
152
|
+
apiUrl = apiUrlCli
|
|
153
|
+
if (pullSchema_content_cli === null) {
|
|
154
|
+
pCancel('There was a problem pulling your shema. Please try again.')
|
|
155
|
+
} else {
|
|
156
|
+
pullSchema_content = pullSchema_content_cli
|
|
157
|
+
}
|
|
149
158
|
} else {
|
|
150
|
-
|
|
159
|
+
const hasSchemaFile = await p.confirm({
|
|
160
|
+
message: 'Do you have a schema file on disk we can use?',
|
|
161
|
+
initialValue: false,
|
|
162
|
+
})
|
|
163
|
+
if (p.isCancel(hasSchemaFile)) pCancel()
|
|
164
|
+
|
|
165
|
+
if (hasSchemaFile) {
|
|
166
|
+
const schemaFilePath = await pathInput({
|
|
167
|
+
message: 'Where is the schema file?',
|
|
168
|
+
initialValue: './schema.graphql',
|
|
169
|
+
validate: (value) => {
|
|
170
|
+
if (!value) return 'Please enter a valid path'
|
|
171
|
+
try {
|
|
172
|
+
fs.statSync(path.resolve(value))
|
|
173
|
+
} catch {
|
|
174
|
+
return 'File not found'
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
})
|
|
178
|
+
if (schemaFilePath === null) pCancel()
|
|
179
|
+
pullSchema_content = fs.readFileSync(path.resolve(schemaFilePath), 'utf-8')
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
apiUrl = 'API_URL'
|
|
151
183
|
}
|
|
152
184
|
} else {
|
|
153
185
|
const pullSchema_content_local = await pullSchema(apiUrl, {})
|
|
@@ -158,7 +190,9 @@ if (!localSchema) {
|
|
|
158
190
|
}
|
|
159
191
|
}
|
|
160
192
|
|
|
161
|
-
|
|
193
|
+
if (pullSchema_content) {
|
|
194
|
+
writeFileSync(path.join(projectDir, 'schema.graphql'), pullSchema_content)
|
|
195
|
+
}
|
|
162
196
|
}
|
|
163
197
|
|
|
164
198
|
// the final client config depends on whether we have a local schema or not
|
|
@@ -380,6 +414,59 @@ function extractHeadersStr(/** @type {string} */ str) {
|
|
|
380
414
|
return obj
|
|
381
415
|
}
|
|
382
416
|
|
|
417
|
+
async function pathInput({ message, initialValue = '', validate }) {
|
|
418
|
+
const { createInterface } = await import('node:readline')
|
|
419
|
+
|
|
420
|
+
function completer(line) {
|
|
421
|
+
const isTrailingSlash = line.endsWith('/')
|
|
422
|
+
const dir = isTrailingSlash ? line || '.' : path.dirname(line) || '.'
|
|
423
|
+
const base = isTrailingSlash ? '' : path.basename(line)
|
|
424
|
+
let hits = []
|
|
425
|
+
try {
|
|
426
|
+
hits = fs
|
|
427
|
+
.readdirSync(dir)
|
|
428
|
+
.filter((e) => e.startsWith(base))
|
|
429
|
+
.map((e) => {
|
|
430
|
+
const full = path.join(dir, e)
|
|
431
|
+
try {
|
|
432
|
+
return fs.statSync(full).isDirectory() ? full + '/' : full
|
|
433
|
+
} catch {
|
|
434
|
+
return full
|
|
435
|
+
}
|
|
436
|
+
})
|
|
437
|
+
} catch {}
|
|
438
|
+
return [hits, line]
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
process.stdout.write(`\n${gray('◆')} ${message}\n`)
|
|
442
|
+
|
|
443
|
+
for (;;) {
|
|
444
|
+
const answer = await new Promise((resolve) => {
|
|
445
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout, completer })
|
|
446
|
+
rl.setPrompt(`${gray('│')} `)
|
|
447
|
+
rl.prompt()
|
|
448
|
+
rl.once('line', (v) => {
|
|
449
|
+
rl.close()
|
|
450
|
+
resolve(v.trim() || initialValue)
|
|
451
|
+
})
|
|
452
|
+
rl.on('SIGINT', () => {
|
|
453
|
+
rl.close()
|
|
454
|
+
resolve(null)
|
|
455
|
+
})
|
|
456
|
+
})
|
|
457
|
+
|
|
458
|
+
if (answer === null) return null
|
|
459
|
+
if (validate) {
|
|
460
|
+
const err = validate(answer)
|
|
461
|
+
if (err) {
|
|
462
|
+
process.stdout.write(`${gray('▲')} ${err}\n`)
|
|
463
|
+
continue
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
return answer
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
383
470
|
function pCancel(cancelText = 'Operation cancelled.') {
|
|
384
471
|
p.cancel(cancelText)
|
|
385
472
|
process.exit(1)
|