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
5 changes: 5 additions & 0 deletions .changeset/auto-upgrade-on-json.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/cli': minor
---

Add typed JSON output to `config autoupgrade on`.
38 changes: 37 additions & 1 deletion docs-shopify.dev/generated/generated_docs_data_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -4381,9 +4381,45 @@
"description": "Print the command's JSON schemas.",
"isOptional": true,
"environmentValue": "SHOPIFY_FLAG_JSON_SCHEMA"
},
{
"filePath": "docs-shopify.dev/commands/interfaces/config-autoupgrade-on.interface.ts",
"syntaxKind": "PropertySignature",
"name": "--no-color",
"value": "''",
"description": "Disable color output.",
"isOptional": true,
"environmentValue": "SHOPIFY_FLAG_NO_COLOR"
},
{
"filePath": "docs-shopify.dev/commands/interfaces/config-autoupgrade-on.interface.ts",
"syntaxKind": "PropertySignature",
"name": "--no-input",
"value": "''",
"description": "Disable interactive prompts and browser authentication.",
"isOptional": true,
"environmentValue": "SHOPIFY_FLAG_NO_INPUT"
},
{
"filePath": "docs-shopify.dev/commands/interfaces/config-autoupgrade-on.interface.ts",
"syntaxKind": "PropertySignature",
"name": "--verbose",
"value": "''",
"description": "Increase the verbosity of the output. May include sensitive data.",
"isOptional": true,
"environmentValue": "SHOPIFY_FLAG_VERBOSE"
},
{
"filePath": "docs-shopify.dev/commands/interfaces/config-autoupgrade-on.interface.ts",
"syntaxKind": "PropertySignature",
"name": "-j, --json",
"value": "''",
"description": "Output the result as JSON. Automatically disables color output.",
"isOptional": true,
"environmentValue": "SHOPIFY_FLAG_JSON"
}
],
"value": "export interface configautoupgradeon {\n /**\n * Print the command's JSON schemas.\n * @environment SHOPIFY_FLAG_JSON_SCHEMA\n */\n '--json-schema'?: ''\n}"
"value": "export interface configautoupgradeon {\n /**\n * Output the result as JSON. Automatically disables color output.\n * @environment SHOPIFY_FLAG_JSON\n */\n '-j, --json'?: ''\n\n /**\n * Print the command's JSON schemas.\n * @environment SHOPIFY_FLAG_JSON_SCHEMA\n */\n '--json-schema'?: ''\n\n /**\n * Disable color output.\n * @environment SHOPIFY_FLAG_NO_COLOR\n */\n '--no-color'?: ''\n\n /**\n * Disable interactive prompts and browser authentication.\n * @environment SHOPIFY_FLAG_NO_INPUT\n */\n '--no-input'?: ''\n\n /**\n * Increase the verbosity of the output. May include sensitive data.\n * @environment SHOPIFY_FLAG_VERBOSE\n */\n '--verbose'?: ''\n}"
}
},
"configautoupgradestatus": {
Expand Down
40 changes: 39 additions & 1 deletion packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3878,13 +3878,29 @@ Enable automatic upgrades for Shopify CLI.

```
USAGE
$ shopify config autoupgrade on [--json-schema]
$ shopify config autoupgrade on [-j] [--json-schema] [--no-color] [--no-input] [--verbose]

FLAGS
-j, --json
Output the result as JSON. Automatically disables color output.
[env: SHOPIFY_FLAG_JSON]

--json-schema
Print the command's JSON schemas.
[env: SHOPIFY_FLAG_JSON_SCHEMA]

--no-color
Disable color output.
[env: SHOPIFY_FLAG_NO_COLOR]

--no-input
Disable interactive prompts and browser authentication.
[env: SHOPIFY_FLAG_NO_INPUT]

--verbose
Increase the verbosity of the output. May include sensitive data.
[env: SHOPIFY_FLAG_VERBOSE]

DESCRIPTION
Enable automatic upgrades for Shopify CLI.

Expand All @@ -3894,6 +3910,28 @@ DESCRIPTION
upgrades are skipped and must be done manually.

To disable auto-upgrade, run `shopify config autoupgrade off`.


Use `--json-schema` to print the result, error, and event schemas.

Output from `--json` conforms to the `AutoUpgradeResult` schema.

```json
{
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
}
},
"required": [
"enabled"
],
"additionalProperties": false,
"title": "AutoUpgradeResult",
"$schema": "http://json-schema.org/draft-07/schema#"
}
```
```

