Skip to content

Commit

Permalink
Add --dev-preview flag to theme init for framework theme support
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmengo committed Dec 11, 2024
1 parent 39e1017 commit 4ed31c8
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs-shopify.dev/commands/interfaces/theme-init.interface.ts
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 @@ -1933,6 +1933,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
59 changes: 59 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,59 @@
import Init 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('https://github.com/Shopify/framework-theme.git', 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(
'https://github.com/Shopify/dawn.git',
expect.any(String),
)
})
})
})
10 changes: 9 additions & 1 deletion packages/theme/src/cli/commands/theme/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,22 @@ export default class Init extends ThemeCommand {
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 57 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#L57

[@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'] !== 'https://github.com/Shopify/dawn.git'
const repoUrl = !cloneUrlProvided && flags['dev-preview'] ? FRAMEWORK_THEME_REPO_URL : flags['clone-url']

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

0 comments on commit 4ed31c8

Please sign in to comment.