From c371cb397ab3d0c534e2c553d1dfb1ad5176d2a6 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Thu, 14 Sep 2023 18:35:26 +0200 Subject: [PATCH] feat: cli sync on windows (#2283) * cli windows * update --- cli/apps.ts | 9 ++++++--- cli/deps.ts | 2 +- cli/flow.ts | 12 ++++++------ cli/folder.ts | 16 ++++++++++++---- cli/pull.ts | 4 +++- cli/resource.ts | 6 +++--- cli/script.ts | 10 ++++++---- cli/sync.ts | 21 +++++++++++++++------ cli/variable.ts | 6 +++--- 9 files changed, 55 insertions(+), 31 deletions(-) diff --git a/cli/apps.ts b/cli/apps.ts index 7d4659ec0c..6ae1a2ee9f 100644 --- a/cli/apps.ts +++ b/cli/apps.ts @@ -33,7 +33,10 @@ export async function pushApp( if (raw) { // deleting old app if it exists in raw mode try { - app = await AppService.getAppByPath({ workspace, path: remotePath }); + app = await AppService.getAppByPath({ + workspace, + path: remotePath.replaceAll("\\", "/"), + }); } catch { //ignore } @@ -45,7 +48,7 @@ export async function pushApp( } await AppService.updateApp({ workspace, - path: remotePath, + path: remotePath.replaceAll("\\", "/"), requestBody: { ...newApp, }, @@ -56,7 +59,7 @@ export async function pushApp( await AppService.createApp({ workspace, requestBody: { - path: remotePath, + path: remotePath.replaceAll("\\", "/"), ...newApp, }, }); diff --git a/cli/deps.ts b/cli/deps.ts index ecca5a5fce..1ca1f3ea4f 100644 --- a/cli/deps.ts +++ b/cli/deps.ts @@ -1,7 +1,7 @@ // windmill export { setClient } from "https://deno.land/x/windmill@v1.95.1/mod.ts"; export * from "https://deno.land/x/windmill@v1.95.1/windmill-api/index.ts"; - +export { SEP } from "https://deno.land/std@0.201.0/path/separator.ts"; // cliffy export { Command } from "https://deno.land/x/cliffy@v1.0.0-rc.2/command/mod.ts"; export { Table } from "https://deno.land/x/cliffy@v1.0.0-rc.2/table/table.ts"; diff --git a/cli/flow.ts b/cli/flow.ts index 5d0a02c92d..4baa5bcf9a 100644 --- a/cli/flow.ts +++ b/cli/flow.ts @@ -1,6 +1,6 @@ // deno-lint-ignore-file no-explicit-any import { GlobalOptions, isSuperset } from "./types.ts"; -import { log } from "./deps.ts"; +import { SEP, log } from "./deps.ts"; import { colors, Command, @@ -42,8 +42,8 @@ export async function pushFlow( // flow doesn't exist } - if (!localFlowPath.endsWith("/")) { - localFlowPath += "/"; + if (!localFlowPath.endsWith(SEP)) { + localFlowPath += SEP; } const localFlowRaw = await Deno.readTextFile(localFlowPath + "flow.yaml"); const localFlow = yamlParse(localFlowRaw) as FlowFile; @@ -74,9 +74,9 @@ export async function pushFlow( log.info(colors.bold.yellow(`Updating flow ${remotePath}...`)); await FlowService.updateFlow({ workspace: workspace, - path: remotePath, + path: remotePath.replaceAll("\\", "/"), requestBody: { - path: remotePath, + path: remotePath.replaceAll("\\", "/"), ...localFlow, }, }); @@ -85,7 +85,7 @@ export async function pushFlow( await FlowService.createFlow({ workspace: workspace, requestBody: { - path: remotePath, + path: remotePath.replaceAll("\\", "/"), ...localFlow, }, }); diff --git a/cli/folder.ts b/cli/folder.ts index 39d7afa592..cab4f17e18 100644 --- a/cli/folder.ts +++ b/cli/folder.ts @@ -1,5 +1,13 @@ // deno-lint-ignore-file no-explicit-any -import { colors, Command, Folder, FolderService, log, Table } from "./deps.ts"; +import { + colors, + Command, + Folder, + FolderService, + log, + SEP, + Table, +} from "./deps.ts"; import { requireLogin, resolveWorkspace, validatePath } from "./context.ts"; import { GlobalOptions, isSuperset, parseFromFile } from "./types.ts"; @@ -38,13 +46,13 @@ export async function pushFolder( localFolder: FolderFile, raw: boolean ): Promise { - if (name.startsWith("/")) { + if (name.startsWith(SEP)) { name = name.substring(1); } - if (name.startsWith("f/")) { + if (name.startsWith("f" + SEP)) { name = name.substring(2); } - name = name.split("/")[0]; + name = name.split(SEP)[0]; log.debug(`Processing local folder ${name}`); if (raw) { diff --git a/cli/pull.ts b/cli/pull.ts index eb94de40e3..0b1c2ed3d4 100644 --- a/cli/pull.ts +++ b/cli/pull.ts @@ -1,6 +1,6 @@ // deno-lint-ignore-file no-explicit-any import { GlobalOptions } from "./types.ts"; -import { colors, Command, JSZip } from "./deps.ts"; +import { colors, Command, JSZip, log } from "./deps.ts"; import { Workspace } from "./workspace.ts"; import { getHeaders } from "./utils.ts"; @@ -45,6 +45,8 @@ export async function downloadZip( colors.red("Failed to request tarball from API " + zipResponse.statusText) ); throw new Error(await zipResponse.text()); + } else { + log.debug(`Downloaded zip/tarball successfully`); } const blob = await zipResponse.blob(); return await JSZip.loadAsync(blob as any); diff --git a/cli/resource.ts b/cli/resource.ts index cbb67bf9e8..3eee8437b3 100644 --- a/cli/resource.ts +++ b/cli/resource.ts @@ -34,7 +34,7 @@ export async function pushResource( try { resource = await ResourceService.getResource({ workspace: workspace, - path: remotePath, + path: remotePath.replaceAll("\\", "/"), }); } catch { // flow doesn't exist @@ -47,7 +47,7 @@ export async function pushResource( await ResourceService.updateResource({ workspace: workspace, - path: remotePath, + path: remotePath.replaceAll("\\", "/"), requestBody: { ...localResource }, }); } else { @@ -63,7 +63,7 @@ export async function pushResource( await ResourceService.createResource({ workspace: workspace, requestBody: { - path: remotePath, + path: remotePath.replaceAll("\\", "/"), ...localResource, }, }); diff --git a/cli/script.ts b/cli/script.ts index 2424ca25b6..b6b40fa688 100644 --- a/cli/script.ts +++ b/cli/script.ts @@ -83,7 +83,9 @@ export async function handleFile( log.debug(`Processing local script ${path}`); alreadySynced.push(path); - const remotePath = path.substring(0, path.indexOf(".")); + const remotePath = path + .substring(0, path.indexOf(".")) + .replaceAll("\\", "/"); const metaPath = remotePath + ".script.json"; let typed = undefined; try { @@ -105,7 +107,7 @@ export async function handleFile( try { remote = await ScriptService.getScriptByPath({ workspace, - path: remotePath, + path: remotePath.replaceAll("\\", "/"), }); log.debug(`Script ${remotePath} exists on remote`); } catch { @@ -142,7 +144,7 @@ export async function handleFile( content, description: typed?.description ?? "", language: language as NewScript.language, - path: remotePath, + path: remotePath.replaceAll("\\", "/"), summary: typed?.summary ?? "", is_template: typed?.is_template, kind: typed?.kind, @@ -162,7 +164,7 @@ export async function handleFile( content, description: typed?.description ?? "", language: language as NewScript.language, - path: remotePath, + path: remotePath.replaceAll("\\", "/"), summary: typed?.summary ?? "", is_template: typed?.is_template, kind: typed?.kind, diff --git a/cli/sync.ts b/cli/sync.ts index 3b1fc5619e..70b1e51a13 100644 --- a/cli/sync.ts +++ b/cli/sync.ts @@ -20,6 +20,7 @@ import { yamlStringify, yamlParse, ScheduleService, + SEP, } from "./deps.ts"; import { getTypeStrFromPath, @@ -237,7 +238,7 @@ function ZipFSElement(zip: JSZip, useYaml: boolean): DynFSElement { }, }; } - return _internal_folder("./", zip); + return _internal_folder("." + SEP, zip); } async function* readDirRecursiveWithIgnore( @@ -353,19 +354,27 @@ async function compareDynFSElement( } const isNotWmillFile = (p: string, isDirectory: boolean) => { - if (p.endsWith("/")) { + if (p.endsWith(SEP)) { return false; } if (isDirectory) { - return !p.startsWith("u/") && !p.startsWith("f/") && !p.startsWith("g/"); + return ( + !p.startsWith("u" + SEP) && + !p.startsWith("f" + SEP) && + !p.startsWith("g" + SEP) + ); } try { const typ = getTypeStrFromPath(p); if (typ == "resource-type") { - return p.includes("/"); + return p.includes(SEP); } else { - return !p.startsWith("u/") && !p.startsWith("f/") && !p.startsWith("g/"); + return ( + !p.startsWith("u" + SEP) && + !p.startsWith("f" + SEP) && + !p.startsWith("g" + SEP) + ); } } catch { return true; @@ -373,7 +382,7 @@ const isNotWmillFile = (p: string, isDirectory: boolean) => { }; export const isWhitelisted = (p: string) => { - return p == "./" || p == "" || p == "u" || p == "f" || p == "g"; + return p == "." + SEP || p == "" || p == "u" || p == "f" || p == "g"; }; export async function ignoreF() { try { diff --git a/cli/variable.ts b/cli/variable.ts index fa27d3bf0d..eebae09af6 100644 --- a/cli/variable.ts +++ b/cli/variable.ts @@ -62,7 +62,7 @@ export async function pushVariable( try { variable = await VariableService.getVariable({ workspace: workspace, - path: remotePath, + path: remotePath.replaceAll("\\", "/"), decryptSecret: plainSecrets, }); log.debug(`Variable ${remotePath} exists on remote`); @@ -80,7 +80,7 @@ export async function pushVariable( await VariableService.updateVariable({ workspace, - path: remotePath, + path: remotePath.replaceAll("\\", "/"), alreadyEncrypted: !plainSecrets, requestBody: { ...localVariable, @@ -94,7 +94,7 @@ export async function pushVariable( workspace, alreadyEncrypted: !plainSecrets, requestBody: { - path: remotePath, + path: remotePath.replaceAll("\\", "/"), ...localVariable, }, });