From e585e3aea2b18b6dc0c9fa7ffa1e6c1dfb2a3ce2 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Sat, 6 May 2023 11:06:32 +0200 Subject: [PATCH] fix(cli): cli flow sync improvements --- cli/flow.ts | 2 +- cli/sync.ts | 20 ++++++++++++++------ cli/types.ts | 8 ++++++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/cli/flow.ts b/cli/flow.ts index 0f2bbac22d..91aa98b9a2 100644 --- a/cli/flow.ts +++ b/cli/flow.ts @@ -21,7 +21,7 @@ export interface FlowFile { schema?: any; } -let alreadySynced: string[] = []; +const alreadySynced: string[] = []; export async function pushFlow( workspace: string, diff --git a/cli/sync.ts b/cli/sync.ts index 3dc7b9b27f..e0ef5d9fd1 100644 --- a/cli/sync.ts +++ b/cli/sync.ts @@ -70,15 +70,23 @@ async function FSFSElement(p: string): Promise { } function prioritizeName(name: string): string { - if (name == "summary") return "aa"; - if (name == "name") return "aaaa"; - if (name == "display_name") return "aaa"; - if (name == "description") return "ab"; - if (name == "value") return "ac"; + if (name == "id") return "a"; + if (name == "type") return "b"; + if (name == "summary") return "d"; + if (name == "name") return "e"; + if (name == "display_name") return "f"; + if (name == "description") return "g"; + if (name == "value") return "h"; + if (name == "content") return "i"; + if (name == "modules") return "j"; + if (name == "failure_modules") return "k"; + if (name == "input_transforms") return "l"; + if (name == "lock") return "z"; + return name; } -const yamlOptions = { +export const yamlOptions = { sortKeys: (a: any, b: any) => { return prioritizeName(a).localeCompare(prioritizeName(b)); }, diff --git a/cli/types.ts b/cli/types.ts index f15337f462..0b9e23903f 100644 --- a/cli/types.ts +++ b/cli/types.ts @@ -14,6 +14,7 @@ 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"; export interface DifferenceCreate { type: "CREATE"; @@ -54,7 +55,10 @@ export function isSuperset( console.log(`Key ${key} not found in remote`); } else { console.log(`Found diff for ${key}:`); - showDiff(yamlStringify(sub), yamlStringify(supers)); + showDiff( + yamlStringify(sub, yamlOptions), + yamlStringify(supers, yamlOptions) + ); } } return eq; @@ -79,7 +83,7 @@ export function showDiff(local: string, remote: string) { lines = lines.concat(part.value.split("\n").slice(-2)); } // print white if unchanged - finalString += `\x1b[37m${part.value}\x1b[0m`; + finalString += `\x1b[37m${lines.join("\n")}\x1b[0m`; } } console.log(finalString);