Skip to content

Commit 7e957ae

Browse files
committed
Adding examples
1 parent b23ef04 commit 7e957ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+157
-34
lines changed

src/add-ons.ts

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { fileURLToPath } from 'node:url'
55

66
export type AddOn = {
77
id: string
8+
type: 'add-on' | 'example'
89
name: string
910
description: string
1011
link: string
@@ -50,38 +51,42 @@ function isDirectory(path: string): boolean {
5051
}
5152

5253
export async function getAllAddOns(): Promise<Array<AddOn>> {
53-
const addOnsBase = fileURLToPath(
54-
new URL('../templates/add-ons', import.meta.url),
55-
)
56-
5754
const addOns: Array<AddOn> = []
5855

59-
for (const dir of await readdirSync(addOnsBase).filter((file) =>
60-
isDirectory(resolve(addOnsBase, file)),
61-
)) {
62-
const filePath = resolve(addOnsBase, dir, 'info.json')
63-
const fileContent = await readFile(filePath, 'utf-8')
56+
for (const type of ['add-on', 'example']) {
57+
const addOnsBase = fileURLToPath(
58+
new URL(`../templates/${type}`, import.meta.url),
59+
)
6460

65-
let packageAdditions: Record<string, string> = {}
66-
if (existsSync(resolve(addOnsBase, dir, 'package.json'))) {
67-
packageAdditions = JSON.parse(
68-
await readFile(resolve(addOnsBase, dir, 'package.json'), 'utf-8'),
69-
)
70-
}
61+
for (const dir of await readdirSync(addOnsBase).filter((file) =>
62+
isDirectory(resolve(addOnsBase, file)),
63+
)) {
64+
const filePath = resolve(addOnsBase, dir, 'info.json')
65+
const fileContent = await readFile(filePath, 'utf-8')
7166

72-
let readme: string | undefined
73-
if (existsSync(resolve(addOnsBase, dir, 'README.md'))) {
74-
readme = await readFile(resolve(addOnsBase, dir, 'README.md'), 'utf-8')
75-
}
67+
let packageAdditions: Record<string, string> = {}
68+
if (existsSync(resolve(addOnsBase, dir, 'package.json'))) {
69+
packageAdditions = JSON.parse(
70+
await readFile(resolve(addOnsBase, dir, 'package.json'), 'utf-8'),
71+
)
72+
}
7673

77-
addOns.push({
78-
id: dir,
79-
...JSON.parse(fileContent),
80-
directory: resolve(addOnsBase, dir),
81-
packageAdditions,
82-
readme,
83-
})
74+
let readme: string | undefined
75+
if (existsSync(resolve(addOnsBase, dir, 'README.md'))) {
76+
readme = await readFile(resolve(addOnsBase, dir, 'README.md'), 'utf-8')
77+
}
78+
79+
addOns.push({
80+
id: dir,
81+
type,
82+
...JSON.parse(fileContent),
83+
directory: resolve(addOnsBase, dir),
84+
packageAdditions,
85+
readme,
86+
})
87+
}
8488
}
89+
8590
return addOns
8691
}
8792

src/create-app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ export async function createApp(options: Required<Options>) {
357357

358358
// Copy all the asset files from the addons
359359
const s = spinner()
360-
for (const phase of ['setup', 'add-on']) {
360+
for (const phase of ['setup', 'add-on', 'example']) {
361361
for (const addOn of options.chosenAddOns.filter(
362362
(addOn) => addOn.phase === phase,
363363
)) {

src/options.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,14 @@ export async function promptForOptions(
152152
const addOns = await getAllAddOns()
153153

154154
const selectedAddOns = await multiselect({
155-
message: 'Select add-ons:',
156-
options: addOns.map((addOn) => ({
157-
value: addOn.id,
158-
label: addOn.name,
159-
hint: addOn.description,
160-
})),
155+
message: 'What add-ons would you like for your project:',
156+
options: addOns
157+
.filter((addOn) => addOn.type === 'add-on')
158+
.map((addOn) => ({
159+
value: addOn.id,
160+
label: addOn.name,
161+
hint: addOn.description,
162+
})),
161163
required: false,
162164
})
163165

@@ -166,7 +168,27 @@ export async function promptForOptions(
166168
process.exit(0)
167169
}
168170

169-
options.chosenAddOns = await finalizeAddOns(selectedAddOns)
171+
const selectedExamples = await multiselect({
172+
message: 'Would you like any examples?',
173+
options: addOns
174+
.filter((addOn) => addOn.type === 'example')
175+
.map((addOn) => ({
176+
value: addOn.id,
177+
label: addOn.name,
178+
hint: addOn.description,
179+
})),
180+
required: false,
181+
})
182+
183+
if (isCancel(selectedExamples)) {
184+
cancel('Operation cancelled.')
185+
process.exit(0)
186+
}
187+
188+
options.chosenAddOns = await finalizeAddOns([
189+
...selectedAddOns,
190+
...selectedExamples,
191+
])
170192
options.tailwind = true
171193
} else {
172194
options.chosenAddOns = []
File renamed without changes.

0 commit comments

Comments
 (0)