From 845728c558d60e426614014b05f6a30fde5f37c7 Mon Sep 17 00:00:00 2001 From: Zeyad Abuamer Date: Wed, 14 Feb 2024 18:02:16 +0000 Subject: [PATCH 1/2] Make site commands and docs options kebab-case --- .../cli/src/commands/site/CommonSiteArgs.ts | 4 ++-- .../src/commands/site/deploy/SiteDeployArgs.ts | 6 +++--- packages/cli/src/commands/site/deploy/index.ts | 18 +++++++++--------- .../commands/site/deploy/siteDeployCommand.mts | 15 ++++++++++++--- packages/cli/src/commands/site/index.ts | 16 ++++++++++------ .../version/delete/versionDeleteCommand.mts | 12 +++++++++++- .../site/version/get/versionGetCommand.mts | 12 +++++++++++- .../site/version/list/versionListCommand.mts | 9 ++++++++- .../site/version/set/versionSetCommand.mts | 13 ++++++++++++- .../site/version/unset/versionUnsetCommand.mts | 12 +++++++++++- packages/cli/src/util/token.ts | 2 +- 11 files changed, 90 insertions(+), 29 deletions(-) diff --git a/packages/cli/src/commands/site/CommonSiteArgs.ts b/packages/cli/src/commands/site/CommonSiteArgs.ts index e40d1681d..e55965907 100644 --- a/packages/cli/src/commands/site/CommonSiteArgs.ts +++ b/packages/cli/src/commands/site/CommonSiteArgs.ts @@ -19,7 +19,7 @@ import type { ThirdPartyAppRid } from "../../net/ThirdPartyAppRid.js"; export interface CommonSiteArgs extends CliCommonArgs { application: ThirdPartyAppRid; - foundryUrl: string; + "foundry-url": string; + "token-file"?: string; token?: string; - tokenFile?: string; } diff --git a/packages/cli/src/commands/site/deploy/SiteDeployArgs.ts b/packages/cli/src/commands/site/deploy/SiteDeployArgs.ts index dff9027f5..4ab75cafb 100644 --- a/packages/cli/src/commands/site/deploy/SiteDeployArgs.ts +++ b/packages/cli/src/commands/site/deploy/SiteDeployArgs.ts @@ -20,7 +20,7 @@ import type { CommonSiteArgs } from "../CommonSiteArgs.js"; export interface SiteDeployArgs extends CommonSiteArgs { version?: string; directory: string; - uploadOnly: boolean; - autoVersion?: AutoVersionConfigType; - gitTagPrefix?: string; + "upload-only": boolean; + "auto-version"?: AutoVersionConfigType; + "git-tag-prefix"?: string; } diff --git a/packages/cli/src/commands/site/deploy/index.ts b/packages/cli/src/commands/site/deploy/index.ts index a1a98929c..7061b1a54 100644 --- a/packages/cli/src/commands/site/deploy/index.ts +++ b/packages/cli/src/commands/site/deploy/index.ts @@ -48,7 +48,7 @@ const command: CommandModule< ? { default: directory } : { demandOption: true }, }, - uploadOnly: { + "upload-only": { type: "boolean", description: "Upload new site version only without setting as live", default: false, @@ -60,7 +60,7 @@ const command: CommandModule< ? { conflicts: "autoVersion" } : {}, }, - autoVersion: { + "auto-version": { coerce: (autoVersion) => autoVersion as AutoVersionConfigType, type: "string", choices: ["git-describe"], @@ -69,7 +69,7 @@ const command: CommandModule< ? { default: autoVersion.type } : { conflicts: "version" }, }, - gitTagPrefix: { + "git-tag-prefix": { type: "string", description: "Prefix to match git tags on when 'git-describe' auto versioning is used. If not provided, all tags are matched and the prefix 'v' is stripped if present.", @@ -79,29 +79,29 @@ const command: CommandModule< }, }) .group( - ["directory", "version", "uploadOnly"], + ["directory", "version", "upload-only"], "Deploy Options", ) .group( - ["autoVersion", "gitTagPrefix"], + ["auto-version", "git-tag-prefix"], "Auto Version Options", ) .check((args) => { - // This is required because we can't use demandOption with conflicts. conflicts protects us against the case where both are provided. + // This is required because we can't use demandOption with conflicts. Conflicts protect us against the case where both are provided. // So this case is for when nothing is provided. if ( autoVersion == null && args.autoVersion == null && args.version == null ) { throw new YargsCheckError( - "One of --version or --autoVersion must be specified", + "One of --version or --auto-version must be specified", ); } const autoVersionType = args.autoVersion ?? autoVersion; if (autoVersionType !== "git-describe") { throw new YargsCheckError( - `Only 'git-describe' is supported for autoVersion`, + `Only 'git-describe' is supported for --auto-version`, ); } @@ -109,7 +109,7 @@ const command: CommandModule< // Future proofing for when we support other autoVersion types if (gitTagPrefixValue != null && autoVersionType !== "git-describe") { throw new YargsCheckError( - `--gitTagPrefix is only supported when --autoVersion=git-describe`, + `--git-tag-prefix is only supported when --auto-version=git-describe`, ); } diff --git a/packages/cli/src/commands/site/deploy/siteDeployCommand.mts b/packages/cli/src/commands/site/deploy/siteDeployCommand.mts index 075d79496..ad54e4ea4 100644 --- a/packages/cli/src/commands/site/deploy/siteDeployCommand.mts +++ b/packages/cli/src/commands/site/deploy/siteDeployCommand.mts @@ -35,12 +35,21 @@ import type { AutoVersionConfig } from "../../../util/config.js"; import { loadToken } from "../../../util/token.js"; import type { SiteDeployArgs } from "./SiteDeployArgs.js"; -interface SiteDeployInternalArgs - extends Omit +interface SiteDeployInternalArgs extends + Omit< + SiteDeployArgs, + | "version" + | "autoVersion" + | "auto-version" + | "foundry-url" + | "token-file" + | "upload-only" + > { selectedVersion: string | AutoVersionConfig; - directory: string; uploadOnly: boolean; + foundryUrl: string; + tokenFile?: string; } export default async function siteDeployCommand( diff --git a/packages/cli/src/commands/site/index.ts b/packages/cli/src/commands/site/index.ts index 43ed7bf66..67a110036 100644 --- a/packages/cli/src/commands/site/index.ts +++ b/packages/cli/src/commands/site/index.ts @@ -25,7 +25,10 @@ import deploy from "./deploy/index.js"; import { logSiteCommandConfigFileOverride } from "./logSiteCommandConfigFileOverride.js"; import version from "./version/index.js"; -const command: CommandModule = { +const command: CommandModule< + CliCommonArgs, + CommonSiteArgs +> = { command: "site", describe: "Manage your site", builder: async (argv) => { @@ -42,7 +45,7 @@ const command: CommandModule = { : { demandOption: true }, description: "Application resource identifier (rid)", }, - foundryUrl: { + "foundry-url": { coerce: (foundryUrl) => foundryUrl.replace(/\/$/, ""), type: "string", ...foundryUrl @@ -55,21 +58,22 @@ const command: CommandModule = { conflicts: "tokenFile", description: "Foundry API token", }, - tokenFile: { + "token-file": { type: "string", conflicts: "token", description: "Path to file containing Foundry API token", }, }) .group( - ["application", "foundryUrl", "token", "tokenFile"], + ["application", "foundry-url", "token", "token-file"], "Common Options", ) .command(version) .command(deploy) .check((args) => { - if (!args.foundryUrl.startsWith("https://")) { - throw new YargsCheckError("foundryUrl must start with https://"); + // Could also do args["foundry-url"] to not do the type assertion + if (!(args.foundryUrl as string).startsWith("https://")) { + throw new YargsCheckError("foundry-url must start with https://"); } return true; }) diff --git a/packages/cli/src/commands/site/version/delete/versionDeleteCommand.mts b/packages/cli/src/commands/site/version/delete/versionDeleteCommand.mts index c620aba53..47b378999 100644 --- a/packages/cli/src/commands/site/version/delete/versionDeleteCommand.mts +++ b/packages/cli/src/commands/site/version/delete/versionDeleteCommand.mts @@ -21,9 +21,19 @@ import { handlePromptCancel } from "../../../../consola/handlePromptCancel.js"; import { loadToken } from "../../../../util/token.js"; import type { VersionDeleteArgs } from "./VersionDeleteArgs.js"; +interface VersionDeleteInternalArgs extends + Omit< + VersionDeleteArgs, + "foundry-url" | "token-file" + > +{ + foundryUrl: string; + tokenFile?: string; +} + export default async function versionDeleteCommand( { version, yes, application, foundryUrl, token, tokenFile }: - VersionDeleteArgs, + VersionDeleteInternalArgs, ) { if (!yes) { const confirmed = await consola.prompt( diff --git a/packages/cli/src/commands/site/version/get/versionGetCommand.mts b/packages/cli/src/commands/site/version/get/versionGetCommand.mts index 2038a9d7b..82b67c1e7 100644 --- a/packages/cli/src/commands/site/version/get/versionGetCommand.mts +++ b/packages/cli/src/commands/site/version/get/versionGetCommand.mts @@ -24,8 +24,18 @@ import { consola } from "consola"; import { loadToken } from "../../../../util/token.js"; import type { VersionGetArgs } from "./VersionGetArgs.js"; +interface VersionGetInternalArgs extends + Omit< + VersionGetArgs, + "foundry-url" | "token-file" + > +{ + foundryUrl: string; + tokenFile?: string; +} + export default async function versionGetCommand( - { foundryUrl, application, token, tokenFile }: VersionGetArgs, + { foundryUrl, application, token, tokenFile }: VersionGetInternalArgs, ) { const loadedToken = await loadToken(token, tokenFile); const tokenProvider = () => loadedToken; diff --git a/packages/cli/src/commands/site/version/list/versionListCommand.mts b/packages/cli/src/commands/site/version/list/versionListCommand.mts index aebd77327..0735e60c2 100644 --- a/packages/cli/src/commands/site/version/list/versionListCommand.mts +++ b/packages/cli/src/commands/site/version/list/versionListCommand.mts @@ -26,8 +26,15 @@ import { colorize } from "consola/utils"; import { loadToken } from "../../../../util/token.js"; import type { VersionListArgs } from "./VersionListArgs.js"; +interface VersionListInternalArgs + extends Omit +{ + foundryUrl: string; + tokenFile?: string; +} + export default async function versionListCommand( - { foundryUrl, application, token, tokenFile }: VersionListArgs, + { foundryUrl, application, token, tokenFile }: VersionListInternalArgs, ) { const loadedToken = await loadToken(token, tokenFile); const tokenProvider = () => loadedToken; diff --git a/packages/cli/src/commands/site/version/set/versionSetCommand.mts b/packages/cli/src/commands/site/version/set/versionSetCommand.mts index fb5b4dcba..c15418157 100644 --- a/packages/cli/src/commands/site/version/set/versionSetCommand.mts +++ b/packages/cli/src/commands/site/version/set/versionSetCommand.mts @@ -25,8 +25,19 @@ import { import { loadToken } from "../../../../util/token.js"; import type { VersionSetArgs } from "./VersionSetArgs.js"; +interface VersionSetInternalArgs extends + Omit< + VersionSetArgs, + "foundry-url" | "token-file" + > +{ + foundryUrl: string; + tokenFile?: string; +} + export default async function versionSetCommand( - { version, application, foundryUrl, token, tokenFile }: VersionSetArgs, + { version, application, foundryUrl, token, tokenFile }: + VersionSetInternalArgs, ) { consola.start(`Setting live version`); const loadedToken = await loadToken(token, tokenFile); diff --git a/packages/cli/src/commands/site/version/unset/versionUnsetCommand.mts b/packages/cli/src/commands/site/version/unset/versionUnsetCommand.mts index e9c757176..ff65d11e9 100644 --- a/packages/cli/src/commands/site/version/unset/versionUnsetCommand.mts +++ b/packages/cli/src/commands/site/version/unset/versionUnsetCommand.mts @@ -27,8 +27,18 @@ import { handlePromptCancel } from "../../../../consola/handlePromptCancel.js"; import { loadToken } from "../../../../util/token.js"; import type { VersionUnsetArgs } from "./VersionUnsetArgs.js"; +interface VersionUnsetInternalArgs extends + Omit< + VersionUnsetArgs, + "foundry-url" | "token-file" + > +{ + foundryUrl: string; + tokenFile?: string; +} + export default async function versionUnsetCommand( - { yes, application, foundryUrl, token, tokenFile }: VersionUnsetArgs, + { yes, application, foundryUrl, token, tokenFile }: VersionUnsetInternalArgs, ) { if (!yes) { const confirmed = await consola.prompt( diff --git a/packages/cli/src/util/token.ts b/packages/cli/src/util/token.ts index 05b5ae99e..827af9803 100644 --- a/packages/cli/src/util/token.ts +++ b/packages/cli/src/util/token.ts @@ -41,7 +41,7 @@ export async function loadToken( if (tokenFile) { const loadedToken = await loadTokenFile(tokenFile); consola.debug( - `Using token from --tokenFile=${loadedToken.filePath} option`, + `Using token from --token-file=${loadedToken.filePath} option`, ); validate(loadedToken.token); return loadedToken.token; From 1f26372744082cdc6a57d2fbe6666dc07e6bafc3 Mon Sep 17 00:00:00 2001 From: Zeyad Abuamer Date: Wed, 14 Feb 2024 18:12:46 +0000 Subject: [PATCH 2/2] Update conflicts to use kebab-case --- packages/cli/src/commands/site/deploy/index.ts | 2 +- packages/cli/src/commands/site/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/commands/site/deploy/index.ts b/packages/cli/src/commands/site/deploy/index.ts index 7061b1a54..7361b0219 100644 --- a/packages/cli/src/commands/site/deploy/index.ts +++ b/packages/cli/src/commands/site/deploy/index.ts @@ -57,7 +57,7 @@ const command: CommandModule< type: "string", description: "New version of site to deploy", ...autoVersion == null - ? { conflicts: "autoVersion" } + ? { conflicts: "auto-version" } : {}, }, "auto-version": { diff --git a/packages/cli/src/commands/site/index.ts b/packages/cli/src/commands/site/index.ts index 67a110036..82f62d6b2 100644 --- a/packages/cli/src/commands/site/index.ts +++ b/packages/cli/src/commands/site/index.ts @@ -55,7 +55,7 @@ const command: CommandModule< }, token: { type: "string", - conflicts: "tokenFile", + conflicts: "token-file", description: "Foundry API token", }, "token-file": {