Skip to content

Commit

Permalink
version commands
Browse files Browse the repository at this point in the history
  • Loading branch information
tzyl committed Dec 12, 2024
1 parent 582ccd4 commit 7618fa4
Show file tree
Hide file tree
Showing 16 changed files with 432 additions and 13 deletions.
1 change: 0 additions & 1 deletion packages/cli/src/commands/site/deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import { isValidSemver, YargsCheckError } from "@osdk/cli.common";
import type {
AutoVersionConfigType,
LoadedFoundryConfig,
SiteConfig,
} from "@osdk/foundry-config-json";
import type { CommandModule } from "yargs";
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/commands/site/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

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";
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
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ async function findWidgetVersion(
} catch (e) {
throw new ExitProcessError(
2,
`Unable to process manifest at ${MANIFEST_FILE_LOCATION}`,
undefined,
e instanceof Error ? e : undefined,
`Unable to process manifest at ${MANIFEST_FILE_LOCATION}${
e instanceof Error ? `: ${e.message}` : ""
}`,
);
}
}
Expand Down Expand Up @@ -148,8 +148,7 @@ async function publishManifest(
headers: {
"Content-Type": "application/json",
},
duplex: "half", // Node hates me
} satisfies RequestInit & { duplex: "half" } as any,
},
);
}

Expand Down
6 changes: 2 additions & 4 deletions packages/cli/src/commands/widget/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,20 @@
*/

import { type CliCommonArgs, YargsCheckError } from "@osdk/cli.common";
import { consola } from "consola";
import type { CommandModule } from "yargs";
import type { WidgetRid } from "../../net/WidgetRid.js";
import configLoader from "../../util/configLoader.js";
import { logConfigFileMiddleware } from "../../yargs/logConfigFileMiddleware.js";
import type { CommonWidgetArgs } from "./CommonWidgetArgs.js";
import deploy from "./deploy/index.js";
import { logWidgetCommandConfigFileOverride } from "./logWidgetCommandConfigFileOverride.js";
import version from "./version/index.js";

