Skip to content

Commit

Permalink
fix(cli): cli flow sync improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfiszel committed May 6, 2023
1 parent 36ecb3a commit e585e3a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cli/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface FlowFile {
schema?: any;
}

let alreadySynced: string[] = [];
const alreadySynced: string[] = [];

export async function pushFlow(
workspace: string,
Expand Down
20 changes: 14 additions & 6 deletions cli/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,23 @@ async function FSFSElement(p: string): Promise<DynFSElement> {
}

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));
},
Expand Down
8 changes: 6 additions & 2 deletions cli/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit e585e3a

Please sign in to comment.