Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --dev-preview flag to theme init for framework theme support #5079

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ export interface themeinit {
*/
'-u, --clone-url <value>'?: string

/**
* Uses the new framework theme as the default clone-url
* @environment SHOPIFY_FLAG_CLONE_URL
*/
'-p, --dev-preview'?: ''

/**
* Downloads the latest release of the `clone-url`
* @environment SHOPIFY_FLAG_LATEST
Expand Down
11 changes: 10 additions & 1 deletion docs-shopify.dev/generated/generated_docs_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -5337,6 +5337,15 @@
"isOptional": true,
"environmentValue": "SHOPIFY_FLAG_LATEST"
},
{
"filePath": "docs-shopify.dev/commands/interfaces/theme-init.interface.ts",
"syntaxKind": "PropertySignature",
"name": "-p, --dev-preview",
"value": "\"\"",
"description": "Uses the new framework theme as the default clone-url",
"isOptional": true,
"environmentValue": "SHOPIFY_FLAG_CLONE_URL"
},
{
"filePath": "docs-shopify.dev/commands/interfaces/theme-init.interface.ts",
"syntaxKind": "PropertySignature",
Expand All @@ -5347,7 +5356,7 @@
"environmentValue": "SHOPIFY_FLAG_CLONE_URL"
}
],
"value": "export interface themeinit {\n /**\n * The Git URL to clone from. Defaults to Shopify's example theme, Dawn: https://github.com/Shopify/dawn.git\n * @environment SHOPIFY_FLAG_CLONE_URL\n */\n '-u, --clone-url <value>'?: string\n\n /**\n * Downloads the latest release of the `clone-url`\n * @environment SHOPIFY_FLAG_LATEST\n */\n '-l, --latest'?: ''\n\n /**\n * Disable color output.\n * @environment SHOPIFY_FLAG_NO_COLOR\n */\n '--no-color'?: ''\n\n /**\n * The path to your theme directory.\n * @environment SHOPIFY_FLAG_PATH\n */\n '--path <value>'?: string\n\n /**\n * Increase the verbosity of the output.\n * @environment SHOPIFY_FLAG_VERBOSE\n */\n '--verbose'?: ''\n}"
"value": "export interface themeinit {\n /**\n * The Git URL to clone from. Defaults to Shopify's example theme, Dawn: https://github.com/Shopify/dawn.git\n * @environment SHOPIFY_FLAG_CLONE_URL\n */\n '-u, --clone-url <value>'?: string\n\n /**\n * Uses the new framework theme as the default clone-url\n * @environment SHOPIFY_FLAG_CLONE_URL\n */\n '-p, --dev-preview'?: ''\n\n /**\n * Downloads the latest release of the `clone-url`\n * @environment SHOPIFY_FLAG_LATEST\n */\n '-l, --latest'?: ''\n\n /**\n * Disable color output.\n * @environment SHOPIFY_FLAG_NO_COLOR\n */\n '--no-color'?: ''\n\n /**\n * The path to your theme directory.\n * @environment SHOPIFY_FLAG_PATH\n */\n '--path <value>'?: string\n\n /**\n * Increase the verbosity of the output.\n * @environment SHOPIFY_FLAG_VERBOSE\n */\n '--verbose'?: ''\n}"
}
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1934,6 +1934,7 @@ ARGUMENTS