const command: CommandModule<CliCommonArgs, CommonWidgetArgs> = {
command: "widget",
describe: "Manage your widget",
builder: async (argv) => {
const config = await configLoader("widget");
// TODO: remove
consola.info(config);
const rid = config?.foundryConfig.widget.rid;
const foundryUrl = config?.foundryConfig.foundryUrl;
return argv.options({
Expand Down Expand Up @@ -65,7 +63,7 @@ const command: CommandModule<CliCommonArgs, CommonWidgetArgs> = {
["rid", "foundryUrl", "token", "tokenFile"],
"Common Options",
)
// .command(version)
.command(version)
.command(deploy)
.check((args) => {
if (!args.foundryUrl.startsWith("https://")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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 VersionDeleteArgs extends CommonWidgetArgs {
version: string;
yes?: boolean;
}
47 changes: 47 additions & 0 deletions packages/cli/src/commands/widget/version/delete/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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 { CommandModule } from "yargs";
import type { CommonWidgetArgs } from "../../CommonWidgetArgs.js";
import type { VersionDeleteArgs } from "./VersionDeleteArgs.js";

const command: CommandModule<
CommonWidgetArgs,
VersionDeleteArgs
> = {
command: "delete <version>",
describe: "Delete widget version",
builder: (argv) => {
return argv
.positional("version", {
type: "string",
demandOption: true,
description: "Version to delete",
})
.option("yes", {
alias: "y",
type: "boolean",
description: "Automatically confirm destructive changes",
})
.group(["yes"], "Delete Options");
},
handler: async (args) => {
const command = await import("./versionDeleteCommand.mjs");
await command.default(args);
},
};

export default command;
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* 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 { createInternalClientContext } from "#net";
import { consola } from "consola";
import { colorize } from "consola/utils";
import { handlePromptCancel } from "../../../../consola/handlePromptCancel.js";
import { createFetch } from "../../../../net/createFetch.mjs";
import type { InternalClientContext } from "../../../../net/internalClientContext.mjs";
import type { WidgetRid } from "../../../../net/WidgetRid.js";
import { loadToken } from "../../../../util/token.js";
import type { VersionDeleteArgs } from "./VersionDeleteArgs.js";

export default async function versionDeleteCommand(
{ version, yes, rid, foundryUrl, token, tokenFile }: VersionDeleteArgs,
) {
if (!yes) {
const confirmed = await consola.prompt(
`Are you sure you want to delete the version ${version}?\n${
colorize("bold", "This action cannot be undone.")
}`,
{ type: "confirm" },
);
handlePromptCancel(confirmed);
}

consola.start(`Deleting version ${version}`);
const loadedToken = await loadToken(token, tokenFile);
const tokenProvider = () => loadedToken;
const clientCtx = createInternalClientContext(foundryUrl, tokenProvider);
// TODO: Look at type of locator and decide whether to confirm delete site version
await Promise.all([
deleteViewRelease(clientCtx, rid, version),
deleteVersion(clientCtx, rid, version),
]);
consola.success(`Deleted version ${version}`);
}

async function deleteViewRelease(
ctx: InternalClientContext,
// TODO: make repository rid
widgetRid: WidgetRid,
version: string,
): Promise<void> {
const fetch = createFetch(ctx.tokenProvider);
const url =
`${ctx.foundryUrl}/view-registry/api/views/${widgetRid}/releases/${version}`;
await fetch(
url,
{
method: "DELETE",
},
);
}

async function deleteVersion(
ctx: InternalClientContext,
// TODO: make repository rid
widgetRid: WidgetRid,
version: string,
): Promise<void> {
const fetch = createFetch(ctx.tokenProvider);
const url =
`${ctx.foundryUrl}/artifacts/api/repositories/${widgetRid}/contents/release/siteasset/versions/${version}`;

await fetch(
url,
{
method: "DELETE",
},
);
}
39 changes: 39 additions & 0 deletions packages/cli/src/commands/widget/version/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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 { CommandModule } from "yargs";
import type { CommonWidgetArgs } from "../CommonWidgetArgs.js";
import deleteCmd from "./delete/index.js";
import info from "./info/index.js";
import list from "./list/index.js";

const command: CommandModule<
CommonWidgetArgs,
CommonWidgetArgs
> = {
command: "version",
describe: "Manage widget versions",
builder: (argv) => {
return argv
.command(list)
.command(info)
.command(deleteCmd)
.demandCommand();
},
handler: async (args) => {},
};

export default command;
21 changes: 21 additions & 0 deletions packages/cli/src/commands/widget/version/info/VersionInfoArgs.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 VersionInfoArgs extends CommonWidgetArgs {
version: string;
}
41 changes: 41 additions & 0 deletions packages/cli/src/commands/widget/version/info/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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 { CommandModule } from "yargs";
import type { CommonWidgetArgs } from "../../CommonWidgetArgs.js";
import type { VersionInfoArgs } from "./VersionInfoArgs.js";

const command: CommandModule<
CommonWidgetArgs,
VersionInfoArgs
> = {
command: "info <version>",
describe: "Load info about widget version",
builder: (argv) => {
return argv
.positional("version", {
type: "string",
demandOption: true,
description: "Version to load",
});
},
handler: async (args) => {
const command = await import("./versionInfoCommand.mjs");
await command.default(args);
},
};

export default command;
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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 { createInternalClientContext } from "#net";
import { consola } from "consola";
import { createFetch } from "../../../../net/createFetch.mjs";
import type { InternalClientContext } from "../../../../net/internalClientContext.mjs";
import type { WidgetRid } from "../../../../net/WidgetRid.js";
import { loadToken } from "../../../../util/token.js";
import type { VersionInfoArgs } from "./VersionInfoArgs.js";

export default async function versionInfoCommand(
{ version, foundryUrl, rid, token, tokenFile }: VersionInfoArgs,
) {
const loadedToken = await loadToken(token, tokenFile);
const tokenProvider = () => loadedToken;
const clientCtx = createInternalClientContext(foundryUrl, tokenProvider);
consola.start("Loading version info");
const response = await getViewRelease(clientCtx, rid, version);
consola.success(`Loaded version info for ${version}`);
consola.log(JSON.stringify(response, null, 2));
}

async function getViewRelease(
ctx: InternalClientContext,
// TODO: make repository rid
widgetRid: WidgetRid,
version: string,
): Promise<any> {
const fetch = createFetch(ctx.tokenProvider);
const url =
`${ctx.foundryUrl}/view-registry/api/views/${widgetRid}/releases/${version}`;
const response = await fetch(url);
return response.json();
}
Loading

0 comments on commit 7618fa4

Please sign in to comment.