Files
windmill/cli/hub.ts
Kai Jellinghaus fc494fbf7f feat(cli): 2-Way sync (#1071)
* Export file type from each file

* Fix example scripts

* Strongly type CLI files

* Allow bash files

* Update API version

* Remove useless files

* WIP: Diff based push

* Fixup other code

* Implement Flow diffing

* Implement resource type

* Remaining impls

* WIP

* Fix missing file error

* Fix misstyping

* Improve error message

* Fix type inferrence

* Allow REMOVE everywhere

* Fix empty changeset

* Fix error message

* Fix type inferrence 2

* Fix variable diffs

* Fix include checks

* Move push & pull

* Handle script in sync

* Handle scripts

* Allow multi-path creation

* Fix merge conflicts

* Fix #1173

* Update Dependencies

* Add missing await

* Apply review comments

* Fix diff

---------

Co-authored-by: Ruben Fiszel <ruben@rubenfiszel.com>
2023-02-03 19:49:46 +01:00

74 lines
1.8 KiB
TypeScript

import { Command } from "./deps.ts";
import { requireLogin, resolveWorkspace } from "./context.ts";
import { ResourceTypeFile } from "./resource-type.ts";
import { GlobalOptions } from "./types.ts";
async function pull(opts: GlobalOptions) {
const workspace = await resolveWorkspace(opts);
if (workspace.workspaceId !== "admins") {
console.log(
"Should only sync to admins workspace, but current is not admins.",
);
return;
}
await requireLogin(opts);
const list: {
id: number;
name: string;
schema: string;
approved: boolean;
app: string;
description: string;
created_by: string;
created_at: Date;
comments: never[];
}[] = await fetch(
"https://hub.windmill.dev/resource_types/list",
)
.then((r) => r.json())
.then((list: { id: number; name: string }[]) =>
list.map((x) =>
fetch(
"https://hub.windmill.dev/resource_types/" + x.id + "/" + x.name,
{
headers: {
"Accept": "application/json",
},
},
)
)
)
.then((x) => Promise.all(x))
.then((x) =>
x.map((x) =>
x.json().catch((e) => {
console.log(e);
return undefined;
})
)
)
.then((x) => Promise.all(x))
.then((x) => x.filter((x) => x).map((x) => x.resource_type));
for (
const x of list
) {
console.log("syncing " + x.name);
const f = new ResourceTypeFile();
f.description = x.description;
f.schema = JSON.parse(x.schema);
await f.push(workspace.workspaceId, x.name);
}
}
const command = new Command()
.name("hub")
.description("Hub related commands. EXPERIMENTAL. INTERNAL USE ONLY.")
.command("pull")
.description("pull any supported defintions. EXPERIMENTAL.")
.action(pull as any);
export default command;