FLAGS
-l, --latest Downloads the latest release of the `clone-url`
-p, --dev-preview Uses the new framework theme as the default clone-url
-u, --clone-url=<value> [default: https://github.com/Shopify/dawn.git] The Git URL to clone from. Defaults to
Shopify's example theme, Dawn: https://github.com/Shopify/dawn.git
--no-color Disable color output.
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/oclif.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5427,6 +5427,14 @@
"name": "clone-url",
"type": "option"
},
"dev-preview": {
"allowNo": false,
"char": "p",
"description": "Uses the new framework theme as the default clone-url",
"env": "SHOPIFY_FLAG_CLONE_URL",
"name": "dev-preview",
"type": "boolean"
},
"latest": {
"allowNo": false,
"char": "l",
Expand Down
56 changes: 56 additions & 0 deletions packages/theme/src/cli/commands/theme/init.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import Init, {DEFAULT_THEME_REPO_URL, FRAMEWORK_THEME_REPO_URL} from './init.js'
import {cloneRepo, cloneRepoAndCheckoutLatestTag} from '../../services/init.js'
import {describe, expect, vi, test} from 'vitest'
import {Config} from '@oclif/core'

vi.mock('../../services/init.js')
vi.mock('@shopify/cli-kit/node/ui')

const CommandConfig = new Config({root: './'})

describe('Init', () => {
const path = '.'

async function run(argv: string[]) {
await CommandConfig.load()
const init = new Init([`--path=${path}`, ...argv], CommandConfig)
return init.run()
}

describe('dev-preview flag', () => {
test('uses framework theme when dev-preview flag is true and default clone-url is not provided', async () => {
// Given
const flags = ['--dev-preview']

// When
await run(flags)

// Then
expect(cloneRepo).toHaveBeenCalledWith(FRAMEWORK_THEME_REPO_URL, expect.any(String))
})

test('uses provided clone-url when custom url is provided, regardless of dev-preview flag', async () => {
// Given
const flags = ['--dev-preview', '--clone-url=https://github.com/org/theme.git']

// When
await run(flags)

// Then
expect(cloneRepo).toHaveBeenCalledWith('https://github.com/org/theme.git', expect.any(String))
})
})

describe('latest flag', () => {
test('uses cloneRepoAndCheckoutLatestTag when latest flag is true', async () => {
// Given
const flags = ['--latest']

// When
await run(flags)

// Then
expect(cloneRepoAndCheckoutLatestTag).toHaveBeenCalledWith(DEFAULT_THEME_REPO_URL, expect.any(String))
})
})
})
18 changes: 14 additions & 4 deletions packages/theme/src/cli/commands/theme/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import {renderTextPrompt} from '@shopify/cli-kit/node/ui'
import {joinPath} from '@shopify/cli-kit/node/path'

export const DEFAULT_THEME_REPO_URL = 'https://github.com/Shopify/dawn.git'
export const FRAMEWORK_THEME_REPO_URL = 'https://github.com/Shopify/theme-blocks-accelerator.git'

export default class Init extends ThemeCommand {
static summary = 'Clones a Git repository to use as a starting point for building a new theme.'

Expand Down Expand Up @@ -34,24 +37,31 @@
path: themeFlags.path,
'clone-url': Flags.string({
char: 'u',
default: 'https://github.com/Shopify/dawn.git',
description:
"The Git URL to clone from. Defaults to Shopify's example theme, Dawn: https://github.com/Shopify/dawn.git",
default: DEFAULT_THEME_REPO_URL,
description: `The Git URL to clone from. Defaults to Shopify's example theme, Dawn: ${DEFAULT_THEME_REPO_URL}`,
env: 'SHOPIFY_FLAG_CLONE_URL',
}),
latest: Flags.boolean({
char: 'l',
description: 'Downloads the latest release of the `clone-url`',
env: 'SHOPIFY_FLAG_LATEST',
}),
'dev-preview': Flags.boolean({
char: 'p',
default: false,
description: 'Uses the new framework theme as the default clone-url',
env: 'SHOPIFY_FLAG_CLONE_URL',
}),
}

async run(): Promise<void> {
const {args, flags} = await this.parse(Init)
const name = args.name || (await this.promptName(flags.path))

Check warning on line 59 in packages/theme/src/cli/commands/theme/init.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/theme/src/cli/commands/theme/init.ts#L59

[@typescript-eslint/prefer-nullish-coalescing] Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator.
const repoUrl = flags['clone-url']
const destination = joinPath(flags.path, name)

const cloneUrlProvided = flags['clone-url'] !== DEFAULT_THEME_REPO_URL
const repoUrl = !cloneUrlProvided && flags['dev-preview'] ? FRAMEWORK_THEME_REPO_URL : flags['clone-url']

if (flags.latest) {
await cloneRepoAndCheckoutLatestTag(repoUrl, destination)
} else {
Expand Down
Loading