Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI unstable widget commands #1059

Draft
wants to merge 2 commits into
base: tl/manifest-plugin-git-describe-strategy
Choose a base branch
from
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
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@osdk/monorepo.tsup": "workspace:~",
"@osdk/shared.net.errors": "workspace:~",
"@osdk/shared.net.fetch": "workspace:~",
"@osdk/widget-api.unstable": "workspace:~",
"@types/archiver": "^6.0.2",
"@types/ngeohash": "^0.6.8",
"@types/node": "^18.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { consola } from "consola";
import type { Argv } from "yargs";
import auth from "./commands/auth/index.js";
import site from "./commands/site/index.js";
import { logConfigFileMiddleware } from "./yargs/logConfigFileMiddleware.js";
import widget from "./commands/widget/index.js";

export async function cli(args: string[] = process.argv) {
consola.info(
Expand All @@ -33,7 +33,6 @@ export async function cli(args: string[] = process.argv) {
// Special handling where failures happen before yargs does its error handling within .fail
try {
return await base
.middleware(logConfigFileMiddleware)
.command(site)
.command({
command: "unstable",
Expand All @@ -43,6 +42,7 @@ export async function cli(args: string[] = process.argv) {
return argv
.command(typescript)
.command(auth)
.command(widget)
.demandCommand();
},
handler: (_args) => {},
Expand Down
9 changes: 3 additions & 6 deletions packages/cli/src/commands/site/deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
import { isValidSemver, YargsCheckError } from "@osdk/cli.common";
import type {
AutoVersionConfigType,
LoadedFoundryConfig,
SiteConfig,
} from "@osdk/foundry-config-json";
import type { CommandModule } from "yargs";
import configLoader from "../../../util/configLoader.js";
import type { CommonSiteArgs } from "../CommonSiteArgs.js";
import { logDeployCommandConfigFileOverride } from "./logDeployCommandConfigFileOverride.js";
import { logSiteDeployCommandConfigFileOverride } from "./logSiteDeployCommandConfigFileOverride.js";
import type { SiteDeployArgs } from "./SiteDeployArgs.js";

const command: CommandModule<
Expand All @@ -33,8 +32,7 @@ const command: CommandModule<
command: "deploy",
describe: "Deploy a new site version",
builder: async (argv) => {
const config: LoadedFoundryConfig<"site"> | undefined =
await configLoader();
const config = await configLoader("site");
const siteConfig: SiteConfig | undefined = config?.foundryConfig.site;
const directory = siteConfig?.directory;
const autoVersion = siteConfig?.autoVersion;
Expand Down Expand Up @@ -134,7 +132,6 @@ const command: CommandModule<
}

const gitTagPrefixValue = args.gitTagPrefix ?? gitTagPrefix;
// 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`,
Expand All @@ -155,7 +152,7 @@ const command: CommandModule<

return true;
}).middleware((args) =>
logDeployCommandConfigFileOverride(
logSiteDeployCommandConfigFileOverride(
args,
siteConfig,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { consola } from "consola";
import type { Arguments } from "yargs";
import type { SiteDeployArgs } from "./SiteDeployArgs.js";

export async function logDeployCommandConfigFileOverride(
export async function logSiteDeployCommandConfigFileOverride(
args: Arguments<SiteDeployArgs>,
config: SiteConfig | undefined,
) {
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/commands/site/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

import type { CliCommonArgs } from "@osdk/cli.common";
import { YargsCheckError } from "@osdk/cli.common";
import type { LoadedFoundryConfig } from "@osdk/foundry-config-json";
import type { CommandModule } from "yargs";
import type { ThirdPartyAppRid } from "../../net/ThirdPartyAppRid.js";
import configLoader from "../../util/configLoader.js";
import { logConfigFileMiddleware } from "../../yargs/logConfigFileMiddleware.js";
import type { CommonSiteArgs } from "./CommonSiteArgs.js";
import deploy from "./deploy/index.js";
import { logSiteCommandConfigFileOverride } from "./logSiteCommandConfigFileOverride.js";
Expand All @@ -29,8 +29,7 @@ const command: CommandModule<CliCommonArgs, CommonSiteArgs> = {
command: "site",
describe: "Manage your site",
builder: async (argv) => {
const config: LoadedFoundryConfig<"site"> | undefined =
await configLoader();
const config = await configLoader("site");
const application = config?.foundryConfig.site.application;
const foundryUrl = config?.foundryConfig.foundryUrl;
return argv
Expand Down Expand Up @@ -74,9 +73,10 @@ const command: CommandModule<CliCommonArgs, CommonSiteArgs> = {
}
return true;
})
.middleware((args) =>
logSiteCommandConfigFileOverride(args, config?.foundryConfig)
)
.middleware((args) => {
logConfigFileMiddleware("site");
logSiteCommandConfigFileOverride(args, config?.foundryConfig);
})
.demandCommand();
},
handler: async (args) => {},
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/site/version/delete/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const command: CommandModule<
.positional("version", {
type: "string",
demandOption: true,
description: "Version to set as live",
description: "Version to delete",
})
.option("yes", {
alias: "y",
Expand Down
25 changes: 25 additions & 0 deletions packages/cli/src/commands/widget/CommonWidgetArgs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2023 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { CliCommonArgs } from "@osdk/cli.common";
import type { WidgetRid } from "../../net/WidgetRid.js";

export interface CommonWidgetArgs extends CliCommonArgs {
rid: WidgetRid;
foundryUrl: string;
token?: string;
tokenFile?: string;
}
21 changes: 21 additions & 0 deletions packages/cli/src/commands/widget/deploy/WidgetDeployArgs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2023 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { CommonWidgetArgs } from "../CommonWidgetArgs.js";

export interface WidgetDeployArgs extends CommonWidgetArgs {
directory: string;
}
58 changes: 58 additions & 0 deletions packages/cli/src/commands/widget/deploy/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2023 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { WidgetConfig } from "@osdk/foundry-config-json";
import type { CommandModule } from "yargs";
import configLoader from "../../../util/configLoader.js";
import type { CommonWidgetArgs } from "../CommonWidgetArgs.js";
import { logWidgetDeployCommandConfigFileOverride } from "./logWidgetDeployCommandConfigFileOverride.js";
import type { WidgetDeployArgs } from "./WidgetDeployArgs.js";

const command: CommandModule<
CommonWidgetArgs,
WidgetDeployArgs
> = {
command: "deploy",
describe: "Deploy a new widget version",
builder: async (argv) => {
const config = await configLoader("widget");
const widgetConfig: WidgetConfig | undefined = config?.foundryConfig.widget;
const directory = widgetConfig?.directory;

return argv
.options({
directory: {
type: "string",
description: "Directory containing widget files",
...directory
? { default: directory }
: { demandOption: true },
},
})
.group(
["directory"],
"Deploy Options",
).middleware((args) =>
logWidgetDeployCommandConfigFileOverride(args, widgetConfig)
);
},
handler: async (args) => {
const command = await import("./widgetDeployCommand.mjs");
await command.default(args);
},
};

export default command;
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2023 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { WidgetConfig } from "@osdk/foundry-config-json";
import { consola } from "consola";
import type { Arguments } from "yargs";
import type { WidgetDeployArgs } from "./WidgetDeployArgs.js";

export async function logWidgetDeployCommandConfigFileOverride(
args: Arguments<WidgetDeployArgs>,
config: WidgetConfig | undefined,
) {
if (config?.directory != null && args.directory !== config.directory) {
consola.debug(
`Overriding "directory" from config file with ${args.directory}`,
);
}
}
Loading
Loading