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 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/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 diff --git a/libs/model/parseConfig.ts b/libs/model/parseConfig.ts index 41657c8..05e7ae0 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; + if (v === false || v === null) return null; + if (v === true) return [{}]; return Array.isArray(v) ? v : [v]; - })(packages[reference]); + })(repositories[reference]); // Skip if no settings if (settingsArr === null) break; 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)); 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 { + const configRoot = '/packages'; + const separateGitRoot = '/meta'; + + + const exercises: { + label: string, + json: string, + expected: unknown, + }[] = [ + { + label: "Test 1", + json: `{}`, + expected: [], + }, + { + label: "Test 2", + 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, + }, + ], + }, + { + label: "Test 3", + json: `{ + "repositories": { + "https://github.com/my-repo.git": false + } + }`, + expected: [], + }, + { + label: "Test 4", + json: `{ + "repositories": { + "https://github.com/my-repo.git": null + } + }`, + 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, + }, + ], + }, + { + 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