Skip to content
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
29 changes: 27 additions & 2 deletions packages/theme/src/cli/commands/theme/profile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {themeFlags} from '../../flags.js'
import ThemeCommand, {RequiredFlags} from '../../utilities/theme-command.js'
import {profile} from '../../services/profile.js'
import {runProfileAnalysis} from '../../utilities/profile-analysis.js'
import {findOrSelectTheme} from '../../utilities/theme-selector.js'
import {renderTasksToStdErr} from '../../utilities/theme-ui.js'
import {Flags} from '@oclif/core'
Expand All @@ -13,11 +14,18 @@ type ProfileFlags = InferredFlags<typeof Profile.flags>
export default class Profile extends ThemeCommand {
static summary = 'Profile the Liquid rendering of a theme page.'

static usage = ['theme profile', 'theme profile --url /products/classic-leather-jacket']
static usage = [
'theme profile',
'theme profile --url /products/classic-leather-jacket',
'theme profile --analysis',
'theme profile --analysis --url /collections/all',
]

static descriptionWithMarkdown = `Profile the Shopify Liquid on a given page.

This command will open a web page with the Speedscope profiler detailing the time spent executing Liquid on the given page.`
This command opens an interactive flame graph showing the time spent executing Liquid on the given page.

Use the \`--analysis\` flag to display a human-readable breakdown of Liquid rendering performance directly in the terminal instead of opening the flame graph viewer.`

static description = this.descriptionWithoutMarkdown()

Expand All @@ -38,6 +46,12 @@ export default class Profile extends ThemeCommand {
description: 'The password for storefronts with password protection.',
env: 'SHOPIFY_FLAG_STORE_PASSWORD',
}),
analysis: Flags.boolean({
char: 'a',
description: 'Analyze the profile and display a summary of Liquid rendering performance in the terminal.',
env: 'SHOPIFY_FLAG_ANALYSIS',
default: false,
}),
...jsonFlag,
}

Expand All @@ -54,6 +68,17 @@ export default class Profile extends ThemeCommand {
}
const theme = await findOrSelectTheme(adminSession, filter)

if (flags.analysis) {
await runProfileAnalysis({
adminSession,
themeId: theme.id.toString(),
url: flags.url,
themeAccessPassword,
storefrontPassword: flags['store-password'],
})
return
}

const tasks: Task[] = [
{
title: `Generating Liquid profile for ${adminSession.storeFqdn} ${flags.url}`,
Expand Down
Loading
Loading