Skip to content

Commit b604454

Browse files
committed
[DNM] Stop app preview
1 parent ab609e6 commit b604454

File tree

4 files changed

+178
-0
lines changed

4 files changed

+178
-0
lines changed

Diff for: packages/app/src/cli/commands/app/dev/clean.ts

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import {linkedAppContext} from '../../../services/app-context.js'
2+
import AppCommand, {AppCommandOutput} from '../../../utilities/app-command.js'
3+
import {appFlags} from '../../../flags.js'
4+
import {storeContext} from '../../../services/store-context.js'
5+
import {globalFlags} from '@shopify/cli-kit/node/cli'
6+
import {Flags} from '@oclif/core'
7+
import {normalizeStoreFqdn} from '@shopify/cli-kit/node/context/fqdn'
8+
import {renderSuccess} from '@shopify/cli-kit/node/ui'
9+
10+
export default class DevClean extends AppCommand {
11+
static summary = 'Cleans up the app preview from the selected store.'
12+
13+
static descriptionWithMarkdown = `Stop the app preview that was started with \`shopify app dev\`.
14+
15+
It restores the app active version to the selected development store.
16+
`
17+
18+
static description = this.descriptionWithoutMarkdown()
19+
20+
static flags = {
21+
...globalFlags,
22+
...appFlags,
23+
store: Flags.string({
24+
hidden: false,
25+
char: 's',
26+
description: 'Store URL. Must be an existing development or Shopify Plus sandbox store.',
27+
env: 'SHOPIFY_FLAG_STORE',
28+
parse: async (input) => normalizeStoreFqdn(input),
29+
}),
30+
}
31+
32+
public async run(): Promise<AppCommandOutput> {
33+
const {flags} = await this.parse(DevClean)
34+
35+
const appContextResult = await linkedAppContext({
36+
directory: flags.path,
37+
clientId: flags['client-id'],
38+
forceRelink: flags.reset,
39+
userProvidedConfigName: flags.config,
40+
})
41+
42+
const store = await storeContext({
43+
appContextResult,
44+
storeFqdn: flags.store,
45+
forceReselectStore: flags.reset,
46+
})
47+
48+
const client = appContextResult.developerPlatformClient
49+
await client.devSessionDelete({shopFqdn: store.shopDomain, appId: appContextResult.remoteApp.id})
50+
51+
renderSuccess({
52+
headline: 'App preview stopped.',
53+
body: [
54+
`The app preview has been stopped on "${store.shopDomain}" and the app active version has been restored.`,
55+
'You can start it again with `shopify app dev`.',
56+
],
57+
})
58+
59+
return {app: appContextResult.app}
60+
}
61+
}

Diff for: packages/app/src/cli/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import init from './hooks/clear_command_cache.js'
2626
import gatherPublicMetadata from './hooks/public_metadata.js'
2727
import gatherSensitiveMetadata from './hooks/sensitive_metadata.js'
2828
import AppCommand from './utilities/app-command.js'
29+
import DevClean from './commands/app/dev/clean.js'
2930

