From 46aab7e5ce4fe08390cd0059403c7c946bf62783 Mon Sep 17 00:00:00 2001 From: Adam Josefus <1031370+adamjosefus@users.noreply.github.com> Date: Tue, 22 Feb 2022 13:14:48 +0100 Subject: [PATCH 1/9] Update variableFilters.ts --- libs/model/variableFilters.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/libs/model/variableFilters.ts b/libs/model/variableFilters.ts index f78d387..80b34d5 100644 --- a/libs/model/variableFilters.ts +++ b/libs/model/variableFilters.ts @@ -1,6 +1,4 @@ - export const variableFilters: Map string> = new Map(); variableFilters.set("encodeUri", (s: string) => encodeURI(s)); - variableFilters.set("encodeUriComponent", (s: string) => encodeURIComponent(s)); From a61cf113ad9ede08e00759b2844c5a241e3c9629 Mon Sep 17 00:00:00 2001 From: Adam Josefus <1031370+adamjosefus@users.noreply.github.com> Date: Tue, 22 Feb 2022 13:15:14 +0100 Subject: [PATCH 2/9] Remove Demo --- demo/bar.token | 1 - demo/config.json | 18 ------------------ demo/demo.sh | 2 -- demo/packages/.gitignore | 2 -- 4 files changed, 23 deletions(-) delete mode 100644 demo/bar.token delete mode 100644 demo/config.json delete mode 100644 demo/demo.sh delete mode 100644 demo/packages/.gitignore diff --git a/demo/bar.token b/demo/bar.token deleted file mode 100644 index e8093c4..0000000 --- a/demo/bar.token +++ /dev/null @@ -1 +0,0 @@ -My token for BAR :-) \ No newline at end of file diff --git a/demo/config.json b/demo/config.json deleted file mode 100644 index e84f8d5..0000000 --- a/demo/config.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "destination": "./packages", - "variables": { - "FOO": "my-foo", - "BAR": { - "from": "./bar.token" - } - }, - "variables2": { - "FOO": "my-foo", - "BAR": "my-bar" - }, - "packages": { - "https://${FOO}:password@github.com/adamjosefus/allo_responses.git": { - "tag": "${BAR|encodeURIComponent}" - } - } -} \ No newline at end of file diff --git a/demo/demo.sh b/demo/demo.sh deleted file mode 100644 index 8ca241e..0000000 --- a/demo/demo.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -deno run -A ./pkg.ts --config=./demo/config.json --delete \ No newline at end of file diff --git a/demo/packages/.gitignore b/demo/packages/.gitignore deleted file mode 100644 index c96a04f..0000000 --- a/demo/packages/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore \ No newline at end of file From bc8aadfc298cb1232fd68b75f9bcb0591095fe1c Mon Sep 17 00:00:00 2001 From: Adam Josefus <1031370+adamjosefus@users.noreply.github.com> Date: Tue, 22 Feb 2022 13:29:15 +0100 Subject: [PATCH 3/9] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 5d91d99..b78fa67 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.DS_Store pkg.macos pkg.exe pkg.linux From df5b36201fd5ccf784d30e818be05bdc806f2960 Mon Sep 17 00:00:00 2001 From: Adam Josefus <1031370+adamjosefus@users.noreply.github.com> Date: Tue, 22 Feb 2022 13:29:43 +0100 Subject: [PATCH 4/9] Update COnfigSchema --- README.md | 4 ++-- libs/model/parseConfig.ts | 6 +++--- libs/types/ConfigSchema.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9e6c8cc..cf75b5e 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ deno run pkg.ts --help "from": "" } }, // optional - "packages": { + "repositories": { "": { "destination": "" // optional "name": "" // optional @@ -92,7 +92,7 @@ deno run pkg.ts --help "from": "./sercet.txt" } }, - "packages": { + "repositories": { "https://github.com/foo.git": [ { "name": "Foo_v1", diff --git a/libs/model/parseConfig.ts b/libs/model/parseConfig.ts index 41657c8..ea076de 100644 --- a/libs/model/parseConfig.ts +++ b/libs/model/parseConfig.ts @@ -29,16 +29,16 @@ export function parseConfig(json: string, configRoot: string, separateGitRoot: s const config: ConfigType = []; const data = JSON.parse(json) as ConfigSchema; const commonVars = crateVariables(configRoot, data.variables ?? {}); - const packages = data.packages ?? {}; + const repositories = data.repositories ?? {}; - for (const reference in packages) { + for (const reference in repositories) { // Normalize reference const settingsArr = (v => { if (v === true || v === null) return [{}]; if (v === false) return null; return Array.isArray(v) ? v : [v]; - })(packages[reference]); + })(repositories[reference]); // Skip if no settings if (settingsArr === null) break; diff --git a/libs/types/ConfigSchema.ts b/libs/types/ConfigSchema.ts index 0ee655c..62dc4f6 100644 --- a/libs/types/ConfigSchema.ts +++ b/libs/types/ConfigSchema.ts @@ -22,5 +22,5 @@ type PackageMapType = Record Date: Tue, 22 Feb 2022 13:38:27 +0100 Subject: [PATCH 5/9] Create parseConfig.test.ts --- tests/parseConfig.test.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/parseConfig.test.ts diff --git a/tests/parseConfig.test.ts b/tests/parseConfig.test.ts new file mode 100644 index 0000000..a45275b --- /dev/null +++ b/tests/parseConfig.test.ts @@ -0,0 +1,36 @@ +import { assertEquals } from "https://deno.land/std@0.126.0/testing/asserts.ts"; +import { parseConfig } from "../libs/model/parseConfig.ts"; + + +Deno.test("parseConfig", () => { + const configRoot = '/packages'; + const separateGitRoot = '/meta'; + + + const exercises = [ + { + json: `{ + "repositories": { + "https://github.com/my-repo.git": { + + } + } + }`, + expected: [ + { + destinationDir: "/packages/my-repo", + displayReference: "https://github.com/my-repo.git", + name: "my-repo", + reference: "https://github.com/my-repo.git", + separatedGitDir: "/meta/my-repo", + tag: null, + }, + ], + }, + ]; + + exercises.forEach((exercise) => { + const config = parseConfig(exercise.json, configRoot, separateGitRoot); + assertEquals(config, exercise.expected); + }); +}); \ No newline at end of file From 41c84278b7f1c12147e22b9b2fc519ecac780674 Mon Sep 17 00:00:00 2001 From: Adam Josefus <1031370+adamjosefus@users.noreply.github.com> Date: Tue, 22 Feb 2022 13:40:33 +0100 Subject: [PATCH 6/9] Update parseConfig.ts --- libs/model/parseConfig.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/model/parseConfig.ts b/libs/model/parseConfig.ts index ea076de..05e7ae0 100644 --- a/libs/model/parseConfig.ts +++ b/libs/model/parseConfig.ts @@ -34,8 +34,8 @@ export function parseConfig(json: string, configRoot: string, separateGitRoot: s for (const reference in repositories) { // Normalize reference const settingsArr = (v => { - if (v === true || v === null) return [{}]; - if (v === false) return null; + if (v === false || v === null) return null; + if (v === true) return [{}]; return Array.isArray(v) ? v : [v]; })(repositories[reference]); From cdab4eb3a22c2a14ccfddd2dee2cf0835593cdb4 Mon Sep 17 00:00:00 2001 From: Adam Josefus <1031370+adamjosefus@users.noreply.github.com> Date: Tue, 22 Feb 2022 13:40:35 +0100 Subject: [PATCH 7/9] Update parseConfig.test.ts --- tests/parseConfig.test.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/parseConfig.test.ts b/tests/parseConfig.test.ts index a45275b..e4a1869 100644 --- a/tests/parseConfig.test.ts +++ b/tests/parseConfig.test.ts @@ -8,6 +8,10 @@ Deno.test("parseConfig", () => { const exercises = [ + { + json: `{}`, + expected: [], + }, { json: `{ "repositories": { @@ -27,6 +31,22 @@ Deno.test("parseConfig", () => { }, ], }, + { + json: `{ + "repositories": { + "https://github.com/my-repo.git": false + } + }`, + expected: [], + }, + { + json: `{ + "repositories": { + "https://github.com/my-repo.git": null + } + }`, + expected: [], + }, ]; exercises.forEach((exercise) => { From 82bceb7082af33276387666ab03a68ae2275cd4a Mon Sep 17 00:00:00 2001 From: Adam Josefus <1031370+adamjosefus@users.noreply.github.com> Date: Tue, 22 Feb 2022 13:47:21 +0100 Subject: [PATCH 8/9] Update parseConfig.test.ts --- tests/parseConfig.test.ts | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/tests/parseConfig.test.ts b/tests/parseConfig.test.ts index e4a1869..c27e85f 100644 --- a/tests/parseConfig.test.ts +++ b/tests/parseConfig.test.ts @@ -7,12 +7,18 @@ Deno.test("parseConfig", () => { const separateGitRoot = '/meta'; - const exercises = [ + const exercises: { + label: string, + json: string, + expected: unknown, + }[] = [ { + label: "Test 1", json: `{}`, expected: [], }, { + label: "Test 2", json: `{ "repositories": { "https://github.com/my-repo.git": { @@ -32,6 +38,7 @@ Deno.test("parseConfig", () => { ], }, { + label: "Test 3", json: `{ "repositories": { "https://github.com/my-repo.git": false @@ -40,6 +47,7 @@ Deno.test("parseConfig", () => { expected: [], }, { + label: "Test 4", json: `{ "repositories": { "https://github.com/my-repo.git": null @@ -47,10 +55,28 @@ Deno.test("parseConfig", () => { }`, expected: [], }, + { + label: "Test 5", + json: `{ + "repositories": { + "https://github.com/my-repo.git": true + } + }`, + expected: [ + { + destinationDir: "/packages/my-repo", + displayReference: "https://github.com/my-repo.git", + name: "my-repo", + reference: "https://github.com/my-repo.git", + separatedGitDir: "/meta/my-repo", + tag: null, + }, + ], + }, ]; - exercises.forEach((exercise) => { - const config = parseConfig(exercise.json, configRoot, separateGitRoot); - assertEquals(config, exercise.expected); + exercises.forEach(({ json, expected, label }) => { + const config = parseConfig(json, configRoot, separateGitRoot); + assertEquals(config, expected, label); }); }); \ No newline at end of file From f9db6d4abaddbeae6b3f791c28234dfddf3935da Mon Sep 17 00:00:00 2001 From: Adam Josefus <1031370+adamjosefus@users.noreply.github.com> Date: Tue, 22 Feb 2022 14:05:52 +0100 Subject: [PATCH 9/9] Update parseConfig.test.ts --- tests/parseConfig.test.ts | 66 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/parseConfig.test.ts b/tests/parseConfig.test.ts index c27e85f..55cad66 100644 --- a/tests/parseConfig.test.ts +++ b/tests/parseConfig.test.ts @@ -73,10 +73,76 @@ Deno.test("parseConfig", () => { }, ], }, + { + label: "Test 6", + json: `{ + "destination": "./subdir", + "repositories": { + "https://github.com/my-repo.git": true + } + }`, + expected: [ + { + destinationDir: "/packages/subdir/my-repo", + displayReference: "https://github.com/my-repo.git", + name: "my-repo", + reference: "https://github.com/my-repo.git", + separatedGitDir: "/meta/my-repo", + tag: null, + }, + ], + }, + { + label: "Test 7", + json: `{ + "destination": "./subdir", + "repositories": { + "https://github.com/my-repo.git": { + "destination": "./subdir2" + } + } + }`, + expected: [ + { + destinationDir: "/packages/subdir2/my-repo", + displayReference: "https://github.com/my-repo.git", + name: "my-repo", + reference: "https://github.com/my-repo.git", + separatedGitDir: "/meta/my-repo", + tag: null, + }, + ], + }, + { + label: "Test 8", + json: `{ + "destination": "./subdir", + "variables": { + "MY_VAR": "my-value" + }, + "repositories": { + "https://github.com/my-repo.git": { + "destination": "./subdir2/${"${MY_VAR}"}" + } + } + }`, + expected: [ + { + destinationDir: "/packages/subdir2/my-value/my-repo", + displayReference: "https://github.com/my-repo.git", + name: "my-repo", + reference: "https://github.com/my-repo.git", + separatedGitDir: "/meta/my-repo", + tag: null, + }, + ], + }, ]; + exercises.forEach(({ json, expected, label }) => { const config = parseConfig(json, configRoot, separateGitRoot); + assertEquals(config, expected, label); }); }); \ No newline at end of file