Skip to content
Merged
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
15 changes: 14 additions & 1 deletion packages/theme/src/cli/commands/theme/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,22 @@ Excludes checks matching any category when specified more than once`,
}),
}

static cli2Flags = [
'auto-correct',
'category',
'config',
'exclude-category',
'fail-level',
'init',
'list',
'output',
'print',
'version',
]

async run(): Promise<void> {
const {flags} = await this.parse(Check)
await execCLI2(['theme', 'check', flags.path, ...this.passThroughFlags(flags, {exclude: ['path', 'verbose']})], {
await execCLI2(['theme', 'check', flags.path, ...this.passThroughFlags(flags, {allowedFlags: Check.cli2Flags})], {
directory: flags.path,
})
}
Expand Down
4 changes: 3 additions & 1 deletion packages/theme/src/cli/commands/theme/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export default class Delete extends ThemeCommand {
store: themeFlags.store,
}

static cli2Flags = ['development', 'show-all', 'force']

async run(): Promise<void> {
const {flags, argv} = await this.parse(Delete)

Expand All @@ -43,7 +45,7 @@ export default class Delete extends ThemeCommand {
command.push(...argv)
}

const flagsToPass = this.passThroughFlags(flags, {exclude: ['store', 'verbose', 'password']})
const flagsToPass = this.passThroughFlags(flags, {allowedFlags: Delete.cli2Flags})
command.push(...flagsToPass)

const adminSession = await session.ensureAuthenticatedThemes(store, flags.password)
Expand Down
15 changes: 14 additions & 1 deletion packages/theme/src/cli/commands/theme/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,26 @@ export default class Dev extends ThemeCommand {
}),
}

static cli2Flags = [
'host',
'live-reload',
'poll',
'theme-editor-sync',
'port',
'theme',
'only',
'ignore',
'stable',
'force',
]

// Tokens are valid for 120m, better to be safe and refresh every 90min
ThemeRefreshTimeoutInMinutes = 90

async run(): Promise<void> {
const {flags} = await this.parse(Dev)

const flagsToPass = this.passThroughFlags(flags, {exclude: ['path', 'store', 'verbose']})
const flagsToPass = this.passThroughFlags(flags, {allowedFlags: Dev.cli2Flags})
const command = ['theme', 'serve', flags.path, ...flagsToPass]

const store = await getThemeStore(flags)
Expand Down
5 changes: 4 additions & 1 deletion packages/theme/src/cli/commands/theme/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ export default class Init extends ThemeCommand {
}),
}

static cli2Flags = ['clone-url']

async run(): Promise<void> {
const {args, flags} = await this.parse(Init)
const directory = flags.path ? path.resolve(flags.path) : process.cwd()
const name = args.name || (await this.promptName(directory))
const command = ['theme', 'init', name]
const flagsToPass = this.passThroughFlags(flags, {allowedFlags: Init.cli2Flags})
const command = ['theme', 'init', name, ...flagsToPass]
await execCLI2(command, {
directory,
})
Expand Down
4 changes: 3 additions & 1 deletion packages/theme/src/cli/commands/theme/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ export default class Open extends ThemeCommand {
store: themeFlags.store,
}

static cli2Flags = ['development', 'editor', 'live', 'theme']

async run(): Promise<void> {
const {flags} = await this.parse(Open)
const flagsToPass = this.passThroughFlags(flags, {exclude: ['store', 'verbose', 'password']})
const flagsToPass = this.passThroughFlags(flags, {allowedFlags: Open.cli2Flags})
const command = ['theme', 'open', ...flagsToPass]

const store = await getThemeStore(flags)
Expand Down
4 changes: 3 additions & 1 deletion packages/theme/src/cli/commands/theme/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ export default class Publish extends ThemeCommand {
store: themeFlags.store,
}

static cli2Flags = ['force']

async run(): Promise<void> {
const {flags, args} = await this.parse(Publish)

const store = await getThemeStore(flags)
const flagsToPass = this.passThroughFlags(flags, {exclude: ['path', 'store', 'verbose', 'password']})
const flagsToPass = this.passThroughFlags(flags, {allowedFlags: Publish.cli2Flags})
const command = ['theme', 'publish']
if (args.themeId) {
command.push(args.themeId)
Expand Down
4 changes: 3 additions & 1 deletion packages/theme/src/cli/commands/theme/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export default class Pull extends ThemeCommand {
}),
}

static cli2Flags = ['theme', 'development', 'live', 'nodelete', 'only', 'ignore', 'force']

async run(): Promise<void> {
const {flags} = await this.parse(Pull)

Expand All @@ -59,7 +61,7 @@ export default class Pull extends ThemeCommand {
validPath = path.resolve(flags.path)
}

const flagsToPass = this.passThroughFlags(flags, {exclude: ['path', 'verbose', 'store', 'password']})
const flagsToPass = this.passThroughFlags(flags, {allowedFlags: Pull.cli2Flags})

const command = ['theme', 'pull', validPath, ...flagsToPass]

Expand Down
17 changes: 16 additions & 1 deletion packages/theme/src/cli/commands/theme/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,25 @@ export default class Push extends ThemeCommand {
}),
}

static cli2Flags = [
'theme',
'development',
'live',
'unpublished',
'nodelete',
'only',
'ignore',
'json',
'allow-live',
'publish',
'stable',
'force',
]

async run(): Promise<void> {
const {flags} = await this.parse(Push)

const flagsToPass = this.passThroughFlags(flags, {exclude: ['path', 'store', 'verbose', 'password']})
const flagsToPass = this.passThroughFlags(flags, {allowedFlags: Push.cli2Flags})
const command = ['theme', 'push', flags.path, ...flagsToPass]

const store = await getThemeStore(flags)
Expand Down
10 changes: 8 additions & 2 deletions packages/theme/src/cli/commands/theme/share.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {themeFlags} from '../../flags.js'
import {getThemeStore} from '../../utilities/theme-store.js'
import ThemeCommand from '../../utilities/theme-command.js'
import {cli, session} from '@shopify/cli-kit'
import {cli, path, session} from '@shopify/cli-kit'
import {execCLI2} from '@shopify/cli-kit/node/ruby'
import {Flags} from '@oclif/core'

Expand All @@ -20,10 +20,16 @@ export default class Share extends ThemeCommand {
}),
}

static cli2Flags = ['force']

async run(): Promise<void> {
const {flags} = await this.parse(Share)
const directory = flags.path ? path.resolve(flags.path) : process.cwd()
const flagsToPass = this.passThroughFlags(flags, {allowedFlags: Share.cli2Flags})

const store = await getThemeStore(flags)
const adminSession = await session.ensureAuthenticatedThemes(store, flags.password)
await execCLI2(['theme', 'share', flags.path], {adminSession})

await execCLI2(['theme', 'share', directory, ...flagsToPass], {adminSession})
}
}
8 changes: 4 additions & 4 deletions packages/theme/src/cli/utilities/theme-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ interface FlagValues {
[key: string]: boolean | string | string[] | number | undefined
}
interface PassThroughFlagsOptions {
// Exclude flags that are only for CLI3 but will cause errors if passed to CLI2
exclude?: string[]
// Only pass on flags that are relevant to CLI2
allowedFlags?: string[]
}

export default abstract class ThemeCommand extends Command {
passThroughFlags(flags: FlagValues, {exclude}: PassThroughFlagsOptions): string[] {
passThroughFlags(flags: FlagValues, {allowedFlags}: PassThroughFlagsOptions): string[] {
const passThroughFlags: string[] = []
for (const [label, value] of Object.entries(flags)) {
if ((exclude ?? []).includes(label)) {
if (!(allowedFlags ?? []).includes(label)) {
continue
} else if (typeof value === 'boolean') {
if (value) passThroughFlags.push(`--${label}`)
Expand Down