## `shopify config autoupgrade status`
Expand Down
34 changes: 33 additions & 1 deletion packages/cli/oclif.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5831,16 +5831,48 @@
],
"args": {
},
"description": "Enable automatic upgrades for Shopify CLI.\n\n When auto-upgrade is enabled, Shopify CLI automatically updates to the latest version once per day. Major version upgrades are skipped and must be done manually.\n\n To disable auto-upgrade, run `shopify config autoupgrade off`.\n",
"description": "Enable automatic upgrades for Shopify CLI.\n\n When auto-upgrade is enabled, Shopify CLI automatically updates to the latest version once per day. Major version upgrades are skipped and must be done manually.\n\n To disable auto-upgrade, run `shopify config autoupgrade off`.\n\n\nUse `--json-schema` to print the result, error, and event schemas.\n\nOutput from `--json` conforms to the `AutoUpgradeResult` schema.\n\n```json\n{\n \"type\": \"object\",\n \"properties\": {\n \"enabled\": {\n \"type\": \"boolean\"\n }\n },\n \"required\": [\n \"enabled\"\n ],\n \"additionalProperties\": false,\n \"title\": \"AutoUpgradeResult\",\n \"$schema\": \"http://json-schema.org/draft-07/schema#\"\n}\n```",
"descriptionWithMarkdown": "Enable automatic upgrades for Shopify CLI.\n\n When auto-upgrade is enabled, Shopify CLI automatically updates to the latest version once per day. Major version upgrades are skipped and must be done manually.\n\n To disable auto-upgrade, run `shopify config autoupgrade off`.\n",
"enableJsonFlag": false,
"flags": {
"json": {
"allowNo": false,
"char": "j",
"description": "Output the result as JSON. Automatically disables color output.",
"env": "SHOPIFY_FLAG_JSON",
"hidden": false,
"name": "json",
"type": "boolean"
},
"json-schema": {
"allowNo": false,
"description": "Print the command's JSON schemas.",
"env": "SHOPIFY_FLAG_JSON_SCHEMA",
"name": "json-schema",
"type": "boolean"
},
"no-color": {
"allowNo": false,
"description": "Disable color output.",
"env": "SHOPIFY_FLAG_NO_COLOR",
"hidden": false,
"name": "no-color",
"type": "boolean"
},
"no-input": {
"allowNo": false,
"description": "Disable interactive prompts and browser authentication.",
"env": "SHOPIFY_FLAG_NO_INPUT",
"name": "no-input",
"type": "boolean"
},
"verbose": {
"allowNo": false,
"description": "Increase the verbosity of the output. May include sensitive data.",
"env": "SHOPIFY_FLAG_VERBOSE",
"hidden": false,
"name": "verbose",
"type": "boolean"
}
},
"hasDynamicHelp": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import AutoupgradeOn from './on.js'
import AutoupgradeStatus from './status.js'
import {autoUpgradeJsonOutputSchema} from '../../../services/commands/config/autoupgrade/types.js'
import {getAutoUpgradeEnabled, setAutoUpgradeEnabled} from '@shopify/cli-kit/node/upgrade'
Expand All @@ -21,7 +22,10 @@ afterEach(() => {
mockAndCaptureOutput().clear()
})

const commands = [{name: 'status', command: AutoupgradeStatus, enabled: false}]
const commands = [
{name: 'status', command: AutoupgradeStatus, enabled: false},
{name: 'on', command: AutoupgradeOn, enabled: true},
]

