Skip to content

Commit 2a58aa6

Browse files
committed
♻️ Improve the definition of default options
1 parent 0f2c9a1 commit 2a58aa6

File tree

3 files changed

+21
-27
lines changed

3 files changed

+21
-27
lines changed

libs/create-qwikdev-astro/src/app.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -179,29 +179,27 @@ export class Application extends Program<Definition, Input> {
179179
const add =
180180
definition.add === undefined
181181
? exists &&
182-
(await this.scanBoolean(
182+
!!(await this.scanBoolean(
183183
definition,
184-
"Do you want to add @QwikDev/astro to your existing project?",
185-
false
184+
"Do you want to add @QwikDev/astro to your existing project?"
186185
))
187186
: definition.add;
188187

189188
const force =
190189
definition.force === undefined
191190
? exists &&
192191
!add &&
193-
(await this.scanBoolean(
192+
!!(await this.scanBoolean(
194193
definition,
195194
`Directory "./${resolveRelativeDir(
196195
outDir
197-
)}" already exists and is not empty. What would you like to overwrite it?`,
198-
false
196+
)}" already exists and is not empty. What would you like to overwrite it?`
199197
))
200198
: false;
201199

202200
let adapter: Adapter;
203201

204-
if (!add && definition.adapter === defaultDefinition.adapter) {
202+
if ((!add || force) && definition.adapter === defaultDefinition.adapter) {
205203
const adapterInput =
206204
((await this.scanBoolean(
207205
definition,
@@ -239,30 +237,28 @@ export class Application extends Program<Definition, Input> {
239237

240238
const biome =
241239
!add && definition.biome === undefined
242-
? await this.scanBoolean(
240+
? !!(await this.scanBoolean(
243241
definition,
244-
"Would you prefer Biome over ESLint/Prettier?",
245-
false
246-
)
242+
"Would you prefer Biome over ESLint/Prettier?"
243+
))
247244
: !!definition.biome;
248245

249246
const ci =
250247
definition.ci === undefined
251-
? await this.scanBoolean(definition, "Would you like to add CI workflow?", false)
248+
? !!(await this.scanBoolean(definition, "Would you like to add CI workflow?"))
252249
: definition.ci;
253250

254251
const install =
255252
definition.install === undefined
256-
? await this.scanBoolean(
253+
? !!(await this.scanBoolean(
257254
definition,
258-
`Would you like to install ${this.#packageManger} dependencies?`,
259-
false
260-
)
255+
`Would you like to install ${this.#packageManger} dependencies?`
256+
))
261257
: definition.install;
262258

263259
const git =
264260
definition.git === undefined
265-
? await this.scanBoolean(definition, "Would you like to initialize Git?", false)
261+
? !!(await this.scanBoolean(definition, "Would you like to initialize Git?"))
266262
: definition.git;
267263

268264
const dryRun = !!definition.dryRun;

libs/create-qwikdev-astro/src/console.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -351,23 +351,21 @@ export async function scanBoolean(
351351
no?: boolean
352352
): Promise<
353353
typeof it extends true
354-
? boolean
354+
? typeof initialValue
355355
: typeof no extends true
356356
? false
357357
: typeof yes extends true
358358
? true
359359
: typeof initialValue
360360
> {
361361
const value =
362-
no && !initialValue
362+
no === true && initialValue === undefined
363363
? false
364-
: (yes && initialValue !== false) ||
365-
initialValue ||
366-
(it &&
367-
(await confirm({
368-
message,
369-
initialValue
370-
})));
364+
: yes === true && initialValue === undefined
365+
? true
366+
: it
367+
? await confirm({ message, initialValue })
368+
: initialValue;
371369

372370
if (value !== initialValue) {
373371
ensureBoolean(value);

libs/create-qwikdev-astro/src/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ export abstract class Program<
428428
return value;
429429
}
430430

431-
return initialValue
431+
return initialValue !== undefined
432432
? scanBoolean(
433433
message,
434434
initialValue,

0 commit comments

Comments
 (0)