Skip to content

Commit

Permalink
migrate more to windmill-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfiszel committed Sep 7, 2024
1 parent 9b4c598 commit 47f0ece
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 21 deletions.
3 changes: 1 addition & 2 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ You can find more information in

## Installation

Install the `wmill` CLI tool using
`deno install --unstable -A https://deno.land/x/wmill/main.ts`.
Install the `wmill` CLI tool using `npm install -g windmill-cli`.

Update to the latest version using `wmill upgrade`.

Expand Down
2 changes: 1 addition & 1 deletion cli/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export async function requireLogin(
}

export async function fetchVersion(baseUrl: string): Promise<string> {
const requestHeaders: HeadersInit = new Headers();
const requestHeaders = new Headers();

const extraHeaders = getHeaders();
if (extraHeaders) {
Expand Down
3 changes: 2 additions & 1 deletion cli/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@std/net": "jsr:@std/net@^1.0.2",
"@std/path": "jsr:@std/path@^1.0.4",
"@std/streams": "jsr:@std/streams@^1.0.4",
"@std/yaml": "jsr:@std/yaml@^1.0.5"
"@std/yaml": "jsr:@std/yaml@^1.0.5",
"@types/diff": "npm:@types/diff@^5.2.2"
}
}
24 changes: 23 additions & 1 deletion cli/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export { stringify as yamlStringify, parse as yamlParse } from "jsr:@std/yaml";

// other

export * as Diff from "npm:diff";
export { minimatch } from "npm:minimatch";
export { default as JSZip } from "npm:[email protected]";