test.each(commands)('$name exposes the result schema and JSON flags in help', ({command}) => {
expect(command.jsonOutputSchema).toBe(autoUpgradeJsonOutputSchema)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import AutoupgradeOn from './on.js'
import {setAutoUpgradeEnabled} from '@shopify/cli-kit/node/upgrade'
import {Config} from '@oclif/core'
import {describe, expect, vi, test} from 'vitest'
import {mockAndCaptureOutput} from '@shopify/cli-kit/node/testing/output'

Expand All @@ -9,11 +8,10 @@ vi.mock('@shopify/cli-kit/node/upgrade')
describe('AutoupgradeOn', () => {
test('enables auto-upgrade', async () => {
// Given
const config = new Config({root: __dirname})
const outputMock = mockAndCaptureOutput()

// When
await new AutoupgradeOn([], config).run()
await AutoupgradeOn.run([], import.meta.url)

// Then
expect(setAutoUpgradeEnabled).toBeCalledWith(true)
Expand Down
21 changes: 16 additions & 5 deletions packages/cli/src/cli/commands/config/autoupgrade/on.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {autoUpgradeStatus} from './constants.js'
import {setAutoUpgradeEnabled} from '@shopify/cli-kit/node/upgrade'
import {configureAutoUpgrade} from '../../../services/commands/config/autoupgrade/index.js'
import {presentAutoUpgradeResult} from '../../../services/commands/config/autoupgrade/result.js'
import {autoUpgradeJsonOutputSchema} from '../../../services/commands/config/autoupgrade/types.js'
import Command from '@shopify/cli-kit/node/base-command'
import {renderInfo} from '@shopify/cli-kit/node/ui'
import {globalFlags, jsonFlag} from '@shopify/cli-kit/node/cli'

export default class AutoupgradeOn extends Command {
static summary = 'Enable automatic upgrades for Shopify CLI.'
Expand All @@ -15,8 +16,18 @@ export default class AutoupgradeOn extends Command {

static description = this.descriptionForHelp()

static flags = {
...globalFlags,
...jsonFlag,
}

static get jsonOutputSchema() {
return autoUpgradeJsonOutputSchema
}

async run(): Promise<void> {
setAutoUpgradeEnabled(true)
renderInfo({body: autoUpgradeStatus.on})
const {flags} = await this.parse(AutoupgradeOn)
const result = configureAutoUpgrade(true)
presentAutoUpgradeResult(result, flags.json ? 'json' : 'text')
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {getAutoUpgradeStatus} from './index.js'
import {configureAutoUpgrade, getAutoUpgradeStatus} from './index.js'
import * as upgrade from '@shopify/cli-kit/node/upgrade'
import {LocalStorage} from '@shopify/cli-kit/node/local-storage'
import {inTemporaryDirectory} from '@shopify/cli-kit/node/fs'
Expand All @@ -9,17 +9,18 @@ afterEach(() => {
mockAndCaptureOutput().clear()
})

test('returns the default and persisted preferences without presenting output', async () => {
test('returns the default preference and persists each configured value without presenting output', async () => {
await inTemporaryDirectory(async (directory) => {
const storage = new LocalStorage<{sessionStore: string; autoUpgradeEnabled?: boolean}>({cwd: directory})
const {getAutoUpgradeEnabled, setAutoUpgradeEnabled} = upgrade
vi.spyOn(upgrade, 'getAutoUpgradeEnabled').mockImplementation(() => getAutoUpgradeEnabled(storage))
vi.spyOn(upgrade, 'setAutoUpgradeEnabled').mockImplementation((enabled) => setAutoUpgradeEnabled(enabled, storage))
const output = mockAndCaptureOutput()

expect(getAutoUpgradeStatus()).toEqual({enabled: true})

for (const enabled of [false, true]) {
setAutoUpgradeEnabled(enabled, storage)
expect(configureAutoUpgrade(enabled)).toEqual({enabled})
expect(getAutoUpgradeStatus()).toEqual({enabled})
const reloadedStorage = new LocalStorage<{sessionStore: string; autoUpgradeEnabled?: boolean}>({cwd: directory})
expect(reloadedStorage.get('autoUpgradeEnabled')).toBe(enabled)
Expand All @@ -30,6 +31,15 @@ test('returns the default and persisted preferences without presenting output',
})
})

test('propagates a configuration write failure', () => {
const error = new Error('Cannot save auto-upgrade preference.')
vi.spyOn(upgrade, 'setAutoUpgradeEnabled').mockImplementation(() => {
throw error
})

expect(() => configureAutoUpgrade(false)).toThrow(error)
})

test('propagates a configuration read failure', () => {
const error = new Error('Cannot read auto-upgrade preference.')
vi.spyOn(upgrade, 'getAutoUpgradeEnabled').mockImplementation(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import {getAutoUpgradeEnabled} from '@shopify/cli-kit/node/upgrade'
import {getAutoUpgradeEnabled, setAutoUpgradeEnabled} from '@shopify/cli-kit/node/upgrade'
import type {AutoUpgradeResult} from './types.js'

export function getAutoUpgradeStatus(): AutoUpgradeResult {
return {enabled: getAutoUpgradeEnabled()}
}

export function configureAutoUpgrade(enabled: boolean): AutoUpgradeResult {
setAutoUpgradeEnabled(enabled)
return {enabled}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const commandExceptions = [
'packages/cli/src/cli/commands/auth/login.ts',
'packages/cli/src/cli/commands/auth/logout.ts',
'packages/cli/src/cli/commands/config/autoupgrade/off.ts',
'packages/cli/src/cli/commands/config/autoupgrade/on.ts',
'packages/cli/src/cli/commands/doc/fetch.ts',
'packages/cli/src/cli/commands/doc/search.ts',
'packages/cli/src/cli/commands/upgrade.ts',
Expand Down
Loading