From 7bfa291afd534e9e2ee45f1df9f95a4e6767a937 Mon Sep 17 00:00:00 2001 From: James Meng Date: Wed, 11 Dec 2024 11:06:54 -0800 Subject: [PATCH] --wip-- [skip ci] --- .../src/cli/commands/theme/generate/block.ts | 24 +++++++++++++++---- .../cli/commands/theme/generate/section.ts | 24 +++++++++++++++---- .../cli/commands/theme/generate/template.ts | 24 +++++++++++++++---- 3 files changed, 60 insertions(+), 12 deletions(-) diff --git a/packages/theme/src/cli/commands/theme/generate/block.ts b/packages/theme/src/cli/commands/theme/generate/block.ts index 926895ce81..7da12a15db 100644 --- a/packages/theme/src/cli/commands/theme/generate/block.ts +++ b/packages/theme/src/cli/commands/theme/generate/block.ts @@ -2,7 +2,7 @@ import {themeFlags} from '../../../flags.js' import ThemeCommand from '../../../utilities/theme-command.js' import {Flags} from '@oclif/core' import {globalFlags} from '@shopify/cli-kit/node/cli' -import {renderSuccess} from '@shopify/cli-kit/node/ui' +import {renderSelectPrompt, renderSuccess, renderTextPrompt} from '@shopify/cli-kit/node/ui' export default class GenerateBlock extends ThemeCommand { static summary = 'Creates and adds a new block file to your local theme directory' @@ -21,13 +21,11 @@ export default class GenerateBlock extends ThemeCommand { name: Flags.string({ char: 'n', description: 'Name of the block', - required: true, env: 'SHOPIFY_FLAG_THEME_GENERATE_BLOCK_NAME', }), type: Flags.string({ char: 't', description: 'Type of block to generate', - required: true, options: ['text', 'image', 'video', 'product', 'collection'], env: 'SHOPIFY_FLAG_THEME_GENERATE_BLOCK_TYPE', }), @@ -35,8 +33,26 @@ export default class GenerateBlock extends ThemeCommand { async run(): Promise { const {flags} = await this.parse(GenerateBlock) + + const name = + flags.name ?? + (await renderTextPrompt({ + message: 'Name of the block', + })) + + const blockTypes = ['text', 'image', 'video', 'product', 'collection'] + const choices = blockTypes.map((type) => { + return {label: type, value: type} + }) + const type = + flags.type ?? + (await renderSelectPrompt({ + message: 'Type of block', + choices, + })) + renderSuccess({ - body: ['Placeholder: Generating block with name:', flags.name, 'type:', flags.type], + body: [`Placeholder: Generating block with name: ${name}, type: ${type}`], }) } } diff --git a/packages/theme/src/cli/commands/theme/generate/section.ts b/packages/theme/src/cli/commands/theme/generate/section.ts index 10715298f7..64c7a432bf 100644 --- a/packages/theme/src/cli/commands/theme/generate/section.ts +++ b/packages/theme/src/cli/commands/theme/generate/section.ts @@ -2,7 +2,7 @@ import {themeFlags} from '../../../flags.js' import ThemeCommand from '../../../utilities/theme-command.js' import {Flags} from '@oclif/core' import {globalFlags} from '@shopify/cli-kit/node/cli' -import {renderSuccess} from '@shopify/cli-kit/node/ui' +import {renderSelectPrompt, renderSuccess, renderTextPrompt} from '@shopify/cli-kit/node/ui' export default class GenerateSection extends ThemeCommand { static summary = 'Creates and adds a new section file to your local theme directory' @@ -21,13 +21,11 @@ export default class GenerateSection extends ThemeCommand { name: Flags.string({ char: 'n', description: 'Name of the section', - required: true, env: 'SHOPIFY_FLAG_THEME_GENERATE_SECTION_NAME', }), type: Flags.string({ char: 't', description: 'Type of section to generate', - required: true, options: ['featured-collection', 'image-with-text', 'rich-text', 'custom'], env: 'SHOPIFY_FLAG_THEME_GENERATE_SECTION_TYPE', }), @@ -35,8 +33,26 @@ export default class GenerateSection extends ThemeCommand { async run(): Promise { const {flags} = await this.parse(GenerateSection) + + const name = + flags.name ?? + (await renderTextPrompt({ + message: 'Name of the section', + })) + + const sectionTypes = ['featured-collection', 'image-with-text', 'rich-text', 'custom'] + const choices = sectionTypes.map((type) => { + return {label: type, value: type} + }) + const type = + flags.type ?? + (await renderSelectPrompt({ + message: 'Type of section', + choices, + })) + renderSuccess({ - body: ['Placeholder: Generating section with name:', flags.name, 'type:', flags.type], + body: [`Placeholder: Generating section with name: ${name}, type: ${type}`], }) } } diff --git a/packages/theme/src/cli/commands/theme/generate/template.ts b/packages/theme/src/cli/commands/theme/generate/template.ts index bf2942c046..87d03f6bad 100644 --- a/packages/theme/src/cli/commands/theme/generate/template.ts +++ b/packages/theme/src/cli/commands/theme/generate/template.ts @@ -2,7 +2,7 @@ import {themeFlags} from '../../../flags.js' import ThemeCommand from '../../../utilities/theme-command.js' import {Flags} from '@oclif/core' import {globalFlags} from '@shopify/cli-kit/node/cli' -import {renderSuccess} from '@shopify/cli-kit/node/ui' +import {renderSelectPrompt, renderSuccess, renderTextPrompt} from '@shopify/cli-kit/node/ui' export default class GenerateTemplate extends ThemeCommand { static summary = 'Creates and adds a new template file to your local theme directory' @@ -21,13 +21,11 @@ export default class GenerateTemplate extends ThemeCommand { name: Flags.string({ char: 'n', description: 'Name of the template', - required: true, env: 'SHOPIFY_FLAG_THEME_GENERATE_TEMPLATE_NAME', }), type: Flags.string({ char: 't', description: 'Type of template to generate', - required: true, options: ['product', 'collection', 'page', 'blog', 'article', 'custom'], env: 'SHOPIFY_FLAG_THEME_GENERATE_TEMPLATE_TYPE', }), @@ -35,8 +33,26 @@ export default class GenerateTemplate extends ThemeCommand { async run(): Promise { const {flags} = await this.parse(GenerateTemplate) + + const name = + flags.name ?? + (await renderTextPrompt({ + message: 'Name of the template', + })) + + const templateTypes = ['product', 'collection', 'page', 'blog', 'article', 'custom'] + const choices = templateTypes.map((type) => { + return {label: type, value: type} + }) + const type = + flags.type ?? + (await renderSelectPrompt({ + message: 'Type of template', + choices, + })) + renderSuccess({ - body: ['Placeholder: Generating template with name:', flags.name, 'type:', flags.type], + body: [`Placeholder: Generating template with name: ${name}, type: ${type}`], }) } }