Skip to content

Commit 2220742

Browse files
committed
improve docs and add assets + asset-types flags, clearer
1 parent ad9bb16 commit 2220742

2 files changed

Lines changed: 52 additions & 26 deletions

File tree

src/commands/theme/generate/component.ts

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ export default class GenerateComponent extends BaseCommand {
3636
static override description = 'Generate a new component with optional supporting files'
3737

3838
static override examples = [
39+
'<%= config.bin %> <%= command.id %>',
3940
'<%= config.bin %> <%= command.id %> element.button',
40-
'<%= config.bin %> <%= command.id %> element.button --assets=css --files',
41-
'<%= config.bin %> <%= command.id %> element.button --snippets=gift-form,upsell',
42-
'<%= config.bin %> <%= command.id %> element.button --setup',
41+
'<%= config.bin %> <%= command.id %> element.button --assets',
42+
'<%= config.bin %> <%= command.id %> element.button --assets --asset-types=css',
43+
'<%= config.bin %> <%= command.id %> section.hero --assets --files',
44+
'<%= config.bin %> <%= command.id %> element.text --assets --snippets=body,heading,rte --setup'
4345
]
4446

4547
static override flags = Flags.getDefinitions([
48+
Flags.ASSET_TYPES,
4649
Flags.ASSETS,
4750
Flags.FILES,
4851
Flags.FORCE,
@@ -172,10 +175,6 @@ export default class GenerateComponent extends BaseCommand {
172175
return { assets, component, snippets }
173176
}
174177

175-
private capitalizeFirst(str: string): string {
176-
return str.charAt(0).toUpperCase() + str.slice(1)
177-
}
178-
179178
private createFiles(component: ComponentParts, filesToCreate: FileToCreate[]): void {
180179
const created: string[] = []
181180
const skipped: string[] = []
@@ -215,27 +214,33 @@ export default class GenerateComponent extends BaseCommand {
215214
return { name, type }
216215
}
217216

218-
private getAssetTypesFromFlag(assetsFlag: string): { css: boolean; js: boolean } {
219-
const assetTypeMap = {
220-
all: { css: true, js: true },
221-
css: { css: true, js: false },
222-
js: { css: false, js: true },
223-
} as const
217+
private getAssetTypesFromFlags(assetTypesFlag?: string): { css: boolean; js: boolean } {
218+
// If no asset types specified, default to both
219+
if (!assetTypesFlag) {
220+
return { css: true, js: true }
221+
}
224222

225-
return assetTypeMap[assetsFlag as keyof typeof assetTypeMap] || { css: false, js: false }
223+
// Parse comma-separated values
224+
const types = new Set(assetTypesFlag.toLowerCase().split(',').map(t => t.trim()))
225+
226+
return {
227+
css: types.has('css'),
228+
js: types.has('js')
229+
}
226230
}
227231

228232
private parseAssetTypes(): { css: boolean; inline: boolean; js: boolean } {
229233
const assetsFlag = this.flags[Flags.ASSETS]
234+
const assetTypesFlag = this.flags[Flags.ASSET_TYPES]
230235
const filesFlag = this.flags[Flags.FILES]
231236

232-
this.validateAssetDependencies(assetsFlag, filesFlag)
237+
this.validateAssetDependencies(assetsFlag, assetTypesFlag, filesFlag)
233238

234239
if (!assetsFlag) {
235240
return { css: false, inline: true, js: false }
236241
}
237242

238-
const { css, js } = this.getAssetTypesFromFlag(assetsFlag)
243+
const { css, js } = this.getAssetTypesFromFlags(assetTypesFlag)
239244

240245
return {
241246
css,
@@ -280,10 +285,21 @@ export default class GenerateComponent extends BaseCommand {
280285
}
281286

282287
private async promptForComponentType(): Promise<string> {
283-
const componentTypes = ['block', 'element', 'form', 'layout', 'section', 'utility'] as const
288+
const componentTypes = [
289+
{ description: 'Resource-specific blocks', name: 'block' },
290+
{ description: 'Basic UI primitives', name: 'element' },
291+
{ description: 'Form-specific components', name: 'form' },
292+
{ description: 'Structure and spacing primitives', name: 'layout' },
293+
{ description: 'Sections rendered in templates', name: 'section' },
294+
{ description: "Helper components that don't render UI elements", name: 'utility' },
295+
] as const
296+
284297
const type = await renderSelectPrompt({
285298
choices: [
286-
...componentTypes.map(t => ({ label: this.capitalizeFirst(t), value: t })),
299+
...componentTypes.map(t => ({
300+
label: `${t.name.charAt(0).toUpperCase() + t.name.slice(1)} - ${t.description}`,
301+
value: t.name
302+
})),
287303
{ label: 'Other (specify custom type)', value: 'other' },
288304
],
289305
message: 'What type of component?',
@@ -386,9 +402,13 @@ export default class GenerateComponent extends BaseCommand {
386402
}
387403
}
388404

389-
private validateAssetDependencies(assetsFlag: string | undefined, filesFlag: boolean): void {
405+
private validateAssetDependencies(assetsFlag: boolean, assetTypesFlag: string | undefined, filesFlag: boolean): void {
390406
if (filesFlag && !assetsFlag) {
391407
this.error('The --files flag can only be used together with --assets')
392408
}
409+
410+
if (assetTypesFlag && !assetsFlag) {
411+
this.error('The --asset-types flag can only be used together with --assets')
412+
}
393413
}
394414
}

src/utilities/flags.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ComponentConfig } from './types.js'
55

66
export default class Flags {
77
[key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any
8+
static readonly ASSET_TYPES = 'asset-types';
89
static readonly ASSETS = 'assets';
910
static readonly CLEAN = 'clean';
1011
static readonly COLLECTION_NAME = 'collection-name';
@@ -56,13 +57,18 @@ export default class Flags {
5657

5758
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5859
export const flagDefinitions: Record<string, any> = {
59-
[Flags.ASSETS]: OclifFlags.string({
60-
char: 'a',
61-
description: "Generate CSS and JS assets. Specify 'all', 'css', or 'js'",
62-
helpValue: '[all|css|js]',
60+
[Flags.ASSET_TYPES]: OclifFlags.string({
61+
description: "The asset types to generate: 'css', 'js', or 'css,js' (defaults to both)",
62+
helpValue: '[css|js|css,js]',
6363
required: false,
6464
}),
6565

66+
[Flags.ASSETS]: OclifFlags.boolean({
67+
char: 'a',
68+
default: false,
69+
description: "Generate CSS and JS assets. Defaults to inline references in the component's Liquid file inside {% stylesheet %} and {% javascript %} tags",
70+
}),
71+
6672
[Flags.CLEAN]: OclifFlags.boolean({
6773
char: 'c',
6874
default: false,
@@ -86,7 +92,7 @@ export const flagDefinitions: Record<string, any> = {
8692
[Flags.FILES]: OclifFlags.boolean({
8793
char: 'f',
8894
default: false,
89-
description: 'Create separate asset files instead of inline',
95+
description: "Create separate CSS and JS files instead of inline references in the component's Liquid file",
9096
}),
9197

9298
[Flags.FORCE]: OclifFlags.boolean({
@@ -172,7 +178,7 @@ export const flagDefinitions: Record<string, any> = {
172178
[Flags.SETUP]: OclifFlags.boolean({
173179
char: 's',
174180
default: false,
175-
description: 'Generate setup files (sections and templates)',
181+
description: 'Generate section and template files to preview component in component explorer',
176182
}),
177183

178184
[Flags.SETUP_FILES]: OclifFlags.boolean({
@@ -183,7 +189,7 @@ export const flagDefinitions: Record<string, any> = {
183189
}),
184190

185191
[Flags.SNIPPETS]: OclifFlags.string({
186-
description: 'Comma-separated list of snippet names to generate',
192+
description: 'Generate component snippets (e.g., "body,heading,rte")',
187193
multiple: true,
188194
}),
189195

0 commit comments

Comments
 (0)