Expand Down
16 changes: 15 additions & 1 deletion cli/dnt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,34 @@ await build({
name: "wmill", // command name
path: "./main.ts",
},
"main.ts",
],
outDir: "./npm",
shims: {
// see JS docs for overview and more options
deno: true,
},
typeCheck: false,
scriptModule: false,
filterDiagnostic(diagnostic) {
if (
diagnostic.file?.fileName.includes("node_modules/") ||
diagnostic.file?.fileName.includes("src/deps/") ||
diagnostic.file?.fileName.includes("src/deps.ts") ||
diagnostic.file?.fileName.includes("src/utils.ts")
) {
return false; // ignore all diagnostics in this file
}
// console.log(diagnostic.file?.fileName);
return true;
},
declaration: "separate",
package: {
// package.json properties
name: "windmill-cli",
version: VERSION,
description: "CLI for Windmill",
license: "Apache 2.0",
main: "esm/main.js",
repository: {
type: "git",
url: "git+https://github.com/windmill-labs/windmill.git",
Expand Down
10 changes: 7 additions & 3 deletions cli/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { pushResourceType } from "./resource-type.ts";
import { GlobalOptions } from "./types.ts";
import { deepEqual } from "./utils.ts";

async function pull(opts: GlobalOptions) {
export async function pull(opts: GlobalOptions) {
const workspace = await resolveWorkspace(opts);

if (workspace.workspaceId !== "admins") {
Expand Down Expand Up @@ -48,7 +48,7 @@ async function pull(opts: GlobalOptions) {
}[] = await fetch(hubBaseUrl + "/resource_types/list", {
headers,
})
.then((r) => r.json())
.then((r) => r.json() as Promise<{ id: number; name: string }[]>)
.then((list: { id: number; name: string }[]) =>
list.map((x) =>
fetch(hubBaseUrl + "/resource_types/" + x.id + "/" + x.name, {
Expand All @@ -68,7 +68,11 @@ async function pull(opts: GlobalOptions) {
)
)
.then((x) => Promise.all(x))
.then((x) => x.filter((x) => x).map((x) => x.resource_type));
.then((x) =>
(x as { resource_type: any }[])
.filter((x) => x)
.map((x) => x.resource_type)
);

const resourceTypes = await ResourceService.listResourceType({
workspace: workspace.workspaceId,
Expand Down
30 changes: 26 additions & 4 deletions cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import workspace, { getActiveWorkspace } from "./workspace.ts";
import resource from "./resource.ts";
import user from "./user.ts";
import variable from "./variable.ts";
import push from "./push.ts";
import pull from "./pull.ts";
import lgeacyPush from "./push.ts";
import legacyPull from "./pull.ts";
import hub from "./hub.ts";
import folder from "./folder.ts";
import schedule from "./schedule.ts";
Expand All @@ -27,6 +27,29 @@ import { GlobalOptions } from "./types.ts";
import { OpenAPI } from "./deps.ts";
import { getHeaders } from "./utils.ts";
import { NpmProvider } from "./upgrade.ts";
import { pull as hubPull } from "./hub.ts";
import { pull, push } from "./sync.ts";

export {
flow,
app,
script,
workspace,
resource,
user,
variable,
hub,
folder,
schedule,
sync,
instance,
dev,
lgeacyPush,
legacyPull,
hubPull,
pull,
push,
};

// addEventListener("error", (event) => {
// if (event.error) {
Expand All @@ -37,7 +60,6 @@ import { NpmProvider } from "./upgrade.ts";

export const VERSION = "1.392.0";


let command: any = new Command()
.name("wmill")
.action(() =>
Expand Down Expand Up @@ -115,7 +137,7 @@ let command: any = new Command()
)
.command("completions", new CompletionsCommand());
if (Number.parseInt(VERSION.replace("v", "").replace(".", "")) > 1700) {
command = command.command("push", push).command("pull", pull);
command = command.command("push", lgeacyPush).command("pull", legacyPull);
}

export let showDiffs = false;
Expand Down
6 changes: 4 additions & 2 deletions cli/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,10 @@ export async function updateFlow(

let responseText = "reading response failed";
try {
const res = await rawResponse.json();
return res?.["updated_flow_value"];
const res = (await rawResponse.json()) as
| { updated_flow_value: any }
| undefined;
return res?.updated_flow_value;
} catch (e) {
try {
responseText = await rawResponse.text();
Expand Down
3 changes: 1 addition & 2 deletions cli/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ export async function downloadZip(
includeKey?: boolean,
defaultTs?: "bun" | "deno"
): Promise<JSZip | undefined> {
const requestHeaders: HeadersInit & { set(x: string, y: string): void } =
new Headers();
const requestHeaders = new Headers();
requestHeaders.set("Authorization", "Bearer " + workspace.token);
requestHeaders.set("Content-Type", "application/octet-stream");

Expand Down
4 changes: 4 additions & 0 deletions cli/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ export async function handleFile(
target: "node20.15.1",
});
bundleContent = out.outputFiles[0].text;
log.info(
"Bundle size: " + (bundleContent.length / 1024).toFixed(0) + "kB"
);
}
if (Array.isArray(codebase.assets) && codebase.assets.length > 0) {
const archiveNpm = await import("npm:@ayonli/jsext/archive");
Expand All @@ -199,6 +202,7 @@ export async function handleFile(
const file = new File([blob], asset.to);
tarball.append(file);
}
log.info("Tarball size: " + (tarball.size / 1024).toFixed(0) + "kB");
bundleContent = tarball;
}
log.info(`Finished building the bundle for ${path}`);
Expand Down
1 change: 1 addition & 0 deletions cli/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ export async function pushInstanceSettings(
localSettings = localSettings.filter((s) => s.name !== "base_url");
localSettings.push({
name: "base_url",
//@ts-ignore
value: baseUrl,
});
}
Expand Down
11 changes: 9 additions & 2 deletions cli/types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
// deno-lint-ignore-file no-explicit-any

import { SEP, colors, log, path, yamlParse, yamlStringify } from "./deps.ts";
import {
Diff,
SEP,
colors,
log,
path,
yamlParse,
yamlStringify,
} from "./deps.ts";
import { pushApp } from "./apps.ts";
import { pushFolder } from "./folder.ts";
import { pushFlow } from "./flow.ts";
import { pushResource } from "./resource.ts";
import { pushResourceType } from "./resource-type.ts";
import { pushVariable } from "./variable.ts";
import * as Diff from "npm:diff";
import { yamlOptions } from "./sync.ts";
import { showDiffs } from "./main.ts";
import { deepEqual } from "./utils.ts";
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lib/components/CliHelpBox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<div class="text-sm" role="alert" id="dynamic-input-help-box">
<ul class="pl-0 pt-2 list-decimal list-inside flex flex-col gap-2">
<li>
Install the latest wmill CLI from deno.land:
<ClipboardPanel content={'deno install -q -A https://deno.land/x/wmill/main.ts'} />
Install the latest wmill CLI from npm:
<ClipboardPanel content={'npm install -g windmill-cli'} />
</li>

<li>
Expand Down

0 comments on commit 47f0ece

Please sign in to comment.