Skip to content

Commit

Permalink
Add theme generation commands for blocks, sections, and templates
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmengo committed Dec 12, 2024
1 parent d3d9d1f commit 7228cbe
Show file tree
Hide file tree
Showing 7 changed files with 487 additions and 0 deletions.
89 changes: 89 additions & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
* [`shopify theme console`](#shopify-theme-console)
* [`shopify theme delete`](#shopify-theme-delete)
* [`shopify theme dev`](#shopify-theme-dev)
* [`shopify theme generate block`](#shopify-theme-generate-block)
* [`shopify theme generate section`](#shopify-theme-generate-section)
* [`shopify theme generate template`](#shopify-theme-generate-template)
* [`shopify theme info`](#shopify-theme-info)
* [`shopify theme init [name]`](#shopify-theme-init-name)
* [`shopify theme language-server`](#shopify-theme-language-server)
Expand Down Expand Up @@ -1895,6 +1898,92 @@ DESCRIPTION
(https://shopify.dev/docs/themes/tools/cli#directory-structure).
```

## `shopify theme generate block`

Creates and adds a new block file to your local theme directory

```
USAGE
$ shopify theme generate block [-n <value>] [--no-color] [--path <value>] [-t text|image|video|product|collection]
[--verbose]
FLAGS
-n, --name=<value> Name of the block
-t, --type=<option> Type of block to generate
<options: text|image|video|product|collection>
--no-color Disable color output.
--path=<value> The path to your theme directory.
--verbose Increase the verbosity of the output.
DESCRIPTION
Creates and adds a new block file to your local theme directory
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.
```

## `shopify theme generate section`

Creates and adds a new section file to your local theme directory

```
USAGE
$ shopify theme generate section [-n <value>] [--no-color] [--path <value>] [-t
featured-collection|image-with-text|rich-text|custom] [--verbose]
FLAGS
-n, --name=<value> Name of the section
-t, --type=<option> Type of section to generate
<options: featured-collection|image-with-text|rich-text|custom>
--no-color Disable color output.
--path=<value> The path to your theme directory.
--verbose Increase the verbosity of the output.
DESCRIPTION
Creates and adds a new section file to your local theme directory
Creates a new "theme section" (https://shopify.dev/docs/themes/architecture/sections) in your local theme directory.
The section is created in the `sections` directory with the basic structure needed, including schema, settings, and
blocks.
You can specify the type of section to generate using the `--type` flag. The section will be created with appropriate
default settings and blocks based on the type.
```

## `shopify theme generate template`

Creates and adds a new template file to your local theme directory

```
USAGE
$ shopify theme generate template [-n <value>] [--no-color] [--path <value>] [-t
product|collection|page|blog|article|custom] [--verbose]
FLAGS
-n, --name=<value> Name of the template
-t, --type=<option> Type of template to generate
<options: product|collection|page|blog|article|custom>
--no-color Disable color output.
--path=<value> The path to your theme directory.
--verbose Increase the verbosity of the output.
DESCRIPTION
Creates and adds a new template file to your local theme directory
Creates a new "theme template" (https://shopify.dev/docs/themes/architecture/templates) in your local theme directory.
The template is created in the `templates` directory with the basic structure needed, including layout and content
sections.
You can specify the type of template to generate using the `--type` flag. The template will be created with
appropriate default sections based on the type.
```

## `shopify theme info`

Displays information about your theme environment, including your current store. Can also retrieve information about a specific theme.
Expand Down
210 changes: 210 additions & 0 deletions packages/cli/oclif.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5317,6 +5317,216 @@
"strict": true,
"summary": "Uploads the current theme as a development theme to the connected store, then prints theme editor and preview URLs to your terminal. While running, changes will push to the store in real time."
},
"theme:generate:block": {
"aliases": [
],
"args": {
},
"customPluginName": "@shopify/theme",
"description": "Creates a new \"theme block\" (https://shopify.dev/docs/themes/architecture/blocks) in your local theme directory.\n\n The block is created in the `blocks` directory with the basic structure needed, including schema and settings.\n\n 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.",
"descriptionWithMarkdown": "Creates a new [theme block](https://shopify.dev/docs/themes/architecture/blocks) in your local theme directory.\n\n The block is created in the `blocks` directory with the basic structure needed, including schema and settings.\n\n 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.",
"flags": {
"name": {
"char": "n",
"description": "Name of the block",
"env": "SHOPIFY_FLAG_BLOCK_NAME",
"hasDynamicHelp": false,
"multiple": false,
"name": "name",
"type": "option"
},
"no-color": {
"allowNo": false,
"description": "Disable color output.",
"env": "SHOPIFY_FLAG_NO_COLOR",
"hidden": false,
"name": "no-color",
"type": "boolean"
},
"path": {
"description": "The path to your theme directory.",
"env": "SHOPIFY_FLAG_PATH",
"hasDynamicHelp": false,
"multiple": false,
"name": "path",
"noCacheDefault": true,
"type": "option"
},
"type": {
"char": "t",
"description": "Type of block to generate",
"env": "SHOPIFY_FLAG_BLOCK_TYPE",
"hasDynamicHelp": false,
"multiple": false,
"name": "type",
"options": [
"text",
"image",
"video",
"product",
"collection"
],
"type": "option"
},
"verbose": {
"allowNo": false,
"description": "Increase the verbosity of the output.",
"env": "SHOPIFY_FLAG_VERBOSE",
"hidden": false,
"name": "verbose",
"type": "boolean"
}
},
"hasDynamicHelp": false,
"hiddenAliases": [
],
"id": "theme:generate:block",
"pluginAlias": "@shopify/cli",
"pluginName": "@shopify/cli",
"pluginType": "core",
"strict": true,
"summary": "Creates and adds a new block file to your local theme directory"
},
"theme:generate:section": {
"aliases": [
],
"args": {
},
"customPluginName": "@shopify/theme",
"description": "Creates a new \"theme section\" (https://shopify.dev/docs/themes/architecture/sections) in your local theme directory.\n\n The section is created in the `sections` directory with the basic structure needed, including schema, settings, and blocks.\n\n You can specify the type of section to generate using the `--type` flag. The section will be created with appropriate default settings and blocks based on the type.",
"descriptionWithMarkdown": "Creates a new [theme section](https://shopify.dev/docs/themes/architecture/sections) in your local theme directory.\n\n The section is created in the `sections` directory with the basic structure needed, including schema, settings, and blocks.\n\n You can specify the type of section to generate using the `--type` flag. The section will be created with appropriate default settings and blocks based on the type.",
"flags": {
"name": {
"char": "n",
"description": "Name of the section",
"env": "SHOPIFY_FLAG_SECTION_NAME",
"hasDynamicHelp": false,
"multiple": false,
"name": "name",
"type": "option"
},
"no-color": {
"allowNo": false,
"description": "Disable color output.",
"env": "SHOPIFY_FLAG_NO_COLOR",
"hidden": false,
"name": "no-color",
"type": "boolean"
},
"path": {
"description": "The path to your theme directory.",
"env": "SHOPIFY_FLAG_PATH",
"hasDynamicHelp": false,
"multiple": false,
"name": "path",
"noCacheDefault": true,
"type": "option"
},
"type": {
"char": "t",
"description": "Type of section to generate",
"env": "SHOPIFY_FLAG_SECTION_TYPE",
"hasDynamicHelp": false,
"multiple": false,
"name": "type",
"options": [
"featured-collection",
"image-with-text",
"rich-text",
"custom"
],
"type": "option"
},
"verbose": {
"allowNo": false,
"description": "Increase the verbosity of the output.",
"env": "SHOPIFY_FLAG_VERBOSE",
"hidden": false,
"name": "verbose",
"type": "boolean"
}
},
"hasDynamicHelp": false,
"hiddenAliases": [
],
"id": "theme:generate:section",
"pluginAlias": "@shopify/cli",
"pluginName": "@shopify/cli",
"pluginType": "core",
"strict": true,
"summary": "Creates and adds a new section file to your local theme directory"
},
"theme:generate:template": {
"aliases": [
],
"args": {
},
"customPluginName": "@shopify/theme",
"description": "Creates a new \"theme template\" (https://shopify.dev/docs/themes/architecture/templates) in your local theme directory.\n\n The template is created in the `templates` directory with the basic structure needed, including layout and content sections.\n\n You can specify the type of template to generate using the `--type` flag. The template will be created with appropriate default sections based on the type.",
"descriptionWithMarkdown": "Creates a new [theme template](https://shopify.dev/docs/themes/architecture/templates) in your local theme directory.\n\n The template is created in the `templates` directory with the basic structure needed, including layout and content sections.\n\n You can specify the type of template to generate using the `--type` flag. The template will be created with appropriate default sections based on the type.",
"flags": {
"name": {
"char": "n",
"description": "Name of the template",
"env": "SHOPIFY_FLAG_TEMPLATE_NAME",
"hasDynamicHelp": false,
"multiple": false,
"name": "name",
"type": "option"
},
"no-color": {
"allowNo": false,
"description": "Disable color output.",
"env": "SHOPIFY_FLAG_NO_COLOR",
"hidden": false,
"name": "no-color",
"type": "boolean"
},
"path": {
"description": "The path to your theme directory.",
"env": "SHOPIFY_FLAG_PATH",
"hasDynamicHelp": false,
"multiple": false,
"name": "path",
"noCacheDefault": true,
"type": "option"
},
"type": {
"char": "t",
"description": "Type of template to generate",
"env": "SHOPIFY_FLAG_TEMPLATE_TYPE",
"hasDynamicHelp": false,
"multiple": false,
"name": "type",
"options": [
"product",
"collection",
"page",
"blog",
"article",
"custom"
],
"type": "option"
},
"verbose": {
"allowNo": false,
"description": "Increase the verbosity of the output.",
"env": "SHOPIFY_FLAG_VERBOSE",
"hidden": false,
"name": "verbose",
"type": "boolean"
}
},
"hasDynamicHelp": false,
"hiddenAliases": [
],
"id": "theme:generate:template",
"pluginAlias": "@shopify/cli",
"pluginName": "@shopify/cli",
"pluginType": "core",
"strict": true,
"summary": "Creates and adds a new template file to your local theme directory"
},
"theme:info": {
"aliases": [
],
Expand Down
57 changes: 57 additions & 0 deletions packages/theme/src/cli/commands/theme/generate/block.ts
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}`],
})
}
}
Loading

0 comments on commit 7228cbe

Please sign in to comment.