From b6044541519cdd5861f1c0575d7542d4296ba3f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isaac=20Rold=C3=A1n?= Date: Thu, 10 Apr 2025 12:53:40 +0200 Subject: [PATCH] [DNM] Stop app preview --- .../app/src/cli/commands/app/dev/clean.ts | 61 +++++++++++++ packages/app/src/cli/index.ts | 2 + packages/cli/README.md | 27 ++++++ packages/cli/oclif.manifest.json | 88 +++++++++++++++++++ 4 files changed, 178 insertions(+) create mode 100644 packages/app/src/cli/commands/app/dev/clean.ts diff --git a/packages/app/src/cli/commands/app/dev/clean.ts b/packages/app/src/cli/commands/app/dev/clean.ts new file mode 100644 index 00000000000..2493f172dc3 --- /dev/null +++ b/packages/app/src/cli/commands/app/dev/clean.ts @@ -0,0 +1,61 @@ +import {linkedAppContext} from '../../../services/app-context.js' +import AppCommand, {AppCommandOutput} from '../../../utilities/app-command.js' +import {appFlags} from '../../../flags.js' +import {storeContext} from '../../../services/store-context.js' +import {globalFlags} from '@shopify/cli-kit/node/cli' +import {Flags} from '@oclif/core' +import {normalizeStoreFqdn} from '@shopify/cli-kit/node/context/fqdn' +import {renderSuccess} from '@shopify/cli-kit/node/ui' + +export default class DevClean extends AppCommand { + static summary = 'Cleans up the app preview from the selected store.' + + static descriptionWithMarkdown = `Stop the app preview that was started with \`shopify app dev\`. + + It restores the app active version to the selected development store. + ` + + static description = this.descriptionWithoutMarkdown() + + static flags = { + ...globalFlags, + ...appFlags, + store: Flags.string({ + hidden: false, + char: 's', + description: 'Store URL. Must be an existing development or Shopify Plus sandbox store.', + env: 'SHOPIFY_FLAG_STORE', + parse: async (input) => normalizeStoreFqdn(input), + }), + } + + public async run(): Promise { + const {flags} = await this.parse(DevClean) + + const appContextResult = await linkedAppContext({ + directory: flags.path, + clientId: flags['client-id'], + forceRelink: flags.reset, + userProvidedConfigName: flags.config, + }) + + const store = await storeContext({ + appContextResult, + storeFqdn: flags.store, + forceReselectStore: flags.reset, + }) + + const client = appContextResult.developerPlatformClient + await client.devSessionDelete({shopFqdn: store.shopDomain, appId: appContextResult.remoteApp.id}) + + renderSuccess({ + headline: 'App preview stopped.', + body: [ + `The app preview has been stopped on "${store.shopDomain}" and the app active version has been restored.`, + 'You can start it again with `shopify app dev`.', + ], + }) + + return {app: appContextResult.app} + } +} diff --git a/packages/app/src/cli/index.ts b/packages/app/src/cli/index.ts index 07a782da5b8..df5b3b4bb01 100644 --- a/packages/app/src/cli/index.ts +++ b/packages/app/src/cli/index.ts @@ -26,6 +26,7 @@ import init from './hooks/clear_command_cache.js' import gatherPublicMetadata from './hooks/public_metadata.js' import gatherSensitiveMetadata from './hooks/sensitive_metadata.js' import AppCommand from './utilities/app-command.js' +import DevClean from './commands/app/dev/clean.js' /** * All app commands should extend AppCommand. @@ -34,6 +35,7 @@ export const commands: {[key: string]: typeof AppCommand} = { 'app:build': Build, 'app:deploy': Deploy, 'app:dev': Dev, + 'app:dev:clean': DevClean, 'app:logs': Logs, 'app:logs:sources': Sources, 'app:import-extensions': ImportExtensions, diff --git a/packages/cli/README.md b/packages/cli/README.md index 5fb4fff8ae2..c33ccea5e59 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -5,6 +5,7 @@ * [`shopify app config use [config] [flags]`](#shopify-app-config-use-config-flags) * [`shopify app deploy`](#shopify-app-deploy) * [`shopify app dev`](#shopify-app-dev) +* [`shopify app dev clean`](#shopify-app-dev-clean) * [`shopify app env pull`](#shopify-app-env-pull) * [`shopify app env show`](#shopify-app-env-show) * [`shopify app function build`](#shopify-app-function-build) @@ -274,6 +275,32 @@ DESCRIPTION Partner Dashboard. ``` +## `shopify app dev clean` + +Stop the app. + +``` +USAGE + $ shopify app dev clean [--client-id | -c ] [--no-color] [--path ] [--reset | ] [-s + ] [--verbose] + +FLAGS + -c, --config= The name of the app configuration. + -s, --store= Store URL. Must be an existing development or Shopify Plus sandbox store. + --client-id= The Client ID of your app. + --no-color Disable color output. + --path= The path to your app directory. + --reset Reset all your settings. + --verbose Increase the verbosity of the output. + +DESCRIPTION + Stop the app. + + Stop the app preview that was started with `shopify app dev`. + + It restores the app active version to the selected development store. +``` + ## `shopify app env pull` Pull app and extensions environment variables. diff --git a/packages/cli/oclif.manifest.json b/packages/cli/oclif.manifest.json index a1ba85e80ab..0970bf0fa54 100644 --- a/packages/cli/oclif.manifest.json +++ b/packages/cli/oclif.manifest.json @@ -585,6 +585,94 @@ "strict": true, "summary": "Run the app." }, + "app:dev:clean": { + "aliases": [ + ], + "args": { + }, + "customPluginName": "@shopify/app", + "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 ", + "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 ", + "flags": { + "client-id": { + "description": "The Client ID of your app.", + "env": "SHOPIFY_FLAG_CLIENT_ID", + "exclusive": [ + "config" + ], + "hasDynamicHelp": false, + "hidden": false, + "multiple": false, + "name": "client-id", + "type": "option" + }, + "config": { + "char": "c", + "description": "The name of the app configuration.", + "env": "SHOPIFY_FLAG_APP_CONFIG", + "hasDynamicHelp": false, + "hidden": false, + "multiple": false, + "name": "config", + "type": "option" + }, + "no-color": { + "allowNo": false, + "description": "Disable color output.", + "env": "SHOPIFY_FLAG_NO_COLOR", + "hidden": false, + "name": "no-color", + "type": "boolean" + }, + "path": { + "description": "The path to your app directory.", + "env": "SHOPIFY_FLAG_PATH", + "hasDynamicHelp": false, + "multiple": false, + "name": "path", + "noCacheDefault": true, + "type": "option" + }, + "reset": { + "allowNo": false, + "description": "Reset all your settings.", + "env": "SHOPIFY_FLAG_RESET", + "exclusive": [ + "config" + ], + "hidden": false, + "name": "reset", + "type": "boolean" + }, + "store": { + "char": "s", + "description": "Store URL. Must be an existing development or Shopify Plus sandbox store.", + "env": "SHOPIFY_FLAG_STORE", + "hasDynamicHelp": false, + "hidden": false, + "multiple": false, + "name": "store", + "type": "option" + }, + "verbose": { + "allowNo": false, + "description": "Increase the verbosity of the output.", + "env": "SHOPIFY_FLAG_VERBOSE", + "hidden": false, + "name": "verbose", + "type": "boolean" + } + }, + "hasDynamicHelp": false, + "hiddenAliases": [ + ], + "id": "app:dev:clean", + "pluginAlias": "@shopify/cli", + "pluginName": "@shopify/cli", + "pluginType": "core", + "strict": true, + "summary": "Stop the app." + }, "app:env:pull": { "aliases": [ ],