-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add theme generation commands for blocks, sections, and templates
- Loading branch information
1 parent
d3d9d1f
commit 7228cbe
Showing
7 changed files
with
487 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
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 {renderSelectPrompt, renderSuccess, renderTextPrompt} from '@shopify/cli-kit/node/ui' | ||
|
||
const BLOCK_TYPES = ['text', 'image', 'video', 'product', 'collection'] | ||
|
||
export default class GenerateBlock extends ThemeCommand { | ||
static summary = 'Creates and adds a new block file to your local theme directory' | ||
|
||
static descriptionWithMarkdown = `Creates a new [theme block](https://shopify.dev/docs/themes/architecture/blocks) in your local theme directory. | ||
The block is created in the \`blocks\` directory with the basic structure needed, including schema and settings. | ||
You can specify the type of block to generate using the \`--type\` flag. The block will be created with appropriate default settings based on the type.` | ||
|
||
static description = this.descriptionWithoutMarkdown() | ||
|
||
static flags = { | ||
...globalFlags, | ||
path: themeFlags.path, | ||
name: Flags.string({ | ||
char: 'n', | ||
description: 'Name of the block', | ||
env: 'SHOPIFY_FLAG_BLOCK_NAME', | ||
}), | ||
type: Flags.string({ | ||
char: 't', | ||
description: 'Type of block to generate', | ||
options: [...BLOCK_TYPES], | ||
env: 'SHOPIFY_FLAG_BLOCK_TYPE', | ||
}), | ||
} | ||
|
||
async run(): Promise<void> { | ||
const {flags} = await this.parse(GenerateBlock) | ||
|
||
const name = | ||
flags.name ?? | ||
(await renderTextPrompt({ | ||
message: 'Name of the block', | ||
})) | ||
|
||
const choices = BLOCK_TYPES.map((type) => ({label: type, value: type})) | ||
const type = | ||
flags.type ?? | ||
(await renderSelectPrompt({ | ||
message: 'Type of block', | ||
choices, | ||
})) | ||
|
||
renderSuccess({ | ||
body: [`Placeholder: Generating block with name: ${name}, type: ${type}`], | ||
}) | ||
} | ||
} |
Oops, something went wrong.