@hanseltime/template-repo-sync 2.3.0 → 2.4.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -46
- package/dist/cjs/checkout-drivers/git-checkout.js +37 -0
- package/dist/cjs/checkout-drivers/git-checkout.spec.js +60 -0
- package/dist/cjs/checkout-drivers/index.js +21 -0
- package/dist/cjs/checkout-drivers/types.js +11 -0
- package/dist/cjs/clone-drivers/git-clone.js +25 -0
- package/dist/cjs/clone-drivers/index.js +21 -0
- package/dist/cjs/clone-drivers/types.js +8 -0
- package/dist/cjs/diff-drivers/git-diff.js +30 -0
- package/dist/cjs/diff-drivers/git-diff.spec.js +138 -0
- package/dist/cjs/diff-drivers/index.js +21 -0
- package/dist/cjs/diff-drivers/types.js +6 -0
- package/dist/cjs/formatting/index.js +21 -0
- package/dist/cjs/formatting/infer-json-indent.js +26 -0
- package/dist/cjs/formatting/infer-json-indent.spec.js +50 -0
- package/dist/cjs/formatting/sync-results-to-md.js +62 -0
- package/dist/cjs/formatting/sync-results-to-md.spec.js +45 -0
- package/dist/cjs/index.js +22 -0
- package/dist/cjs/load-plugin.js +44 -0
- package/dist/cjs/match.js +51 -0
- package/dist/cjs/match.spec.js +75 -0
- package/dist/cjs/merge-file.js +91 -0
- package/dist/cjs/merge-file.spec.js +508 -0
- package/dist/cjs/plugins/index.js +20 -0
- package/dist/cjs/plugins/json-merge.js +228 -0
- package/dist/cjs/plugins/json-merge.spec.js +514 -0
- package/dist/cjs/ref-drivers/git-current-ref.js +18 -0
- package/dist/cjs/ref-drivers/git-current-ref.spec.js +15 -0
- package/dist/cjs/ref-drivers/index.js +20 -0
- package/dist/cjs/ref-drivers/types.js +11 -0
- package/dist/cjs/template-sync.js +236 -0
- package/dist/cjs/template-sync.spec.js +521 -0
- package/dist/cjs/test-utils/index.js +26 -0
- package/dist/cjs/types.js +12 -0
- package/dist/esm/checkout-drivers/git-checkout.mjs +27 -0
- package/dist/esm/checkout-drivers/git-checkout.spec.mjs +56 -0
- package/dist/esm/checkout-drivers/index.mjs +4 -0
- package/dist/esm/checkout-drivers/types.mjs +8 -0
- package/dist/esm/clone-drivers/git-clone.mjs +15 -0
- package/dist/esm/clone-drivers/index.mjs +4 -0
- package/dist/esm/clone-drivers/types.mjs +8 -0
- package/dist/esm/diff-drivers/git-diff.mjs +26 -0
- package/dist/esm/diff-drivers/git-diff.spec.mjs +93 -0
- package/dist/esm/diff-drivers/index.mjs +4 -0
- package/dist/esm/diff-drivers/types.mjs +6 -0
- package/dist/esm/formatting/index.mjs +4 -0
- package/dist/esm/formatting/infer-json-indent.mjs +16 -0
- package/dist/esm/formatting/infer-json-indent.spec.mjs +46 -0
- package/dist/esm/formatting/sync-results-to-md.mjs +52 -0
- package/dist/esm/formatting/sync-results-to-md.spec.mjs +41 -0
- package/dist/esm/index.mjs +5 -0
- package/dist/esm/load-plugin.mjs +40 -0
- package/dist/esm/match.mjs +40 -0
- package/dist/esm/match.spec.mjs +71 -0
- package/dist/esm/merge-file.mjs +88 -0
- package/dist/esm/merge-file.spec.mjs +504 -0
- package/dist/esm/plugins/index.mjs +10 -0
- package/dist/esm/plugins/json-merge.mjs +164 -0
- package/dist/esm/plugins/json-merge.spec.mjs +469 -0
- package/dist/esm/ref-drivers/git-current-ref.mjs +8 -0
- package/dist/esm/ref-drivers/git-current-ref.spec.mjs +11 -0
- package/dist/esm/ref-drivers/index.mjs +3 -0
- package/dist/esm/ref-drivers/types.mjs +8 -0
- package/dist/esm/template-sync.mjs +174 -0
- package/dist/esm/template-sync.spec.mjs +517 -0
- package/dist/esm/test-utils/index.mjs +10 -0
- package/dist/esm/types.mjs +9 -0
- package/{lib/cjs → dist/types}/checkout-drivers/git-checkout.d.ts +1 -0
- package/dist/types/checkout-drivers/git-checkout.d.ts.map +1 -0
- package/dist/types/checkout-drivers/git-checkout.spec.d.ts +2 -0
- package/dist/types/checkout-drivers/git-checkout.spec.d.ts.map +1 -0
- package/{lib/cjs → dist/types}/checkout-drivers/index.d.ts +1 -0
- package/dist/types/checkout-drivers/index.d.ts.map +1 -0
- package/{lib/cjs → dist/types}/checkout-drivers/types.d.ts +1 -0
- package/dist/types/checkout-drivers/types.d.ts.map +1 -0
- package/{lib/cjs → dist/types}/clone-drivers/git-clone.d.ts +2 -1
- package/dist/types/clone-drivers/git-clone.d.ts.map +1 -0
- package/{lib/cjs → dist/types}/clone-drivers/index.d.ts +2 -1
- package/dist/types/clone-drivers/index.d.ts.map +1 -0
- package/{lib/cjs → dist/types}/clone-drivers/types.d.ts +1 -0
- package/dist/types/clone-drivers/types.d.ts.map +1 -0
- package/{lib/cjs → dist/types}/diff-drivers/git-diff.d.ts +1 -0
- package/dist/types/diff-drivers/git-diff.d.ts.map +1 -0
- package/dist/types/diff-drivers/git-diff.spec.d.ts +2 -0
- package/dist/types/diff-drivers/git-diff.spec.d.ts.map +1 -0
- package/{lib/cjs → dist/types}/diff-drivers/index.d.ts +2 -1
- package/dist/types/diff-drivers/index.d.ts.map +1 -0
- package/{lib/cjs → dist/types}/diff-drivers/types.d.ts +1 -0
- package/dist/types/diff-drivers/types.d.ts.map +1 -0
- package/{lib/cjs → dist/types}/formatting/index.d.ts +2 -1
- package/dist/types/formatting/index.d.ts.map +1 -0
- package/{lib/cjs → dist/types}/formatting/infer-json-indent.d.ts +1 -0
- package/dist/types/formatting/infer-json-indent.d.ts.map +1 -0
- package/dist/types/formatting/infer-json-indent.spec.d.ts +2 -0
- package/dist/types/formatting/infer-json-indent.spec.d.ts.map +1 -0
- package/dist/types/formatting/sync-results-to-md.d.ts +3 -0
- package/dist/types/formatting/sync-results-to-md.d.ts.map +1 -0
- package/dist/types/formatting/sync-results-to-md.spec.d.ts +2 -0
- package/dist/types/formatting/sync-results-to-md.spec.d.ts.map +1 -0
- package/{lib/cjs → dist/types}/index.d.ts +3 -2
- package/dist/types/index.d.ts.map +1 -0
- package/{lib/cjs → dist/types}/load-plugin.d.ts +2 -1
- package/dist/types/load-plugin.d.ts.map +1 -0
- package/{lib/cjs → dist/types}/match.d.ts +1 -0
- package/dist/types/match.d.ts.map +1 -0
- package/dist/types/match.spec.d.ts +2 -0
- package/dist/types/match.spec.d.ts.map +1 -0
- package/{lib/cjs → dist/types}/merge-file.d.ts +3 -2
- package/dist/types/merge-file.d.ts.map +1 -0
- package/dist/types/merge-file.spec.d.ts +2 -0
- package/dist/types/merge-file.spec.d.ts.map +1 -0
- package/{lib/cjs → dist/types}/plugins/index.d.ts +2 -1
- package/dist/types/plugins/index.d.ts.map +1 -0
- package/{lib/cjs → dist/types}/plugins/json-merge.d.ts +2 -1
- package/dist/types/plugins/json-merge.d.ts.map +1 -0
- package/dist/types/plugins/json-merge.spec.d.ts +2 -0
- package/dist/types/plugins/json-merge.spec.d.ts.map +1 -0
- package/{lib/cjs → dist/types}/ref-drivers/git-current-ref.d.ts +1 -0
- package/dist/types/ref-drivers/git-current-ref.d.ts.map +1 -0
- package/dist/types/ref-drivers/git-current-ref.spec.d.ts +2 -0
- package/dist/types/ref-drivers/git-current-ref.spec.d.ts.map +1 -0
- package/{lib/cjs → dist/types}/ref-drivers/index.d.ts +1 -0
- package/dist/types/ref-drivers/index.d.ts.map +1 -0
- package/{lib/cjs → dist/types}/ref-drivers/types.d.ts +1 -0
- package/dist/types/ref-drivers/types.d.ts.map +1 -0
- package/{lib/cjs → dist/types}/template-sync.d.ts +6 -5
- package/dist/types/template-sync.d.ts.map +1 -0
- package/dist/types/template-sync.spec.d.ts +2 -0
- package/dist/types/template-sync.spec.d.ts.map +1 -0
- package/{lib/cjs → dist/types}/test-utils/index.d.ts +1 -0
- package/dist/types/test-utils/index.d.ts.map +1 -0
- package/{lib/cjs → dist/types}/types.d.ts +1 -0
- package/dist/types/types.d.ts.map +1 -0
- package/package.json +26 -23
- package/.eslintrc.js +0 -10
- package/.github/CODEOWNERS +0 -6
- package/.github/workflows/pr-checks.yaml +0 -12
- package/.github/workflows/release.yaml +0 -47
- package/.github/workflows/test-flow.yaml +0 -63
- package/.husky/commit-msg +0 -4
- package/.prettierignore +0 -1
- package/.prettierrc +0 -1
- package/action.yml +0 -13
- package/commitlint.config.js +0 -3
- package/docs/merge-plugins/CURRENT_PLUGINS.md +0 -168
- package/docs/merge-plugins/PLUGIN_DEVELOPMENT.md +0 -122
- package/docs/merge-plugins/README.md +0 -75
- package/jest.config.js +0 -19
- package/lib/cjs/checkout-drivers/git-checkout.js +0 -29
- package/lib/cjs/checkout-drivers/index.js +0 -18
- package/lib/cjs/checkout-drivers/types.js +0 -2
- package/lib/cjs/clone-drivers/git-clone.js +0 -17
- package/lib/cjs/clone-drivers/index.js +0 -18
- package/lib/cjs/clone-drivers/types.js +0 -2
- package/lib/cjs/diff-drivers/git-diff.js +0 -41
- package/lib/cjs/diff-drivers/index.js +0 -18
- package/lib/cjs/diff-drivers/types.js +0 -2
- package/lib/cjs/formatting/index.js +0 -18
- package/lib/cjs/formatting/infer-json-indent.js +0 -18
- package/lib/cjs/formatting/sync-results-to-md.d.ts +0 -2
- package/lib/cjs/formatting/sync-results-to-md.js +0 -57
- package/lib/cjs/index.js +0 -19
- package/lib/cjs/load-plugin.js +0 -69
- package/lib/cjs/match.js +0 -45
- package/lib/cjs/merge-file.js +0 -98
- package/lib/cjs/plugins/index.js +0 -11
- package/lib/cjs/plugins/json-merge.js +0 -208
- package/lib/cjs/ref-drivers/git-current-ref.js +0 -12
- package/lib/cjs/ref-drivers/index.js +0 -17
- package/lib/cjs/ref-drivers/types.js +0 -2
- package/lib/cjs/template-sync.js +0 -204
- package/lib/cjs/test-utils/index.js +0 -10
- package/lib/cjs/types.js +0 -2
- package/lib/esm/checkout-drivers/git-checkout.js +0 -29
- package/lib/esm/checkout-drivers/index.js +0 -18
- package/lib/esm/checkout-drivers/types.js +0 -2
- package/lib/esm/clone-drivers/git-clone.js +0 -17
- package/lib/esm/clone-drivers/index.js +0 -18
- package/lib/esm/clone-drivers/types.js +0 -2
- package/lib/esm/diff-drivers/git-diff.js +0 -41
- package/lib/esm/diff-drivers/index.js +0 -18
- package/lib/esm/diff-drivers/types.js +0 -2
- package/lib/esm/formatting/index.js +0 -18
- package/lib/esm/formatting/infer-json-indent.js +0 -18
- package/lib/esm/formatting/sync-results-to-md.js +0 -57
- package/lib/esm/index.js +0 -19
- package/lib/esm/load-plugin.js +0 -46
- package/lib/esm/match.js +0 -45
- package/lib/esm/merge-file.js +0 -98
- package/lib/esm/plugins/index.js +0 -11
- package/lib/esm/plugins/json-merge.js +0 -208
- package/lib/esm/ref-drivers/git-current-ref.js +0 -12
- package/lib/esm/ref-drivers/index.js +0 -17
- package/lib/esm/ref-drivers/types.js +0 -2
- package/lib/esm/template-sync.js +0 -204
- package/lib/esm/test-utils/index.js +0 -10
- package/lib/esm/types.js +0 -2
- package/release.config.js +0 -40
- package/src/checkout-drivers/git-checkout.spec.ts +0 -69
- package/src/checkout-drivers/git-checkout.ts +0 -38
- package/src/checkout-drivers/index.ts +0 -2
- package/src/checkout-drivers/types.ts +0 -14
- package/src/clone-drivers/git-clone.ts +0 -20
- package/src/clone-drivers/index.ts +0 -2
- package/src/clone-drivers/types.ts +0 -20
- package/src/diff-drivers/git-diff.spec.ts +0 -73
- package/src/diff-drivers/git-diff.ts +0 -39
- package/src/diff-drivers/index.ts +0 -2
- package/src/diff-drivers/types.ts +0 -14
- package/src/formatting/__snapshots__/sync-results-to-md.spec.ts.snap +0 -39
- package/src/formatting/index.ts +0 -2
- package/src/formatting/infer-json-indent.spec.ts +0 -49
- package/src/formatting/infer-json-indent.ts +0 -16
- package/src/formatting/sync-results-to-md.spec.ts +0 -31
- package/src/formatting/sync-results-to-md.ts +0 -63
- package/src/index.ts +0 -3
- package/src/load-plugin.ts +0 -51
- package/src/match.spec.ts +0 -68
- package/src/match.ts +0 -52
- package/src/merge-file.spec.ts +0 -506
- package/src/merge-file.ts +0 -154
- package/src/plugins/index.ts +0 -12
- package/src/plugins/json-merge.spec.ts +0 -436
- package/src/plugins/json-merge.ts +0 -215
- package/src/ref-drivers/git-current-ref.spec.ts +0 -12
- package/src/ref-drivers/git-current-ref.ts +0 -9
- package/src/ref-drivers/index.ts +0 -1
- package/src/ref-drivers/types.ts +0 -10
- package/src/template-sync.spec.ts +0 -602
- package/src/template-sync.ts +0 -304
- package/src/test-utils/index.ts +0 -13
- package/src/types.ts +0 -129
- package/templatesync.local.json +0 -15
- package/test-fixtures/downstream/README.md +0 -3
- package/test-fixtures/downstream/package.json +0 -18
- package/test-fixtures/downstream/plugins/custom-plugin.js +0 -14
- package/test-fixtures/downstream/plugins/fail-validate-plugin.js +0 -14
- package/test-fixtures/downstream/src/index.js +0 -2
- package/test-fixtures/downstream/src/index.ts +0 -1
- package/test-fixtures/downstream/src/templated.js +0 -2
- package/test-fixtures/downstream/src/templated.ts +0 -1
- package/test-fixtures/downstream/templatesync.json +0 -16
- package/test-fixtures/downstream/templatesync.local.json +0 -10
- package/test-fixtures/dummy-plugin.js +0 -8
- package/test-fixtures/glob-test/folder1/something.js +0 -1
- package/test-fixtures/glob-test/folder1/something.ts +0 -0
- package/test-fixtures/glob-test/toplevel.js +0 -0
- package/test-fixtures/glob-test/toplevel.txt +0 -0
- package/test-fixtures/template/custom-bin/something.txt +0 -1
- package/test-fixtures/template/dummy-fail-plugin.js +0 -8
- package/test-fixtures/template/package.json +0 -17
- package/test-fixtures/template/src/index.js +0 -2
- package/test-fixtures/template/src/index.ts +0 -1
- package/test-fixtures/template/src/templated.js +0 -2
- package/test-fixtures/template/src/templated.ts +0 -1
- package/test-fixtures/template/templatesync.json +0 -16
- package/test-fixtures/testGitRepo/README.md +0 -17
- package/test-fixtures/testGitRepo/gitDir/COMMIT_EDITMSG +0 -14
- package/test-fixtures/testGitRepo/gitDir/HEAD +0 -1
- package/test-fixtures/testGitRepo/gitDir/config +0 -7
- package/test-fixtures/testGitRepo/gitDir/description +0 -1
- package/test-fixtures/testGitRepo/gitDir/hooks/applypatch-msg.sample +0 -15
- package/test-fixtures/testGitRepo/gitDir/hooks/commit-msg.sample +0 -24
- package/test-fixtures/testGitRepo/gitDir/hooks/fsmonitor-watchman.sample +0 -174
- package/test-fixtures/testGitRepo/gitDir/hooks/post-update.sample +0 -8
- package/test-fixtures/testGitRepo/gitDir/hooks/pre-applypatch.sample +0 -14
- package/test-fixtures/testGitRepo/gitDir/hooks/pre-commit.sample +0 -49
- package/test-fixtures/testGitRepo/gitDir/hooks/pre-merge-commit.sample +0 -13
- package/test-fixtures/testGitRepo/gitDir/hooks/pre-push.sample +0 -53
- package/test-fixtures/testGitRepo/gitDir/hooks/pre-rebase.sample +0 -169
- package/test-fixtures/testGitRepo/gitDir/hooks/pre-receive.sample +0 -24
- package/test-fixtures/testGitRepo/gitDir/hooks/prepare-commit-msg.sample +0 -42
- package/test-fixtures/testGitRepo/gitDir/hooks/push-to-checkout.sample +0 -78
- package/test-fixtures/testGitRepo/gitDir/hooks/sendemail-validate.sample +0 -77
- package/test-fixtures/testGitRepo/gitDir/hooks/update.sample +0 -128
- package/test-fixtures/testGitRepo/gitDir/index +0 -0
- package/test-fixtures/testGitRepo/gitDir/info/exclude +0 -6
- package/test-fixtures/testGitRepo/gitDir/logs/HEAD +0 -5
- package/test-fixtures/testGitRepo/gitDir/logs/refs/heads/master +0 -2
- package/test-fixtures/testGitRepo/gitDir/logs/refs/heads/test-branch +0 -2
- package/test-fixtures/testGitRepo/gitDir/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 +0 -0
- package/test-fixtures/testGitRepo/gitDir/objects/6e/187bee8d02f39d0a1be8331dd8fe6a00c9b613 +0 -0
- package/test-fixtures/testGitRepo/gitDir/objects/73/185f1f3f5a6345e087d9f46dc4af77cc59449f +0 -2
- package/test-fixtures/testGitRepo/gitDir/objects/90/e7ea1089f939840e9649fd617584c1ad117159 +0 -3
- package/test-fixtures/testGitRepo/gitDir/objects/ba/99a452b9097047e9bfa8d5a08b3e452fcb364a +0 -0
- package/test-fixtures/testGitRepo/gitDir/objects/c5/8d400177cd5180b8566f82a127fafc5bf394b7 +0 -0
- package/test-fixtures/testGitRepo/gitDir/objects/e2/e668265db019249a7e8296d85f79000e3d71cf +0 -0
- package/test-fixtures/testGitRepo/gitDir/objects/e4/243e430c1ab69f3e344249f5b1859e90abc883 +0 -1
- package/test-fixtures/testGitRepo/gitDir/objects/ec/6c1cb72312605282ac61858cf1eaf1ea9f1d02 +0 -0
- package/test-fixtures/testGitRepo/gitDir/objects/fc/89cecc4ac0b5b075bd7d0ce9e09b2f50598b82 +0 -0
- package/test-fixtures/testGitRepo/gitDir/refs/heads/master +0 -1
- package/test-fixtures/testGitRepo/gitDir/refs/heads/test-branch +0 -1
- package/tsconfig.cjs.json +0 -12
- package/tsconfig.esm.json +0 -10
- package/tsconfig.json +0 -22
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.merge = exports.validate = void 0;
|
|
30
|
-
const lodash_merge_1 = __importDefault(require("lodash.merge"));
|
|
31
|
-
const jsonpath_1 = __importDefault(require("jsonpath"));
|
|
32
|
-
const infer_json_indent_1 = require("../formatting/infer-json-indent");
|
|
33
|
-
const commentJSON = __importStar(require("comment-json"));
|
|
34
|
-
function stringOptionError(value) {
|
|
35
|
-
if (value === "overwrite" ||
|
|
36
|
-
value === "merge-template" ||
|
|
37
|
-
value === "merge-current") {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
return `${value} must be one of type overwrite, merge-template, or merge-current`;
|
|
41
|
-
}
|
|
42
|
-
function validate(options) {
|
|
43
|
-
const errors = [];
|
|
44
|
-
// check for flat options
|
|
45
|
-
if (typeof options === "string") {
|
|
46
|
-
const errMsg = stringOptionError(options);
|
|
47
|
-
if (errMsg) {
|
|
48
|
-
errors.push(errMsg);
|
|
49
|
-
}
|
|
50
|
-
return errors;
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
if (typeof options !== "object") {
|
|
54
|
-
errors.push(`Options must be an object and not ${typeof options}`);
|
|
55
|
-
return errors;
|
|
56
|
-
}
|
|
57
|
-
if (Array.isArray(options)) {
|
|
58
|
-
errors.push(`Options must be an object and not Array`);
|
|
59
|
-
return errors;
|
|
60
|
-
}
|
|
61
|
-
if (options === null) {
|
|
62
|
-
errors.push("Options cannot be null");
|
|
63
|
-
return errors;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
const optionsCast = options;
|
|
67
|
-
const optionKeys = Object.keys(optionsCast);
|
|
68
|
-
optionKeys.forEach((k) => {
|
|
69
|
-
if (k === "paths") {
|
|
70
|
-
optionsCast.paths.forEach((pathObj) => {
|
|
71
|
-
const [jsonPath, options] = pathObj;
|
|
72
|
-
if (jsonPath.startsWith("$.")) {
|
|
73
|
-
try {
|
|
74
|
-
jsonpath_1.default.parse(jsonPath);
|
|
75
|
-
}
|
|
76
|
-
catch (err) {
|
|
77
|
-
errors.push(`Invalid jsonpath key: ${err}`);
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
const errMsg = stringOptionError(options);
|
|
81
|
-
if (errMsg) {
|
|
82
|
-
errors.push(`jsonpath ${jsonPath}: ${errMsg}`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
errors.push(`Unrecognized jsonpath syntax: ${jsonPath}`);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
if (k === "ignoreNewProperties" || k === "missingIsDelete") {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
errors.push(`Unrecognized key: ${k}`);
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
return errors;
|
|
98
|
-
}
|
|
99
|
-
exports.validate = validate;
|
|
100
|
-
async function merge(current, fromTemplateRepo, context) {
|
|
101
|
-
if (context.mergeArguments === "overwrite") {
|
|
102
|
-
return fromTemplateRepo;
|
|
103
|
-
}
|
|
104
|
-
const currentJson = commentJSON.parse(current);
|
|
105
|
-
const fromTemplateJson = commentJSON.parse(fromTemplateRepo);
|
|
106
|
-
if (context.mergeArguments === "merge-current") {
|
|
107
|
-
// Performs Lodash Merge with current as the override
|
|
108
|
-
return commentJSON.stringify((0, lodash_merge_1.default)(fromTemplateJson, currentJson), null, (0, infer_json_indent_1.inferJSONIndent)(current));
|
|
109
|
-
}
|
|
110
|
-
if (context.mergeArguments === "merge-template") {
|
|
111
|
-
// Performs Lodash Merge with current as the override
|
|
112
|
-
return commentJSON.stringify((0, lodash_merge_1.default)(currentJson, fromTemplateJson), null, (0, infer_json_indent_1.inferJSONIndent)(current));
|
|
113
|
-
}
|
|
114
|
-
const { missingIsDelete, ignoreNewProperties, paths } = context.mergeArguments;
|
|
115
|
-
const returnJson = commentJSON.parse(current);
|
|
116
|
-
paths.forEach((p) => {
|
|
117
|
-
const [jPath, overrideType] = p;
|
|
118
|
-
const fromTemplatePaths = new Map();
|
|
119
|
-
if (overrideType === "merge-template") {
|
|
120
|
-
// We want to make sure there aren't extra paths from the template that didn't get added
|
|
121
|
-
jsonpath_1.default.nodes(fromTemplateJson, jPath).forEach((n) => {
|
|
122
|
-
fromTemplatePaths.set(jsonpath_1.default.stringify(n.path), n.path);
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
jsonpath_1.default.nodes(currentJson, jPath).forEach(({ path, value }) => {
|
|
126
|
-
// This solves for wildcard operators
|
|
127
|
-
const fullPath = jsonpath_1.default.stringify(path);
|
|
128
|
-
// track the paths in the template we've walked
|
|
129
|
-
fromTemplatePaths.delete(fullPath);
|
|
130
|
-
jsonpath_1.default.apply(returnJson, fullPath, () => {
|
|
131
|
-
const templateValue = jsonpath_1.default.value(fromTemplateJson, fullPath);
|
|
132
|
-
if (overrideType === "merge-template") {
|
|
133
|
-
if (templateValue === undefined) {
|
|
134
|
-
if (missingIsDelete) {
|
|
135
|
-
return templateValue;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
return applyValueMerge(value, templateValue);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
else if (overrideType === "merge-current") {
|
|
143
|
-
return applyValueMerge(templateValue, value);
|
|
144
|
-
}
|
|
145
|
-
else if (overrideType === "overwrite") {
|
|
146
|
-
if (templateValue !== undefined || missingIsDelete) {
|
|
147
|
-
return templateValue;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
throw new Error(`Unexpected JsonPath merge value ${overrideType}`);
|
|
152
|
-
}
|
|
153
|
-
return value;
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
if (!ignoreNewProperties) {
|
|
157
|
-
for (const fromTemplatePath of fromTemplatePaths.values()) {
|
|
158
|
-
applyPerPath(fromTemplatePath, returnJson, fromTemplateJson);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
if (!ignoreNewProperties) {
|
|
163
|
-
Object.keys(fromTemplateJson).forEach((key) => {
|
|
164
|
-
if (!returnJson[key]) {
|
|
165
|
-
returnJson[key] = fromTemplateJson[key];
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
return commentJSON.stringify(returnJson, null, (0, infer_json_indent_1.inferJSONIndent)(current));
|
|
170
|
-
}
|
|
171
|
-
exports.merge = merge;
|
|
172
|
-
/**
|
|
173
|
-
* A merge from a template to template perspective is either melding objects
|
|
174
|
-
* or completely overwriting primitive types
|
|
175
|
-
*/
|
|
176
|
-
function applyValueMerge(base, toMerge) {
|
|
177
|
-
if (typeof base === "object" && typeof toMerge === "object") {
|
|
178
|
-
return (0, lodash_merge_1.default)(base, toMerge);
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
return toMerge;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Given a nodePath on the "map" tree, this will go to the first missing element
|
|
186
|
-
* and copy that node onto the object
|
|
187
|
-
*
|
|
188
|
-
* @param nodePath
|
|
189
|
-
* @param onto
|
|
190
|
-
* @param map
|
|
191
|
-
* @param forIdx
|
|
192
|
-
*/
|
|
193
|
-
function applyPerPath(nodePath,
|
|
194
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
195
|
-
onto,
|
|
196
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
197
|
-
map, forIdx = 0) {
|
|
198
|
-
if (nodePath[forIdx] === "$") {
|
|
199
|
-
applyPerPath(nodePath, onto, map, forIdx + 1);
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
const selector = nodePath[forIdx];
|
|
203
|
-
if (onto[selector]) {
|
|
204
|
-
applyPerPath(nodePath, onto[selector], map[selector], forIdx + 1);
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
onto[selector] = map[selector];
|
|
208
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.gitCurrentRef = void 0;
|
|
4
|
-
const child_process_1 = require("child_process");
|
|
5
|
-
async function gitCurrentRef(options) {
|
|
6
|
-
return (0, child_process_1.execSync)(`git rev-parse HEAD`, {
|
|
7
|
-
cwd: options.rootDir,
|
|
8
|
-
})
|
|
9
|
-
.toString()
|
|
10
|
-
.trim();
|
|
11
|
-
}
|
|
12
|
-
exports.gitCurrentRef = gitCurrentRef;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./git-current-ref"), exports);
|
package/lib/esm/template-sync.js
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.templateSync = exports.TEMPLATE_SYNC_LOCAL_CONFIG = exports.TEMPLATE_SYNC_CONFIG = void 0;
|
|
27
|
-
const path_1 = require("path");
|
|
28
|
-
const fs_1 = require("fs");
|
|
29
|
-
const match_1 = require("./match");
|
|
30
|
-
const merge_file_1 = require("./merge-file");
|
|
31
|
-
const git_clone_1 = require("./clone-drivers/git-clone");
|
|
32
|
-
const diff_drivers_1 = require("./diff-drivers");
|
|
33
|
-
const ref_drivers_1 = require("./ref-drivers");
|
|
34
|
-
const formatting_1 = require("./formatting");
|
|
35
|
-
const commentJSON = __importStar(require("comment-json"));
|
|
36
|
-
const checkout_drivers_1 = require("./checkout-drivers");
|
|
37
|
-
const micromatch_1 = require("micromatch");
|
|
38
|
-
const load_plugin_1 = require("./load-plugin");
|
|
39
|
-
exports.TEMPLATE_SYNC_CONFIG = "templatesync";
|
|
40
|
-
exports.TEMPLATE_SYNC_LOCAL_CONFIG = "templatesync.local";
|
|
41
|
-
async function templateSync(options) {
|
|
42
|
-
const cloneDriver = options.cloneDriver ?? git_clone_1.gitClone;
|
|
43
|
-
const diffDriver = options.diffDriver ?? diff_drivers_1.gitDiff;
|
|
44
|
-
const currentRefDriver = options.currentRefDriver ?? ref_drivers_1.gitCurrentRef;
|
|
45
|
-
const checkoutDriver = options.checkoutDriver ?? checkout_drivers_1.gitCheckout;
|
|
46
|
-
const cloneReturn = await cloneDriver(options.tmpCloneDir, options.repoUrl);
|
|
47
|
-
const { dir: tempCloneDir, remoteName } = typeof cloneReturn === "string"
|
|
48
|
-
? {
|
|
49
|
-
dir: cloneReturn,
|
|
50
|
-
remoteName: "origin", // Default to this
|
|
51
|
-
}
|
|
52
|
-
: cloneReturn;
|
|
53
|
-
if (options.branch) {
|
|
54
|
-
await checkoutDriver({
|
|
55
|
-
tmpDir: tempCloneDir,
|
|
56
|
-
remoteName,
|
|
57
|
-
branch: options.branch,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
// Get the clone Config
|
|
61
|
-
const cloneConfigPath = (0, path_1.join)(tempCloneDir, `${exports.TEMPLATE_SYNC_CONFIG}.json`);
|
|
62
|
-
const templateSyncConfig = (0, fs_1.existsSync)(cloneConfigPath)
|
|
63
|
-
? commentJSON.parse((0, fs_1.readFileSync)(cloneConfigPath).toString())
|
|
64
|
-
: { ignore: [] };
|
|
65
|
-
const localConfigFile = `${exports.TEMPLATE_SYNC_LOCAL_CONFIG}.json`;
|
|
66
|
-
const localConfigPath = (0, path_1.join)(options.repoDir, localConfigFile);
|
|
67
|
-
const localTemplateSyncConfig = (0, fs_1.existsSync)(localConfigPath)
|
|
68
|
-
? commentJSON.parse((0, fs_1.readFileSync)(localConfigPath).toString())
|
|
69
|
-
: { ignore: [] };
|
|
70
|
-
let filesToSync;
|
|
71
|
-
const ref = await currentRefDriver({
|
|
72
|
-
rootDir: tempCloneDir,
|
|
73
|
-
});
|
|
74
|
-
if (localTemplateSyncConfig.afterRef) {
|
|
75
|
-
if (ref === localTemplateSyncConfig.afterRef) {
|
|
76
|
-
// short circuit if the refs match
|
|
77
|
-
return {
|
|
78
|
-
localSkipFiles: [],
|
|
79
|
-
localFileChanges: {},
|
|
80
|
-
modifiedFiles: {
|
|
81
|
-
added: [],
|
|
82
|
-
modified: [],
|
|
83
|
-
deleted: [],
|
|
84
|
-
total: 0,
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
filesToSync = await diffDriver(tempCloneDir, localTemplateSyncConfig.afterRef);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
filesToSync = {
|
|
92
|
-
added: (0, match_1.getAllFilesInDir)(tempCloneDir, [
|
|
93
|
-
...templateSyncConfig.ignore,
|
|
94
|
-
".git/**",
|
|
95
|
-
]),
|
|
96
|
-
deleted: [],
|
|
97
|
-
modified: [],
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
// Pre-load plugins and make sure the sync file is respected
|
|
101
|
-
// Synchronous since grpc servers take a second
|
|
102
|
-
const localValidateErrors = {};
|
|
103
|
-
const validateErrors = {};
|
|
104
|
-
for (const config of localTemplateSyncConfig.merge ?? []) {
|
|
105
|
-
const plugin = await (0, load_plugin_1.loadPlugin)(config, options.repoDir);
|
|
106
|
-
const errors = plugin.validate(config.options ?? {});
|
|
107
|
-
if (errors && errors.length > 0) {
|
|
108
|
-
localValidateErrors[config.plugin] = errors;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
for (const config of templateSyncConfig.merge ?? []) {
|
|
112
|
-
const plugin = await (0, load_plugin_1.loadPlugin)(config, tempCloneDir);
|
|
113
|
-
const errors = plugin.validate(config.options ?? {});
|
|
114
|
-
if (errors && errors.length > 0) {
|
|
115
|
-
validateErrors[config.plugin] = errors;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
let errorStr = "";
|
|
119
|
-
if (Object.keys(validateErrors).length > 0) {
|
|
120
|
-
errorStr = `${errorStr}templatesync.json plugin option errors:\n`;
|
|
121
|
-
for (const plugin in validateErrors) {
|
|
122
|
-
errorStr = `${errorStr}\tPlugin (${plugin}):\n`;
|
|
123
|
-
validateErrors[plugin].forEach((err) => {
|
|
124
|
-
errorStr = `${errorStr}\t\t${err}\n`;
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (Object.keys(localValidateErrors).length > 0) {
|
|
129
|
-
errorStr = `${errorStr}templatesync.local.json plugin option errors:\n`;
|
|
130
|
-
for (const plugin in localValidateErrors) {
|
|
131
|
-
errorStr = `${errorStr}\tPlugin (${plugin}):\n`;
|
|
132
|
-
localValidateErrors[plugin].forEach((err) => {
|
|
133
|
-
errorStr = `${errorStr}\t\t${err}\n`;
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
if (errorStr !== "") {
|
|
138
|
-
throw Error(errorStr);
|
|
139
|
-
}
|
|
140
|
-
// Apply ignore filters
|
|
141
|
-
filesToSync.added = filesToSync.added.filter((f) => !(0, micromatch_1.some)(f, templateSyncConfig.ignore));
|
|
142
|
-
filesToSync.modified = filesToSync.modified.filter((f) => !(0, micromatch_1.some)(f, templateSyncConfig.ignore));
|
|
143
|
-
filesToSync.deleted = filesToSync.deleted.filter((f) => !(0, micromatch_1.some)(f, templateSyncConfig.ignore));
|
|
144
|
-
const localSkipFiles = new Set();
|
|
145
|
-
const localFileChanges = {};
|
|
146
|
-
const fileSyncFactory = (op) => {
|
|
147
|
-
return async (f) => {
|
|
148
|
-
const result = await (0, merge_file_1.mergeFile)(f, {
|
|
149
|
-
localTemplateSyncConfig,
|
|
150
|
-
templateSyncConfig,
|
|
151
|
-
tempCloneDir,
|
|
152
|
-
cwd: options.repoDir,
|
|
153
|
-
fileOperation: op,
|
|
154
|
-
});
|
|
155
|
-
if (result.ignoredDueToLocal) {
|
|
156
|
-
localSkipFiles.add(f);
|
|
157
|
-
}
|
|
158
|
-
else if (result?.localChanges && result.localChanges.length > 0) {
|
|
159
|
-
localFileChanges[f] = result.localChanges;
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
};
|
|
163
|
-
// Added and modified have the same setup for now
|
|
164
|
-
await Promise.all(filesToSync.added.map(fileSyncFactory("added")));
|
|
165
|
-
await Promise.all(filesToSync.modified.map(fileSyncFactory("modified")));
|
|
166
|
-
await Promise.all(filesToSync.deleted.map(fileSyncFactory("deleted")));
|
|
167
|
-
// Report the files that changed in general
|
|
168
|
-
const actualAdded = filesToSync.added.filter((f) => !localSkipFiles.has(f));
|
|
169
|
-
const actualModified = filesToSync.modified.filter((f) => !localSkipFiles.has(f));
|
|
170
|
-
const actualDeleted = filesToSync.deleted.filter((f) => !localSkipFiles.has(f));
|
|
171
|
-
const modifiedFiles = {
|
|
172
|
-
added: actualAdded,
|
|
173
|
-
modified: actualModified,
|
|
174
|
-
deleted: actualDeleted,
|
|
175
|
-
};
|
|
176
|
-
// apply after ref
|
|
177
|
-
if (options.updateAfterRef) {
|
|
178
|
-
const ref = await currentRefDriver({
|
|
179
|
-
rootDir: tempCloneDir,
|
|
180
|
-
});
|
|
181
|
-
if ((0, fs_1.existsSync)(localConfigPath)) {
|
|
182
|
-
const configStr = (0, fs_1.readFileSync)(localConfigPath).toString();
|
|
183
|
-
const config = commentJSON.parse(configStr);
|
|
184
|
-
config.afterRef = ref;
|
|
185
|
-
(0, fs_1.writeFileSync)(localConfigPath, commentJSON.stringify(config, null, (0, formatting_1.inferJSONIndent)(configStr)));
|
|
186
|
-
modifiedFiles.modified.push(localConfigFile);
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
(0, fs_1.writeFileSync)(localConfigPath, commentJSON.stringify({ afterRef: ref }, null, 4));
|
|
190
|
-
modifiedFiles.added.push(localConfigFile);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return {
|
|
194
|
-
localSkipFiles: Array.from(localSkipFiles),
|
|
195
|
-
localFileChanges,
|
|
196
|
-
modifiedFiles: {
|
|
197
|
-
...modifiedFiles,
|
|
198
|
-
total: modifiedFiles.added.length +
|
|
199
|
-
modifiedFiles.deleted.length +
|
|
200
|
-
modifiedFiles.modified.length,
|
|
201
|
-
},
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
exports.templateSync = templateSync;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tempDir = exports.TEST_FIXTURES_DIR = void 0;
|
|
4
|
-
const path_1 = require("path");
|
|
5
|
-
const os_1 = require("os");
|
|
6
|
-
exports.TEST_FIXTURES_DIR = (0, path_1.resolve)(__dirname, "..", "..", "test-fixtures");
|
|
7
|
-
function tempDir() {
|
|
8
|
-
return process.env.RUNNER_TEMP ?? (0, os_1.tmpdir)();
|
|
9
|
-
}
|
|
10
|
-
exports.tempDir = tempDir;
|
package/lib/esm/types.js
DELETED
package/release.config.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
-
const { readFileSync } = require("fs");
|
|
3
|
-
const { join } = require("path");
|
|
4
|
-
|
|
5
|
-
const packageJson = JSON.parse(
|
|
6
|
-
readFileSync(join(__dirname, "package.json")).toString(),
|
|
7
|
-
);
|
|
8
|
-
|
|
9
|
-
// Abbreviate for Git Commit readability
|
|
10
|
-
const fullName = packageJson.name;
|
|
11
|
-
const scopeLimiterIdx = fullName.lastIndexOf("/");
|
|
12
|
-
const abbreviatedName = fullName.substring(
|
|
13
|
-
scopeLimiterIdx >= 0 ? scopeLimiterIdx + 1 : 0,
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
module.exports = {
|
|
17
|
-
branches: ["main", { name: "alpha", prerelease: true }],
|
|
18
|
-
plugins: [
|
|
19
|
-
"@semantic-release/commit-analyzer",
|
|
20
|
-
"@semantic-release/release-notes-generator",
|
|
21
|
-
"@semantic-release/changelog",
|
|
22
|
-
[
|
|
23
|
-
"@semantic-release/npm",
|
|
24
|
-
{
|
|
25
|
-
npmPublish: false, // We just use this to increment the versions since semantic-release doesn't handle OIDC well
|
|
26
|
-
// Call the publish comand in the CI/CD
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
[
|
|
30
|
-
"@semantic-release/git",
|
|
31
|
-
{
|
|
32
|
-
assets: ["CHANGELOG.md", "package.json"],
|
|
33
|
-
message: `docs(release): ${abbreviatedName} $\{nextRelease.version} [skip ci]\n\n$\{nextRelease.notes}`,
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
// This creates a release on github - you can decide if you want to mirror the files in package.json
|
|
37
|
-
"@semantic-release/github",
|
|
38
|
-
],
|
|
39
|
-
ci: true,
|
|
40
|
-
};
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { join, resolve } from "path";
|
|
2
|
-
import { TEST_FIXTURES_DIR, tempDir } from "../test-utils";
|
|
3
|
-
import { copy, mkdtemp, moveSync } from "fs-extra";
|
|
4
|
-
import { execSync } from "child_process";
|
|
5
|
-
import { gitCheckout } from "./git-checkout";
|
|
6
|
-
import { readFileSync } from "fs";
|
|
7
|
-
|
|
8
|
-
const gitRemoteDir = resolve(TEST_FIXTURES_DIR, "testGitRepo");
|
|
9
|
-
|
|
10
|
-
describe("gitCheckout", () => {
|
|
11
|
-
let tmpRemoteDir: string;
|
|
12
|
-
let tmpRepoDir: string;
|
|
13
|
-
beforeEach(async () => {
|
|
14
|
-
const baseTmpDir = await mkdtemp(tempDir());
|
|
15
|
-
// Make the remote dir
|
|
16
|
-
tmpRemoteDir = join(baseTmpDir, "remote");
|
|
17
|
-
await copy(gitRemoteDir, tmpRemoteDir);
|
|
18
|
-
// rehydrate the git repo
|
|
19
|
-
moveSync(join(tmpRemoteDir, "gitDir"), join(tmpRemoteDir, ".git"));
|
|
20
|
-
|
|
21
|
-
// Perform the clone we expect
|
|
22
|
-
execSync(`git clone ${tmpRemoteDir} testGitRepo`, {
|
|
23
|
-
cwd: baseTmpDir,
|
|
24
|
-
});
|
|
25
|
-
tmpRepoDir = join(baseTmpDir, "testGitRepo");
|
|
26
|
-
});
|
|
27
|
-
it("checks out the appropriate branch", async () => {
|
|
28
|
-
await gitCheckout({
|
|
29
|
-
tmpDir: tmpRepoDir,
|
|
30
|
-
remoteName: "origin",
|
|
31
|
-
branch: "test-branch", // We set this in the gitDir
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
expect(readFileSync(join(tmpRepoDir, "README.md")).toString()).toContain(
|
|
35
|
-
"# This is the test-branch",
|
|
36
|
-
);
|
|
37
|
-
});
|
|
38
|
-
it("throws an error if the branch is not found", async () => {
|
|
39
|
-
await expect(
|
|
40
|
-
async () =>
|
|
41
|
-
await gitCheckout({
|
|
42
|
-
tmpDir: tmpRepoDir,
|
|
43
|
-
remoteName: "origin",
|
|
44
|
-
branch: "test-branch-not-there", // This is not set in gitDir
|
|
45
|
-
}),
|
|
46
|
-
).rejects.toThrow();
|
|
47
|
-
});
|
|
48
|
-
it("throws an error if the origin is not found", async () => {
|
|
49
|
-
await expect(
|
|
50
|
-
async () =>
|
|
51
|
-
await gitCheckout({
|
|
52
|
-
tmpDir: tmpRepoDir,
|
|
53
|
-
remoteName: "originNA",
|
|
54
|
-
branch: "test-branch", // This is not set in gitDir
|
|
55
|
-
}),
|
|
56
|
-
).rejects.toThrow();
|
|
57
|
-
});
|
|
58
|
-
it("does not throw if the branch was the default", async () => {
|
|
59
|
-
await gitCheckout({
|
|
60
|
-
tmpDir: tmpRepoDir,
|
|
61
|
-
remoteName: "origin",
|
|
62
|
-
branch: "master", // We set this in the gitDir
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
expect(readFileSync(join(tmpRepoDir, "README.md")).toString()).toContain(
|
|
66
|
-
"# This is the master branch",
|
|
67
|
-
);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { execSync } from "child_process";
|
|
2
|
-
|
|
3
|
-
export async function gitCheckout(options: {
|
|
4
|
-
/** The directory where we cloned to */
|
|
5
|
-
tmpDir: string;
|
|
6
|
-
/** The name of the remote that git checks out against */
|
|
7
|
-
remoteName: string;
|
|
8
|
-
/** The branch to checkout against */
|
|
9
|
-
branch: string;
|
|
10
|
-
}): Promise<boolean> {
|
|
11
|
-
const { branch, remoteName, tmpDir } = options;
|
|
12
|
-
|
|
13
|
-
const remoteInfo = execSync(`git remote show ${remoteName}`, {
|
|
14
|
-
cwd: tmpDir,
|
|
15
|
-
env: process.env,
|
|
16
|
-
}).toString();
|
|
17
|
-
const defaultMatch = /HEAD branch:\s*([a-zA-Z0-9_-]+)/.exec(remoteInfo);
|
|
18
|
-
if (!defaultMatch || !defaultMatch[1]) {
|
|
19
|
-
throw new Error(
|
|
20
|
-
`Could not determine default branch of cloned repo.\nAttempted to find in remote info:\n${remoteInfo} `,
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const defaultBranch = defaultMatch[1];
|
|
25
|
-
// Skip this if the default branch is already pulled
|
|
26
|
-
if (defaultBranch !== branch) {
|
|
27
|
-
execSync(`git fetch ${remoteName} ${branch}`, {
|
|
28
|
-
cwd: tmpDir,
|
|
29
|
-
env: process.env,
|
|
30
|
-
});
|
|
31
|
-
execSync(`git checkout -b ${branch} --track ${remoteName}/${branch}`, {
|
|
32
|
-
cwd: tmpDir,
|
|
33
|
-
env: process.env,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A function that will checkout a given "branch" after the repo has been
|
|
3
|
-
* "cloned" by a clone drvier.
|
|
4
|
-
*
|
|
5
|
-
* @returns true if the checkout succeeded
|
|
6
|
-
*/
|
|
7
|
-
export type TemplateCheckoutDriverFn = (options: {
|
|
8
|
-
/** The directory where we cloned to */
|
|
9
|
-
tmpDir: string;
|
|
10
|
-
/** The name of the remote that git checks out against */
|
|
11
|
-
remoteName: string;
|
|
12
|
-
/** The branch to checkout against */
|
|
13
|
-
branch: string;
|
|
14
|
-
}) => Promise<boolean>;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { execSync } from "child_process";
|
|
2
|
-
import { resolve } from "path";
|
|
3
|
-
import { CloneReturn } from "./types";
|
|
4
|
-
|
|
5
|
-
const CLONE_DIR = "cloned_repo";
|
|
6
|
-
|
|
7
|
-
export async function gitClone(
|
|
8
|
-
tmpDir: string,
|
|
9
|
-
repoUrl: string,
|
|
10
|
-
): Promise<CloneReturn> {
|
|
11
|
-
execSync(`git clone ${repoUrl} ${CLONE_DIR}`, {
|
|
12
|
-
cwd: tmpDir,
|
|
13
|
-
env: process.env,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
return {
|
|
17
|
-
dir: resolve(tmpDir, CLONE_DIR),
|
|
18
|
-
remoteName: "origin",
|
|
19
|
-
};
|
|
20
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @deprecated - return the remote name in the CloneReturn
|
|
3
|
-
*/
|
|
4
|
-
type CloneDir = string;
|
|
5
|
-
|
|
6
|
-
export interface CloneReturn {
|
|
7
|
-
/** The directory where the clone occurred - absolute path to avoid working dir issues */
|
|
8
|
-
dir: string;
|
|
9
|
-
/** The name of the remote for the particular technology that you used - passed to checkout drivers */
|
|
10
|
-
remoteName: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* A function that clones the template repo into the provided tmpDir
|
|
15
|
-
* and then returns the relative path within that directory to the template root
|
|
16
|
-
*/
|
|
17
|
-
export type TemplateCloneDriverFn = (
|
|
18
|
-
tmpDir: string,
|
|
19
|
-
repoUrl: string,
|
|
20
|
-
) => Promise<CloneReturn | CloneDir>;
|