Skip to content

Commit

Permalink
Add no-logs flag to the theme dev commands
Browse files Browse the repository at this point in the history
This commit adds a `--no-logs` flag to the `theme dev` command.
When this flag is passed, it will disable request logging.
  • Loading branch information
EvilGenius13 committed Nov 25, 2024
1 parent ecb0b9d commit 8cbbac5
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-fans-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/theme': minor
---

Add no-logs flag to theme dev command to disable request logs
6 changes: 6 additions & 0 deletions docs-shopify.dev/commands/interfaces/theme-dev.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export interface themedev {
*/
'--no-color'?: ''

/**
* Disable request logs.
* @environment SHOPIFY_FLAG_NO_LOGS
*/
'--no-logs'?: ''

/**
* Prevents files from being deleted in the remote theme when a file has been deleted locally. This applies to files that are deleted while the command is running, and files that have been deleted locally before the command is run.
* @environment SHOPIFY_FLAG_NODELETE
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 @@ -4829,6 +4829,15 @@
"isOptional": true,
"environmentValue": "SHOPIFY_FLAG_NO_COLOR"
},
{
"filePath": "docs-shopify.dev/commands/interfaces/theme-dev.interface.ts",
"syntaxKind": "PropertySignature",
"name": "--no-logs",
"value": "\"\"",
"description": "Disable request logs.",
"isOptional": true,
"environmentValue": "SHOPIFY_FLAG_NO_LOGS"
},
{
"filePath": "docs-shopify.dev/commands/interfaces/theme-dev.interface.ts",
"syntaxKind": "PropertySignature",
Expand Down Expand Up @@ -4956,7 +4965,7 @@
"environmentValue": "SHOPIFY_FLAG_IGNORE"
}
],
"value": "export interface themedev {\n /**\n * The environment to apply to the current command.\n * @environment SHOPIFY_FLAG_ENVIRONMENT\n */\n '-e, --environment <value>'?: string\n\n /**\n * Set which network interface the web server listens on. The default value is 127.0.0.1.\n * @environment SHOPIFY_FLAG_HOST\n */\n '--host <value>'?: string\n\n /**\n * Skip hot reloading any files that match the specified pattern.\n * @environment SHOPIFY_FLAG_IGNORE\n */\n '-x, --ignore <value>'?: string\n\n /**\n * The live reload mode switches the server behavior when a file is modified:\n- hot-reload Hot reloads local changes to CSS and sections (default)\n- full-page Always refreshes the entire page\n- off Deactivate live reload\n * @environment SHOPIFY_FLAG_LIVE_RELOAD\n */\n '--live-reload <value>'?: string\n\n /**\n * Disable color output.\n * @environment SHOPIFY_FLAG_NO_COLOR\n */\n '--no-color'?: ''\n\n /**\n * Prevents files from being deleted in the remote theme when a file has been deleted locally. This applies to files that are deleted while the command is running, and files that have been deleted locally before the command is run.\n * @environment SHOPIFY_FLAG_NODELETE\n */\n '-n, --nodelete'?: ''\n\n /**\n * The file path or URL. The file path is to a file that you want updated on idle. The URL path is where you want a webhook posted to report on file changes.\n * @environment SHOPIFY_FLAG_NOTIFY\n */\n '--notify <value>'?: string\n\n /**\n * Hot reload only files that match the specified pattern.\n * @environment SHOPIFY_FLAG_ONLY\n */\n '-o, --only <value>'?: string\n\n /**\n * Automatically launch the theme preview in your default web browser.\n * @environment SHOPIFY_FLAG_OPEN\n */\n '--open'?: ''\n\n /**\n * Password generated from the Theme Access app.\n * @environment SHOPIFY_CLI_THEME_TOKEN\n */\n '--password <value>'?: string\n\n /**\n * The path to your theme directory.\n * @environment SHOPIFY_FLAG_PATH\n */\n '--path <value>'?: string\n\n /**\n * Local port to serve theme preview from.\n * @environment SHOPIFY_FLAG_PORT\n */\n '--port <value>'?: string\n\n /**\n * Store URL. It can be the store prefix (example) or the full myshopify.com URL (example.myshopify.com, https://example.myshopify.com).\n * @environment SHOPIFY_FLAG_STORE\n */\n '-s, --store <value>'?: string\n\n /**\n * The password for storefronts with password protection.\n * @environment SHOPIFY_FLAG_STORE_PASSWORD\n */\n '--store-password <value>'?: string\n\n /**\n * Theme ID or name of the remote theme.\n * @environment SHOPIFY_FLAG_THEME_ID\n */\n '-t, --theme <value>'?: string\n\n /**\n * Synchronize Theme Editor updates in the local theme files.\n * @environment SHOPIFY_FLAG_THEME_EDITOR_SYNC\n */\n '--theme-editor-sync'?: ''\n\n /**\n * Increase the verbosity of the output.\n * @environment SHOPIFY_FLAG_VERBOSE\n */\n '--verbose'?: ''\n}"
"value": "export interface themedev {\n /**\n * The environment to apply to the current command.\n * @environment SHOPIFY_FLAG_ENVIRONMENT\n */\n '-e, --environment <value>'?: string\n\n /**\n * Set which network interface the web server listens on. The default value is 127.0.0.1.\n * @environment SHOPIFY_FLAG_HOST\n */\n '--host <value>'?: string\n\n /**\n * Skip hot reloading any files that match the specified pattern.\n * @environment SHOPIFY_FLAG_IGNORE\n */\n '-x, --ignore <value>'?: string\n\n /**\n * The live reload mode switches the server behavior when a file is modified:\n- hot-reload Hot reloads local changes to CSS and sections (default)\n- full-page Always refreshes the entire page\n- off Deactivate live reload\n * @environment SHOPIFY_FLAG_LIVE_RELOAD\n */\n '--live-reload <value>'?: string\n\n /**\n * Disable color output.\n * @environment SHOPIFY_FLAG_NO_COLOR\n */\n '--no-color'?: ''\n\n /**\n * Disable request logs.\n * @environment SHOPIFY_FLAG_NO_LOGS\n */\n '--no-logs'?: ''\n\n /**\n * Prevents files from being deleted in the remote theme when a file has been deleted locally. This applies to files that are deleted while the command is running, and files that have been deleted locally before the command is run.\n * @environment SHOPIFY_FLAG_NODELETE\n */\n '-n, --nodelete'?: ''\n\n /**\n * The file path or URL. The file path is to a file that you want updated on idle. The URL path is where you want a webhook posted to report on file changes.\n * @environment SHOPIFY_FLAG_NOTIFY\n */\n '--notify <value>'?: string\n\n /**\n * Hot reload only files that match the specified pattern.\n * @environment SHOPIFY_FLAG_ONLY\n */\n '-o, --only <value>'?: string\n\n /**\n * Automatically launch the theme preview in your default web browser.\n * @environment SHOPIFY_FLAG_OPEN\n */\n '--open'?: ''\n\n /**\n * Password generated from the Theme Access app.\n * @environment SHOPIFY_CLI_THEME_TOKEN\n */\n '--password <value>'?: string\n\n /**\n * The path to your theme directory.\n * @environment SHOPIFY_FLAG_PATH\n */\n '--path <value>'?: string\n\n /**\n * Local port to serve theme preview from.\n * @environment SHOPIFY_FLAG_PORT\n */\n '--port <value>'?: string\n\n /**\n * Store URL. It can be the store prefix (example) or the full myshopify.com URL (example.myshopify.com, https://example.myshopify.com).\n * @environment SHOPIFY_FLAG_STORE\n */\n '-s, --store <value>'?: string\n\n /**\n * The password for storefronts with password protection.\n * @environment SHOPIFY_FLAG_STORE_PASSWORD\n */\n '--store-password <value>'?: string\n\n /**\n * Theme ID or name of the remote theme.\n * @environment SHOPIFY_FLAG_THEME_ID\n */\n '-t, --theme <value>'?: string\n\n /**\n * Synchronize Theme Editor updates in the local theme files.\n * @environment SHOPIFY_FLAG_THEME_EDITOR_SYNC\n */\n '--theme-editor-sync'?: ''\n\n /**\n * Increase the verbosity of the output.\n * @environment SHOPIFY_FLAG_VERBOSE\n */\n '--verbose'?: ''\n}"
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1768,8 +1768,8 @@ Uploads the current theme as a development theme to the connected store, then pr
```
USAGE
$ shopify theme dev [-e <value>] [--host <value>] [-x <value>] [--live-reload hot-reload|full-page|off]
[--no-color] [-n] [--notify <value>] [-o <value>] [--open] [--password <value>] [--path <value>] [--port <value>]
[-s <value>] [--store-password <value>] [-t <value>] [--theme-editor-sync] [--verbose]
[--no-color] [--no-logs] [-n] [--notify <value>] [-o <value>] [--open] [--password <value>] [--path <value>] [--port
<value>] [-s <value>] [--store-password <value>] [-t <value>] [--theme-editor-sync] [--verbose]
FLAGS
-e, --environment=<value>
Expand Down Expand Up @@ -1805,6 +1805,9 @@ FLAGS
--no-color
Disable color output.
--no-logs
Disable request logs.
--notify=<value>
The file path or URL. The file path is to a file that you want updated on idle. The URL path is where you want a
webhook posted to report on file changes.
Expand Down
14 changes: 14 additions & 0 deletions packages/cli/oclif.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4903,6 +4903,13 @@
"name": "no-color",
"type": "boolean"
},
"no-logs": {
"allowNo": false,
"description": "Disable request logs.",
"env": "SHOPIFY_FLAG_NO_LOGS",
"name": "no-logs",
"type": "boolean"
},
"nodelete": {
"allowNo": false,
"char": "n",
Expand Down Expand Up @@ -5985,6 +5992,13 @@
"name": "no-color",
"type": "boolean"
},
"no-logs": {
"allowNo": false,
"description": "Disable request logs.",
"env": "SHOPIFY_FLAG_NO_LOGS",
"name": "no-logs",
"type": "boolean"
},
"nodelete": {
"allowNo": false,
"char": "n",
Expand Down
5 changes: 5 additions & 0 deletions packages/theme/src/cli/commands/theme/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ You can run this command only in a directory that matches the [default Shopify t
description: 'The password for storefronts with password protection.',
env: 'SHOPIFY_FLAG_STORE_PASSWORD',
}),
'no-logs': Flags.boolean({
description: 'Disable request logs.',
env: 'SHOPIFY_FLAG_NO_LOGS',
}),
}

async run(): Promise<void> {
Expand Down Expand Up @@ -153,6 +157,7 @@ You can run this command only in a directory that matches the [default Shopify t
ignore,
only,
notify: flags.notify,
noLogs: flags['no-logs'],
})
}
}
26 changes: 26 additions & 0 deletions packages/theme/src/cli/services/dev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {ensureValidPassword} from '../utilities/theme-environment/storefront-pas
import {emptyThemeExtFileSystem} from '../utilities/theme-fs-empty.js'
import {initializeDevServerSession} from '../utilities/theme-environment/dev-server-session.js'
import {DevServerSession} from '../utilities/theme-environment/types.js'
import {logRequestLine} from '../utilities/log-request-line.js'
import {describe, expect, test, vi} from 'vitest'
import {buildTheme} from '@shopify/cli-kit/node/themes/factories'
import {DEVELOPMENT_THEME_ROLE} from '@shopify/cli-kit/node/themes/utils'
Expand All @@ -22,6 +23,7 @@ vi.mock('../utilities/theme-environment/storefront-session.js')
vi.mock('../utilities/theme-environment/theme-environment.js')
vi.mock('../utilities/theme-fs-empty.js')
vi.mock('../utilities/theme-fs.js')
vi.mock('../utilities/log-request-line.js')
vi.mock('@shopify/cli-kit/node/colors', () => ({
default: {
bold: (str: string) => str,
Expand Down Expand Up @@ -101,11 +103,35 @@ describe('dev', () => {
ignore: [],
noDelete: false,
only: [],
noLogs: false,
},
})
})
})

test('does not log requests and responses when the `no-logs` option is true', async () => {
// Given
vi.mocked(initializeDevServerSession).mockResolvedValue(session)
vi.mocked(isStorefrontPasswordProtected).mockResolvedValue(false)
vi.mocked(mountThemeFileSystem).mockReturnValue(localThemeFileSystem)
vi.mocked(emptyThemeExtFileSystem).mockReturnValue(localThemeExtensionFileSystem)
vi.mocked(logRequestLine).mockReturnValue(undefined)
vi.mocked(setupDevServer).mockReturnValue({
workPromise: Promise.resolve(),
renderDevSetupProgress: () => Promise.resolve(),
dispatchEvent: () => {},
serverStart: async () => ({close: async () => {}}),
})

const devOptions = {...options, 'no-logs': true}

// When
await dev(devOptions)

// Then
expect(logRequestLine).not.toHaveBeenCalled()
})

test('renders "dev" command links', async () => {
// Given
const themeId = theme.id.toString()
Expand Down
2 changes: 2 additions & 0 deletions packages/theme/src/cli/services/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface DevOptions {
ignore: string[]
only: string[]
notify?: string
noLogs?: boolean
}

export async function dev(options: DevOptions) {
Expand Down Expand Up @@ -91,6 +92,7 @@ export async function dev(options: DevOptions) {
noDelete: options.noDelete,
ignore: options.ignore,
only: options.only,
noLogs: options.noLogs ?? false,
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ function createTestContext(options?: {files?: [string, string][]}) {
liveReload: 'hot-reload',
open: false,
themeEditorSync: false,
noLogs: false,
},
}

Expand Down
4 changes: 3 additions & 1 deletion packages/theme/src/cli/utilities/theme-environment/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export function getHtmlHandler(theme: Theme, ctx: DevServerContext) {
replaceTemplates: getInMemoryTemplates(ctx, browserPathname, getCookie(event, 'localization')?.toLowerCase()),
})
.then(async (response) => {
logRequestLine(event, response)
if (!ctx.options.noLogs) {
logRequestLine(event, response)
}

let html = await patchRenderingResponse(ctx, event, response)

Expand Down
4 changes: 3 additions & 1 deletion packages/theme/src/cli/utilities/theme-environment/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ function proxyStorefrontRequest(event: H3Event, ctx: DevServerContext) {
redirect: 'manual',
},
async onResponse(event, response) {
logRequestLine(event, response)
if (!ctx.options.noLogs) {
logRequestLine(event, response)
}

patchProxiedResponseHeaders(ctx, event, response)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ describe('setupDevServer', () => {
liveReload: 'hot-reload',
open: false,
themeEditorSync: false,
noLogs: false,
},
}

Expand Down
5 changes: 5 additions & 0 deletions packages/theme/src/cli/utilities/theme-environment/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ export interface DevServerContext {
* Automatically open the theme preview in the default browser.
*/
open: boolean

/**
* Disable request logs.
*/
noLogs: boolean
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ async function contextDevServerContext(
port: port.toString(),
liveReload: 'hot-reload',
open: false,
noLogs: false,
},
}
}
Expand Down

0 comments on commit 8cbbac5

Please sign in to comment.