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
6 changes: 0 additions & 6 deletions packages/cli/json-output-command-exceptions.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@
const commandExceptions = [
// Existing finite commands awaiting migration. Remove entries as they adopt typed JSON output.
// Do not add new finite commands to this section.
'packages/cli/src/commands/hydrogen/init.ts',
'packages/cli/src/commands/hydrogen/link.ts',
'packages/cli/src/commands/hydrogen/list.ts',
'packages/cli/src/commands/hydrogen/login.ts',
'packages/cli/src/commands/hydrogen/logout.ts',
'packages/cli/src/commands/hydrogen/setup.ts',
'packages/cli/src/commands/hydrogen/setup/css.ts',
'packages/cli/src/commands/hydrogen/setup/markets.ts',
'packages/cli/src/commands/hydrogen/setup/vite.ts',
'packages/cli/src/commands/hydrogen/shortcut.ts',
'packages/cli/src/commands/hydrogen/unlink.ts',
'packages/cli/src/commands/hydrogen/upgrade.ts',

// Streaming commands without a single finite result.
Expand Down
66 changes: 60 additions & 6 deletions packages/cli/oclif.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@
"hydrogen:init": {
"aliases": [],
"args": {},
"description": "Creates a new Hydrogen storefront.",
"description": "Creates a new Hydrogen storefront.\n\nUse `--json-schema` to print the result, error, and event schemas.\n\nOutput from `--json` conforms to the `HydrogenInitResult` schema.\n\n```json\n{\n \"anyOf\": [\n {\n \"type\": \"object\",\n \"properties\": {\n \"location\": {\n \"type\": \"string\"\n },\n \"name\": {\n \"type\": \"string\"\n },\n \"directory\": {\n \"type\": \"string\"\n },\n \"storefrontTitle\": {\n \"type\": \"string\"\n },\n \"language\": {\n \"type\": \"string\",\n \"enum\": [\n \"js\",\n \"ts\"\n ]\n },\n \"packageManager\": {\n \"type\": \"string\"\n },\n \"depsInstalled\": {\n \"type\": \"boolean\"\n },\n \"cssStrategy\": {\n \"type\": \"string\"\n },\n \"i18n\": {\n \"type\": \"string\"\n },\n \"routes\": {\n \"type\": \"object\",\n \"additionalProperties\": {\n \"anyOf\": [\n {\n \"type\": \"string\"\n },\n {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"string\"\n }\n }\n ]\n }\n },\n \"failures\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"string\",\n \"enum\": [\n \"dependencies\",\n \"markets\",\n \"routes\"\n ]\n }\n }\n },\n \"required\": [\n \"location\",\n \"name\",\n \"directory\",\n \"packageManager\",\n \"depsInstalled\",\n \"failures\"\n ],\n \"additionalProperties\": false\n },\n {\n \"type\": \"null\"\n }\n ],\n \"title\": \"HydrogenInitResult\",\n \"$schema\": \"http://json-schema.org/draft-07/schema#\"\n}\n```",
"flags": {
"json-schema": {
"description": "Print the command's JSON schemas.",
Expand All @@ -1212,6 +1212,15 @@
"allowNo": false,
"type": "boolean"
},
"json": {
"char": "j",
"description": "Output the result as JSON. Automatically disables color output.",
"env": "SHOPIFY_FLAG_JSON",
"hidden": false,
"name": "json",
"allowNo": false,
"type": "boolean"
},
"force": {
"char": "f",
"description": "Overwrites the destination directory and files if they already exist.",
Expand Down Expand Up @@ -1330,7 +1339,7 @@
"hydrogen:link": {
"aliases": [],
"args": {},
"description": "Link a local project to one of your shop's Hydrogen storefronts.",
"description": "Links your local development environment to a remote Hydrogen storefront. You can link an unlimited number of development environments to a single Hydrogen storefront.\n\n Linking to a Hydrogen storefront enables you to run \"dev\" (https://shopify.dev/docs/api/shopify-cli/hydrogen/hydrogen-dev) and automatically inject your linked Hydrogen storefront's environment variables directly into the server runtime.\n\n After you run the `link` command, you can access the \"env list\" (https://shopify.dev/docs/api/shopify-cli/hydrogen/hydrogen-env-list), \"env pull\" (https://shopify.dev/docs/api/shopify-cli/hydrogen/hydrogen-env-pull), and \"unlink\" (https://shopify.dev/docs/api/shopify-cli/hydrogen/hydrogen-unlink) commands.\n\nUse `--json-schema` to print the result, error, and event schemas.\n\nOutput from `--json` conforms to the `HydrogenLinkResult` schema.\n\n```json\n{\n \"type\": \"object\",\n \"properties\": {\n \"shop\": {\n \"type\": \"string\"\n },\n \"storefront\": {\n \"anyOf\": [\n {\n \"$ref\": \"#/definitions/Storefront\"\n },\n {\n \"type\": \"null\"\n }\n ]\n }\n },\n \"required\": [\n \"shop\",\n \"storefront\"\n ],\n \"additionalProperties\": false,\n \"title\": \"HydrogenLinkResult\",\n \"definitions\": {\n \"Storefront\": {\n \"type\": \"object\",\n \"properties\": {\n \"id\": {\n \"type\": \"string\"\n },\n \"title\": {\n \"type\": \"string\"\n },\n \"productionUrl\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"parsedId\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"id\",\n \"title\"\n ],\n \"additionalProperties\": false\n }\n },\n \"$schema\": \"http://json-schema.org/draft-07/schema#\"\n}\n```",
"flags": {
"json-schema": {
"description": "Print the command's JSON schemas.",
Expand All @@ -1339,6 +1348,15 @@
"allowNo": false,
"type": "boolean"
},
"json": {
"char": "j",
"description": "Output the result as JSON. Automatically disables color output.",
"env": "SHOPIFY_FLAG_JSON",
"hidden": false,
"name": "json",
"allowNo": false,
"type": "boolean"
},
"force": {
"char": "f",
"description": "Overwrites the destination directory and files if they already exist.",
Expand Down Expand Up @@ -1418,7 +1436,7 @@
"hydrogen:list": {
"aliases": [],
"args": {},
"description": "Returns a list of Hydrogen storefronts available on a given shop.",
"description": "Lists all remote Hydrogen storefronts available to link to your local development environment.\n\nUse `--json-schema` to print the result, error, and event schemas.\n\nOutput from `--json` conforms to the `HydrogenListResult` schema.\n\n```json\n{\n \"type\": \"object\",\n \"properties\": {\n \"shop\": {\n \"type\": \"string\"\n },\n \"storefronts\": {\n \"type\": \"array\",\n \"items\": {\n \"$ref\": \"#/definitions/Storefront\"\n }\n }\n },\n \"required\": [\n \"shop\",\n \"storefronts\"\n ],\n \"additionalProperties\": false,\n \"title\": \"HydrogenListResult\",\n \"definitions\": {\n \"Storefront\": {\n \"type\": \"object\",\n \"properties\": {\n \"id\": {\n \"type\": \"string\"\n },\n \"title\": {\n \"type\": \"string\"\n },\n \"productionUrl\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"parsedId\": {\n \"type\": \"string\"\n },\n \"currentProductionDeployment\": {\n \"anyOf\": [\n {\n \"$ref\": \"#/definitions/Deployment\"\n },\n {\n \"type\": \"null\"\n }\n ]\n }\n },\n \"required\": [\n \"id\",\n \"title\",\n \"currentProductionDeployment\"\n ],\n \"additionalProperties\": false\n },\n \"Deployment\": {\n \"type\": \"object\",\n \"properties\": {\n \"id\": {\n \"type\": \"string\"\n },\n \"createdAt\": {\n \"type\": \"string\"\n },\n \"commitMessage\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n }\n },\n \"required\": [\n \"id\",\n \"createdAt\",\n \"commitMessage\"\n ],\n \"additionalProperties\": false\n }\n },\n \"$schema\": \"http://json-schema.org/draft-07/schema#\"\n}\n```",
"flags": {
"json-schema": {
"description": "Print the command's JSON schemas.",
Expand All @@ -1427,6 +1445,15 @@
"allowNo": false,
"type": "boolean"
},
"json": {
"char": "j",
"description": "Output the result as JSON. Automatically disables color output.",
"env": "SHOPIFY_FLAG_JSON",
"hidden": false,
"name": "json",
"allowNo": false,
"type": "boolean"
},
"path": {
"description": "The path to the directory of the Hydrogen storefront. Defaults to the current directory where the command is run.",
"env": "SHOPIFY_HYDROGEN_FLAG_PATH",
Expand Down Expand Up @@ -1456,7 +1483,7 @@
"hydrogen:login": {
"aliases": [],
"args": {},
"description": "Login to your Shopify account.",
"description": "Logs in to the specified shop and saves the shop domain to the project.\n\nUse `--json-schema` to print the result, error, and event schemas.\n\nOutput from `--json` conforms to the `HydrogenLoginResult` schema.\n\n```json\n{\n \"type\": \"object\",\n \"properties\": {\n \"shop\": {\n \"type\": \"string\"\n },\n \"shopName\": {\n \"type\": \"string\"\n },\n \"email\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"shop\",\n \"shopName\",\n \"email\"\n ],\n \"additionalProperties\": false,\n \"title\": \"HydrogenLoginResult\",\n \"$schema\": \"http://json-schema.org/draft-07/schema#\"\n}\n```",
"flags": {
"json-schema": {
"description": "Print the command's JSON schemas.",
Expand All @@ -1465,6 +1492,15 @@
"allowNo": false,
"type": "boolean"
},
"json": {
"char": "j",
"description": "Output the result as JSON. Automatically disables color output.",
"env": "SHOPIFY_FLAG_JSON",
"hidden": false,
"name": "json",
"allowNo": false,
"type": "boolean"
},
"path": {
"description": "The path to the directory of the Hydrogen storefront. Defaults to the current directory where the command is run.",
"env": "SHOPIFY_HYDROGEN_FLAG_PATH",
Expand Down Expand Up @@ -1503,7 +1539,7 @@
"hydrogen:logout": {
"aliases": [],
"args": {},
"description": "Logout of your local session.",
"description": "Log out from the current shop.\n\nUse `--json-schema` to print the result, error, and event schemas.\n\nOutput from `--json` conforms to the `HydrogenLogoutResult` schema.\n\n```json\n{\n \"type\": \"object\",\n \"properties\": {\n \"loggedOut\": {\n \"type\": \"boolean\",\n \"const\": true\n }\n },\n \"required\": [\n \"loggedOut\"\n ],\n \"additionalProperties\": false,\n \"title\": \"HydrogenLogoutResult\",\n \"$schema\": \"http://json-schema.org/draft-07/schema#\"\n}\n```",
"flags": {
"json-schema": {
"description": "Print the command's JSON schemas.",
Expand All @@ -1512,6 +1548,15 @@
"allowNo": false,
"type": "boolean"
},
"json": {
"char": "j",
"description": "Output the result as JSON. Automatically disables color output.",
"env": "SHOPIFY_FLAG_JSON",
"hidden": false,
"name": "json",
"allowNo": false,
"type": "boolean"
},
"path": {
"description": "The path to the directory of the Hydrogen storefront. Defaults to the current directory where the command is run.",
"env": "SHOPIFY_HYDROGEN_FLAG_PATH",
Expand Down Expand Up @@ -1937,7 +1982,7 @@
"hydrogen:unlink": {
"aliases": [],
"args": {},
"description": "Unlink a local project from a Hydrogen storefront.",
"description": "Unlinks your local development environment from a remote Hydrogen storefront.\n\nUse `--json-schema` to print the result, error, and event schemas.\n\nOutput from `--json` conforms to the `HydrogenUnlinkResult` schema.\n\n```json\n{\n \"type\": \"object\",\n \"properties\": {\n \"unlinked\": {\n \"type\": \"boolean\"\n },\n \"storefront\": {\n \"anyOf\": [\n {\n \"type\": \"object\",\n \"properties\": {\n \"id\": {\n \"type\": \"string\"\n },\n \"title\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"id\",\n \"title\"\n ],\n \"additionalProperties\": false\n },\n {\n \"type\": \"null\"\n }\n ]\n }\n },\n \"required\": [\n \"unlinked\",\n \"storefront\"\n ],\n \"additionalProperties\": false,\n \"title\": \"HydrogenUnlinkResult\",\n \"$schema\": \"http://json-schema.org/draft-07/schema#\"\n}\n```",
"flags": {
"json-schema": {
"description": "Print the command's JSON schemas.",
Expand All @@ -1946,6 +1991,15 @@
"allowNo": false,
"type": "boolean"
},
"json": {
"char": "j",
"description": "Output the result as JSON. Automatically disables color output.",
"env": "SHOPIFY_FLAG_JSON",
"hidden": false,
"name": "json",
"allowNo": false,
"type": "boolean"
},
"path": {
"description": "The path to the directory of the Hydrogen storefront. Defaults to the current directory where the command is run.",
"env": "SHOPIFY_HYDROGEN_FLAG_PATH",
Expand Down
9 changes: 8 additions & 1 deletion packages/cli/src/commands/hydrogen/init.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {jsonFlag} from '@shopify/cli-kit/node/cli';
import {initJsonOutputSchema} from '../../lib/onboarding/types.js';
import Command from '@shopify/cli-kit/node/base-command';
import {Flags} from '@oclif/core';
import {AbortError} from '@shopify/cli-kit/node/error';
Expand All @@ -19,9 +21,14 @@ import {LANGUAGES} from '../../lib/onboarding/common.js';
const FLAG_MAP = {f: 'force'} as Record<string, string>;

export default class Init extends Command {
static get jsonOutputSchema(): typeof initJsonOutputSchema {
return initJsonOutputSchema;
}

static descriptionWithMarkdown = 'Creates a new Hydrogen storefront.';
static description = 'Creates a new Hydrogen storefront.';
static description = this.descriptionForHelp();
static flags = {
...jsonFlag,
...commonFlags.force,
path: Flags.string({
description: 'The path to the directory of the new Hydrogen storefront.',
Expand Down
37 changes: 25 additions & 12 deletions packages/cli/src/commands/hydrogen/link.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import {writeJsonResult} from '../../lib/json-output.js';
import {jsonFlag} from '@shopify/cli-kit/node/cli';
import {linkJsonOutputSchema} from '../../lib/storefronts/types.js';
import {Flags} from '@oclif/core';
import Command from '@shopify/cli-kit/node/base-command';
import {basename} from '@shopify/cli-kit/node/path';
Expand Down Expand Up @@ -28,16 +31,20 @@ import {
} from '../../lib/onboarding/common.js';

export default class Link extends Command {
static get jsonOutputSchema(): typeof linkJsonOutputSchema {
return linkJsonOutputSchema;
}

static descriptionWithMarkdown = `Links your local development environment to a remote Hydrogen storefront. You can link an unlimited number of development environments to a single Hydrogen storefront.

Linking to a Hydrogen storefront enables you to run [dev](https://shopify.dev/docs/api/shopify-cli/hydrogen/hydrogen-dev) and automatically inject your linked Hydrogen storefront's environment variables directly into the server runtime.

After you run the \`link\` command, you can access the [env list](https://shopify.dev/docs/api/shopify-cli/hydrogen/hydrogen-env-list), [env pull](https://shopify.dev/docs/api/shopify-cli/hydrogen/hydrogen-env-pull), and [unlink](https://shopify.dev/docs/api/shopify-cli/hydrogen/hydrogen-unlink) commands.`;

static description =
"Link a local project to one of your shop's Hydrogen storefronts.";
static description = this.descriptionForHelp();

static flags = {
...jsonFlag,
...commonFlags.force,
...commonFlags.path,
...commonFlags.shop,
Expand All @@ -60,7 +67,7 @@ export default class Link extends Command {

async run(): Promise<void> {
const {flags} = await this.parse(Link);
await runLink(flagsToCamelObject(flags));
await runLink(flagsToCamelObject(flags), flags.json);
}
}

Expand All @@ -73,14 +80,17 @@ export interface LinkStorefrontArguments {
name?: string;
}

export async function runLink({
createStorefront: flagCreateStorefront,
force,
path: root = process.cwd(),
shop,
storefront: flagStorefront,
name,
}: LinkStorefrontArguments) {
export async function runLink(
{
createStorefront: flagCreateStorefront,
force,
path: root = process.cwd(),
shop,
storefront: flagStorefront,
name,
}: LinkStorefrontArguments,
json?: boolean,
) {
const [{session, config}, cliCommand] = await Promise.all([
login(root, shop),
getCliCommand(),
Expand All @@ -94,7 +104,9 @@ export async function runLink({
cliCommand,
});

if (!linkedStore) return;
const result = {shop: config.shop!, storefront: linkedStore ?? null};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-blocking: list takes shop from session.storeFqdn, but this takes it from config.shop!. Let's use the session here as well. It's the same authenticated shop, the two commands then read it from the same place, and we get rid of the !:

Suggested change
const result = {shop: config.shop!, storefront: linkedStore ?? null};
const result = {shop: session.storeFqdn, storefront: linkedStore ?? null};

if (writeJsonResult(linkJsonOutputSchema, result, json) || !linkedStore)
return result;

renderSuccess({
body: [{userInput: linkedStore.title}, 'is now linked'],
Expand All @@ -106,6 +118,7 @@ export async function runLink({
],
],
});
return result;
}

export async function linkStorefront(
Expand Down
Loading
Loading