3031
/**
3132
* All app commands should extend AppCommand.
@@ -34,6 +35,7 @@ export const commands: {[key: string]: typeof AppCommand} = {
3435
'app:build': Build,
3536
'app:deploy': Deploy,
3637
'app:dev': Dev,
38+
'app:dev:clean': DevClean,
3739
'app:logs': Logs,
3840
'app:logs:sources': Sources,
3941
'app:import-extensions': ImportExtensions,

Diff for: packages/cli/README.md

+27
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* [`shopify app config use [config] [flags]`](#shopify-app-config-use-config-flags)
66
* [`shopify app deploy`](#shopify-app-deploy)
77
* [`shopify app dev`](#shopify-app-dev)
8+
* [`shopify app dev clean`](#shopify-app-dev-clean)
89
* [`shopify app env pull`](#shopify-app-env-pull)
910
* [`shopify app env show`](#shopify-app-env-show)
1011
* [`shopify app function build`](#shopify-app-function-build)
@@ -274,6 +275,32 @@ DESCRIPTION
274275
Partner Dashboard.
275276
```
276277

278+
## `shopify app dev clean`
279+
280+
Stop the app.
281+
282+
```
283+
USAGE
284+
$ shopify app dev clean [--client-id <value> | -c <value>] [--no-color] [--path <value>] [--reset | ] [-s
285+
<value>] [--verbose]
286+
287+
FLAGS
288+
-c, --config=<value> The name of the app configuration.
289+
-s, --store=<value> Store URL. Must be an existing development or Shopify Plus sandbox store.
290+
--client-id=<value> The Client ID of your app.
291+
--no-color Disable color output.
292+
--path=<value> The path to your app directory.
293+
--reset Reset all your settings.
294+
--verbose Increase the verbosity of the output.
295+
296+
DESCRIPTION
297+
Stop the app.
298+
299+
Stop the app preview that was started with `shopify app dev`.
300+
301+
It restores the app active version to the selected development store.
302+
```
303+
277304
## `shopify app env pull`
278305

279306
Pull app and extensions environment variables.

Diff for: packages/cli/oclif.manifest.json

+88
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,94 @@
585585
"strict": true,
586586
"summary": "Run the app."
587587
},
588+
"app:dev:clean": {
589+
"aliases": [
590+
],
591+
"args": {
592+
},
593+
"customPluginName": "@shopify/app",
594+
"description": "Stop the app preview that was started with `shopify app dev`.\n\n It restores the app active version to the selected development store.\n ",
595+
"descriptionWithMarkdown": "Stop the app preview that was started with `shopify app dev`.\n\n It restores the app active version to the selected development store.\n ",
596+
"flags": {
597+
"client-id": {
598+
"description": "The Client ID of your app.",
599+
"env": "SHOPIFY_FLAG_CLIENT_ID",
600+
"exclusive": [
601+
"config"
602+
],
603+
"hasDynamicHelp": false,
604+
"hidden": false,
605+
"multiple": false,
606+
"name": "client-id",
607+
"type": "option"
608+
},
609+
"config": {
610+
"char": "c",
611+
"description": "The name of the app configuration.",
612+
"env": "SHOPIFY_FLAG_APP_CONFIG",
613+
"hasDynamicHelp": false,
614+
"hidden": false,
615+
"multiple": false,
616+
"name": "config",
617+
"type": "option"
618+
},
619+
"no-color": {
620+
"allowNo": false,
621+
"description": "Disable color output.",
622+
"env": "SHOPIFY_FLAG_NO_COLOR",
623+
"hidden": false,
624+
"name": "no-color",
625+
"type": "boolean"
626+
},
627+
"path": {
628+
"description": "The path to your app directory.",
629+
"env": "SHOPIFY_FLAG_PATH",
630+
"hasDynamicHelp": false,
631+
"multiple": false,
632+
"name": "path",
633+
"noCacheDefault": true,
634+
"type": "option"
635+
},
636+
"reset": {
637+
"allowNo": false,
638+
"description": "Reset all your settings.",
639+
"env": "SHOPIFY_FLAG_RESET",
640+
"exclusive": [
641+
"config"
642+
],
643+
"hidden": false,
644+
"name": "reset",
645+
"type": "boolean"
646+
},
647+
"store": {
648+
"char": "s",
649+
"description": "Store URL. Must be an existing development or Shopify Plus sandbox store.",
650+
"env": "SHOPIFY_FLAG_STORE",
651+
"hasDynamicHelp": false,
652+
"hidden": false,
653+
"multiple": false,
654+
"name": "store",
655+
"type": "option"
656+
},
657+
"verbose": {
658+
"allowNo": false,
659+
"description": "Increase the verbosity of the output.",
660+
"env": "SHOPIFY_FLAG_VERBOSE",
661+
"hidden": false,
662+
"name": "verbose",
663+
"type": "boolean"
664+
}
665+
},
666+
"hasDynamicHelp": false,
667+
"hiddenAliases": [
668+
],
669+
"id": "app:dev:clean",
670+
"pluginAlias": "@shopify/cli",
671+
"pluginName": "@shopify/cli",
672+
"pluginType": "core",
673+
"strict": true,
674+
"summary": "Stop the app."
675+
},
588676
"app:env:pull": {
589677
"aliases": [
590678
],

0 commit comments

Comments
 (0)