@hanseltime/template-repo-sync 1.0.1

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.
Files changed (119) hide show
  1. package/.eslintrc.js +10 -0
  2. package/.github/CODEOWNERS +6 -0
  3. package/.github/workflows/pr-checks.yaml +12 -0
  4. package/.github/workflows/release.yaml +36 -0
  5. package/.github/workflows/test-flow.yaml +58 -0
  6. package/.husky/commit-msg +4 -0
  7. package/.prettierignore +1 -0
  8. package/.prettierrc +1 -0
  9. package/CHANGELOG.md +27 -0
  10. package/README.md +93 -0
  11. package/action.yml +13 -0
  12. package/commitlint.config.js +3 -0
  13. package/jest.config.js +19 -0
  14. package/lib/cjs/clone-drivers/git-clone.d.ts +1 -0
  15. package/lib/cjs/clone-drivers/git-clone.js +14 -0
  16. package/lib/cjs/clone-drivers/index.d.ts +2 -0
  17. package/lib/cjs/clone-drivers/index.js +18 -0
  18. package/lib/cjs/clone-drivers/types.d.ts +5 -0
  19. package/lib/cjs/clone-drivers/types.js +2 -0
  20. package/lib/cjs/diff-drivers/git-diff.d.ts +1 -0
  21. package/lib/cjs/diff-drivers/git-diff.js +13 -0
  22. package/lib/cjs/diff-drivers/index.d.ts +2 -0
  23. package/lib/cjs/diff-drivers/index.js +18 -0
  24. package/lib/cjs/diff-drivers/types.d.ts +5 -0
  25. package/lib/cjs/diff-drivers/types.js +2 -0
  26. package/lib/cjs/formatting/index.d.ts +2 -0
  27. package/lib/cjs/formatting/index.js +18 -0
  28. package/lib/cjs/formatting/infer-json-indent.d.ts +1 -0
  29. package/lib/cjs/formatting/infer-json-indent.js +18 -0
  30. package/lib/cjs/formatting/sync-results-to-md.d.ts +2 -0
  31. package/lib/cjs/formatting/sync-results-to-md.js +40 -0
  32. package/lib/cjs/index.d.ts +3 -0
  33. package/lib/cjs/index.js +19 -0
  34. package/lib/cjs/load-plugin.d.ts +2 -0
  35. package/lib/cjs/load-plugin.js +63 -0
  36. package/lib/cjs/match.d.ts +10 -0
  37. package/lib/cjs/match.js +45 -0
  38. package/lib/cjs/merge-file.d.ts +29 -0
  39. package/lib/cjs/merge-file.js +99 -0
  40. package/lib/cjs/plugins/index.d.ts +4 -0
  41. package/lib/cjs/plugins/index.js +10 -0
  42. package/lib/cjs/plugins/json-merge.d.ts +3 -0
  43. package/lib/cjs/plugins/json-merge.js +185 -0
  44. package/lib/cjs/template-sync.d.ts +40 -0
  45. package/lib/cjs/template-sync.js +56 -0
  46. package/lib/cjs/test-utils/index.d.ts +2 -0
  47. package/lib/cjs/test-utils/index.js +10 -0
  48. package/lib/cjs/types.d.ts +113 -0
  49. package/lib/cjs/types.js +2 -0
  50. package/lib/esm/clone-drivers/git-clone.js +14 -0
  51. package/lib/esm/clone-drivers/index.js +18 -0
  52. package/lib/esm/clone-drivers/types.js +2 -0
  53. package/lib/esm/diff-drivers/git-diff.js +13 -0
  54. package/lib/esm/diff-drivers/index.js +18 -0
  55. package/lib/esm/diff-drivers/types.js +2 -0
  56. package/lib/esm/formatting/index.js +18 -0
  57. package/lib/esm/formatting/infer-json-indent.js +18 -0
  58. package/lib/esm/formatting/sync-results-to-md.js +40 -0
  59. package/lib/esm/index.js +19 -0
  60. package/lib/esm/load-plugin.js +40 -0
  61. package/lib/esm/match.js +45 -0
  62. package/lib/esm/merge-file.js +99 -0
  63. package/lib/esm/plugins/index.js +10 -0
  64. package/lib/esm/plugins/json-merge.js +185 -0
  65. package/lib/esm/template-sync.js +56 -0
  66. package/lib/esm/test-utils/index.js +10 -0
  67. package/lib/esm/types.js +2 -0
  68. package/package.json +60 -0
  69. package/release.config.js +34 -0
  70. package/src/clone-drivers/git-clone.ts +16 -0
  71. package/src/clone-drivers/index.ts +2 -0
  72. package/src/clone-drivers/types.ts +8 -0
  73. package/src/diff-drivers/git-diff.ts +10 -0
  74. package/src/diff-drivers/index.ts +2 -0
  75. package/src/diff-drivers/types.ts +8 -0
  76. package/src/formatting/__snapshots__/sync-results-to-md.spec.ts.snap +22 -0
  77. package/src/formatting/index.ts +2 -0
  78. package/src/formatting/infer-json-indent.spec.ts +49 -0
  79. package/src/formatting/infer-json-indent.ts +16 -0
  80. package/src/formatting/sync-results-to-md.spec.ts +25 -0
  81. package/src/formatting/sync-results-to-md.ts +46 -0
  82. package/src/index.ts +3 -0
  83. package/src/load-plugin.ts +42 -0
  84. package/src/match.spec.ts +68 -0
  85. package/src/match.ts +52 -0
  86. package/src/merge-file.spec.ts +432 -0
  87. package/src/merge-file.ts +150 -0
  88. package/src/plugins/index.ts +11 -0
  89. package/src/plugins/json-merge.spec.ts +350 -0
  90. package/src/plugins/json-merge.ts +205 -0
  91. package/src/template-sync.spec.ts +216 -0
  92. package/src/template-sync.ts +113 -0
  93. package/src/test-utils/index.ts +13 -0
  94. package/src/types.ts +124 -0
  95. package/templatesync.local.json +15 -0
  96. package/test-fixtures/downstream/README.md +3 -0
  97. package/test-fixtures/downstream/package.json +18 -0
  98. package/test-fixtures/downstream/plugins/custom-plugin.js +11 -0
  99. package/test-fixtures/downstream/src/index.js +2 -0
  100. package/test-fixtures/downstream/src/index.ts +1 -0
  101. package/test-fixtures/downstream/src/templated.js +2 -0
  102. package/test-fixtures/downstream/src/templated.ts +1 -0
  103. package/test-fixtures/downstream/templatesync.json +19 -0
  104. package/test-fixtures/downstream/templatesync.local.json +14 -0
  105. package/test-fixtures/dummy-plugin.js +8 -0
  106. package/test-fixtures/glob-test/folder1/something.js +1 -0
  107. package/test-fixtures/glob-test/folder1/something.ts +0 -0
  108. package/test-fixtures/glob-test/toplevel.js +0 -0
  109. package/test-fixtures/glob-test/toplevel.txt +0 -0
  110. package/test-fixtures/template/custom-bin/something.txt +1 -0
  111. package/test-fixtures/template/package.json +17 -0
  112. package/test-fixtures/template/src/index.js +2 -0
  113. package/test-fixtures/template/src/index.ts +1 -0
  114. package/test-fixtures/template/src/templated.js +2 -0
  115. package/test-fixtures/template/src/templated.ts +1 -0
  116. package/test-fixtures/template/templatesync.json +19 -0
  117. package/tsconfig.cjs.json +12 -0
  118. package/tsconfig.esm.json +10 -0
  119. package/tsconfig.json +22 -0
package/.eslintrc.js ADDED
@@ -0,0 +1,10 @@
1
+ module.exports = {
2
+ env: {
3
+ node: true,
4
+ },
5
+ ignorePatterns: ["lib/**/*"],
6
+ extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
7
+ parser: "@typescript-eslint/parser",
8
+ plugins: ["@typescript-eslint"],
9
+ root: true,
10
+ };
@@ -0,0 +1,6 @@
1
+ # This is a comment.
2
+ # Each line is a file pattern followed by one or more owners.
3
+
4
+ # These owners will be the default owners for everything in
5
+ # the repo, Unless a later match takes precedence.
6
+ * @hanseltime
@@ -0,0 +1,12 @@
1
+ name: PR Checks
2
+ run-name: ${{ github.head_ref }} PR Checks
3
+
4
+ on:
5
+ pull_request:
6
+ branches: [main, alpha]
7
+
8
+ jobs:
9
+ call-test-workflow:
10
+ uses: ./.github/workflows/test-flow.yaml
11
+ with:
12
+ from: ${{ github.workflow }}
@@ -0,0 +1,36 @@
1
+ name: Release
2
+ run-name: ${{ github.ref_name }} Release
3
+
4
+ on:
5
+ push:
6
+ branches:
7
+ - main
8
+ - alpha
9
+
10
+ jobs:
11
+ call-test-workflow:
12
+ uses: ./.github/workflows/test-flow.yaml
13
+ with:
14
+ from: ${{ github.workflow }}
15
+ release:
16
+ runs-on: ubuntu-latest
17
+ needs: call-test-workflow
18
+ steps:
19
+ - uses: actions/checkout@v3
20
+ with:
21
+ token: ${{ secrets.RELEASE_PAT }}
22
+ - name: Use Node.js 20.x
23
+ uses: actions/setup-node@v4
24
+ with:
25
+ node-version: 20.x
26
+ cache: "npm"
27
+ cache-dependency-path: package-lock.json
28
+ - name: Install
29
+ run: npm ci
30
+ - name: Build
31
+ run: npm run build
32
+ - name: Release
33
+ run: npm run release
34
+ env:
35
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
36
+ GITHUB_TOKEN: ${{ secrets.RELEASE_PAT }}
@@ -0,0 +1,58 @@
1
+ name: Tests
2
+ on:
3
+ workflow_call:
4
+ inputs:
5
+ from:
6
+ required: true
7
+ type: string
8
+
9
+ # This will cancel in progress jobs if another job with the same ref gets started.
10
+ # Github run_id is a backup in case github.ref doesn't exist for some reason
11
+ concurrency:
12
+ group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
13
+ cancel-in-progress: true
14
+
15
+ jobs:
16
+ ci-checks:
17
+ runs-on: ubuntu-latest
18
+
19
+ strategy:
20
+ matrix:
21
+ node-version: [18.x, 20.x]
22
+
23
+ steps:
24
+ - uses: actions/checkout@v3
25
+ # TODO: caching this action would accelerate the run
26
+ - name: corepack
27
+ run: |
28
+ corepack enable
29
+ - uses: actions/setup-node@v4
30
+ with:
31
+ node-version: ${{ matrix.node-version }}
32
+ cache: "npm"
33
+ cache-dependency-path: package-lock.json
34
+ - name: install
35
+ run: |
36
+ npm ci
37
+ - name: commit-linting
38
+ run: |
39
+ if [[ "${{ github.base_ref }}" != "" ]]; then
40
+ echo "Setting up git environment for commitlint of pull request"
41
+ git fetch origin ${{ github.base_ref }}
42
+ git fetch origin ${{ github.head_ref }}
43
+ npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose
44
+ else
45
+ echo "Setting up git environment for commitlint of branch push"
46
+ git fetch origin ${{ github.ref_name }} --unshallow
47
+ npx commitlint --from $(git rev-list --max-parents=0 origin/${{ github.ref_name }})
48
+ fi
49
+ - name: build
50
+ run: |
51
+ npm run build
52
+ - name: linting
53
+ run: |
54
+ npm run lint
55
+ npx prettier . --check
56
+ - name: testing
57
+ run: |
58
+ npm run test
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env sh
2
+ . "$(dirname -- "$0")/_/husky.sh"
3
+
4
+ npx commitlint --edit $1
@@ -0,0 +1 @@
1
+ CHANGELOG.md
package/.prettierrc ADDED
@@ -0,0 +1 @@
1
+ {}
package/CHANGELOG.md ADDED
@@ -0,0 +1,27 @@
1
+ ## [1.0.1](https://github.com/HanseltimeIndustries/template-repo-sync/compare/v1.0.0...v1.0.1) (2024-03-03)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * adding despcription ([4ef4e57](https://github.com/HanseltimeIndustries/template-repo-sync/commit/4ef4e57ef824e19d363839482d6664b61b670804))
7
+
8
+ # 1.0.0 (2024-03-03)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * adding json spacing inference for writes ([fb28695](https://github.com/HanseltimeIndustries/template-repo-sync/commit/fb2869585b23adbaeb4d50a9eeaf9345b4130b20))
14
+ * creating directory if missing ([ff53e90](https://github.com/HanseltimeIndustries/template-repo-sync/commit/ff53e90c5b03e46082dff7a1c910a52b379fd569))
15
+ * do not merge .git ([a18799e](https://github.com/HanseltimeIndustries/template-repo-sync/commit/a18799e90ef95352d171018605f97d1abbb2fccc))
16
+ * pushing upstream ([c127b15](https://github.com/HanseltimeIndustries/template-repo-sync/commit/c127b15012d19ba821df61020acb3c784334f000))
17
+ * removing gha concern for separate package ([963bdf8](https://github.com/HanseltimeIndustries/template-repo-sync/commit/963bdf88659386aab99dc95258f1e7ca84fc098b))
18
+ * slight adjustment to formatting ([bea1519](https://github.com/HanseltimeIndustries/template-repo-sync/commit/bea151916dcc519da91ad75db9cc5d56a6897f5d))
19
+ * updating how template sync returns ([0ef0f73](https://github.com/HanseltimeIndustries/template-repo-sync/commit/0ef0f7331bc45d72001244560579671600fc4195))
20
+ * updating valdiation for linting ([b3f39e5](https://github.com/HanseltimeIndustries/template-repo-sync/commit/b3f39e595e6866e284a99d9a1259e96d4f45730a))
21
+
22
+
23
+ ### Features
24
+
25
+ * adding afterRef support ([66f16e7](https://github.com/HanseltimeIndustries/template-repo-sync/commit/66f16e7057a5129d9255b684a08fdda31211209a))
26
+ * initializing jsonpath support in two different repos ([a1438a2](https://github.com/HanseltimeIndustries/template-repo-sync/commit/a1438a22a5bd39ad70dde600ab2b9ba8a7e99972))
27
+ * setting up the github action flow ([5ef6772](https://github.com/HanseltimeIndustries/template-repo-sync/commit/5ef67728f29e8f266f81cdf84c6d75d2aa9441d0))
package/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # Template Sync Action
2
+
3
+ This npm package seeks to provide further granularity for people hoping to maintain a base template repo in github that
4
+ is either imported or used as a literal template repo.
5
+
6
+ In both of those cases, the downstream repos that have based themselves off of this template can quickly become out of sync for 2 reasons:
7
+
8
+ 1. The template repo is actively being developed with new standards
9
+ 2. The downstream repo has changes to support their use cases
10
+
11
+ If we were to consider that the template and its downstream repos are part of say, an organization's attempt at standardizing their
12
+ best practice development patterns, then we naturally want to have a way to allow each downstream implementer to adopt the newest
13
+ changes, while also having control over things that may be specifically changed due to their need to support something beyond the
14
+ orgnaization standard.
15
+
16
+ # How to use this
17
+
18
+ This repository publishes a github action that can be used for ease of use in github. It also provides itself as an npm package
19
+ for those who would like to implement the same calls in another CI/CD structure.
20
+
21
+ ## Config file
22
+
23
+ There are two types of config files that you can create:
24
+
25
+ - `templatesync.config` in the template repo (this is for the template maintainer to specify how they would expect a roll out
26
+ to update and for them to exclude anything that is more of an example than a standard (for instance, a hellow world placeholder))
27
+
28
+ - `templatesync.local.config` in the repo that cloned the template. This is meant for the repo maintainers to have the ability to avoid
29
+ or customize updates between the template repo in the event that they have deviated purposefully from it.
30
+
31
+ This library will always respect the overrides of the local template sync file if it exists but, as a compromise to rapidly developing
32
+ templates and their repos, will also provide a list of all files whose template sync behavior was either ignored or overridden by the local
33
+ file. In this way, teams should be able to track (with a little extra CI/CD wiring) or at the very least, explicitly acknowledge a deviation.
34
+
35
+ ### File format
36
+
37
+ ```typescript
38
+ export interface Config {
39
+ /**
40
+ * A set of micromatch globs that we are supposed to ignore
41
+ */
42
+ ignore: string[];
43
+ /**
44
+ * If there is no merge config, then we will always just overwrite the file for the diff
45
+ */
46
+ merge: {
47
+ /**
48
+ * .json file merge overrides. Keep in mind,
49
+ */
50
+ ".json": {
51
+ // You can add a merge plugin for extensions that we don't natively support
52
+ mergePlugin: string;
53
+ /**
54
+ * A list of file globs for json files that can have custom rules applied
55
+ *
56
+ * The first matching glob will be applied so make sure to put your defaults last
57
+ */
58
+ [fileGlobs: string]: JsonFileMerge;
59
+ }[];
60
+ };
61
+ }
62
+ ```
63
+
64
+ ### Example 1
65
+
66
+ ```typescript
67
+ {
68
+
69
+ merge: {
70
+ ".ini": {
71
+ // If you are running under pacakge manager like yarn or npm,
72
+ // you can provide a valid pacakge or .js fil from your package to run
73
+ driver: 'my-installed-npm-package',
74
+ }
75
+ }
76
+ }
77
+ ```
78
+
79
+ ## From SHA/Tag directive
80
+
81
+ One of the biggest pains of syncing templates is that you can end up seeing a change multiple times because your change has
82
+ purposefully desynchronized from the template. For instance, let's say that you need to support a newer framework than
83
+ the template you cloned from. You have added a PR to the template to upgrade, but the template maintainers are worried about
84
+ the effect of the change on all other template-based repos and are waiting. In the meantime, you still want to get any new
85
+ security patterns or boilerplate patterns for other tools.
86
+
87
+ To solve this, rudimentarily, we allow the local template sync config to provide a `afterRef` option. When provided, template sync
88
+ will only apply changes that have occurred after the ref (tag or sha) in question in the git based repo. This does not mean
89
+ that you will never see changes to the files from the last sync (because if someone changed something in that same file, all of its changes will be copied over),
90
+ but it does mean that you will only see the changes to files that are newer than the last time you looked at it.
91
+
92
+ As always, you can remove the SHA/Tag from your local config and this will trigger a full sync in the event that you made the wrong
93
+ assumption about merging templates correctly.
package/action.yml ADDED
@@ -0,0 +1,13 @@
1
+ name: "Template Repo Sync Action"
2
+ description: "Action for taking the files in a template repo and synchronizing them to the repo via a PR"
3
+ inputs:
4
+ who-to-greet: # id of input
5
+ description: "Who to greet"
6
+ required: true
7
+ default: "World"
8
+ outputs:
9
+ time: # id of output
10
+ description: "The time we greeted you"
11
+ runs:
12
+ using: "node20"
13
+ main: "index.js"
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ extends: ["@commitlint/config-angular"],
3
+ };
package/jest.config.js ADDED
@@ -0,0 +1,19 @@
1
+ module.exports = {
2
+ preset: "ts-jest",
3
+ testEnvironment: "node",
4
+ roots: ["<rootDir>/src"],
5
+ transform: {
6
+ "\\.tsx?$": "ts-jest",
7
+ "\\.jsx?$": "babel-jest",
8
+ },
9
+ collectCoverage: true,
10
+ collectCoverageFrom: ["./src/**"],
11
+ coverageThreshold: {
12
+ global: {
13
+ branches: 80,
14
+ functions: 80,
15
+ // Lines can get skewed by bucket files
16
+ statements: 80,
17
+ },
18
+ },
19
+ };
@@ -0,0 +1 @@
1
+ export declare function gitClone(tmpDir: string, repoUrl: string): Promise<string>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gitClone = void 0;
4
+ const child_process_1 = require("child_process");
5
+ const path_1 = require("path");
6
+ const CLONE_DIR = "cloned_repo";
7
+ async function gitClone(tmpDir, repoUrl) {
8
+ (0, child_process_1.execSync)(`git clone ${repoUrl} ${CLONE_DIR}`, {
9
+ cwd: tmpDir,
10
+ env: process.env,
11
+ });
12
+ return (0, path_1.resolve)(tmpDir, CLONE_DIR);
13
+ }
14
+ exports.gitClone = gitClone;
@@ -0,0 +1,2 @@
1
+ export * from "./types";
2
+ export * from "./git-clone";
@@ -0,0 +1,18 @@
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("./types"), exports);
18
+ __exportStar(require("./git-clone"), exports);
@@ -0,0 +1,5 @@
1
+ /**
2
+ * A function that clones the template repo into the provided tmpDir
3
+ * and then returns the relative path within that directory to the template root
4
+ */
5
+ export type TemplateCloneDriverFn = (tmpDir: string, repoUrl: string) => Promise<string>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export declare function gitDiff(gitDir: string, afterRef: string): Promise<string[]>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gitDiff = void 0;
4
+ const child_process_1 = require("child_process");
5
+ async function gitDiff(gitDir, afterRef) {
6
+ const diffFilesStr = (0, child_process_1.execSync)(`git diff ${afterRef}.. --name-only`, {
7
+ cwd: gitDir,
8
+ })
9
+ .toString()
10
+ .trim();
11
+ return diffFilesStr.split("\n");
12
+ }
13
+ exports.gitDiff = gitDiff;
@@ -0,0 +1,2 @@
1
+ export * from "./types";
2
+ export * from "./git-diff";
@@ -0,0 +1,18 @@
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("./types"), exports);
18
+ __exportStar(require("./git-diff"), exports);
@@ -0,0 +1,5 @@
1
+ /**
2
+ * A function that operates within the gitDir, and returns the list of file paths
3
+ * since the last sha
4
+ */
5
+ export type TemplateDiffDriverFn = (gitDir: string, afterRef: string) => Promise<string[]>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export * from "./sync-results-to-md";
2
+ export * from "./infer-json-indent";
@@ -0,0 +1,18 @@
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("./sync-results-to-md"), exports);
18
+ __exportStar(require("./infer-json-indent"), exports);
@@ -0,0 +1 @@
1
+ export declare function inferJSONIndent(rawJSON: string): string;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.inferJSONIndent = void 0;
4
+ const spacingRegex = /[{[]\n?(?<spacing>\s+)["tf\d]/;
5
+ function inferJSONIndent(rawJSON) {
6
+ const match = spacingRegex.exec(rawJSON);
7
+ if (!match?.groups?.spacing) {
8
+ // eslint-disable-next-line no-console
9
+ console.warn(`Could not find json indentation for json string: ${rawJSON.slice(40)} ... \nDefaulting to 4 spaces`);
10
+ // Four spaces
11
+ return " ";
12
+ }
13
+ const spacing = match.groups.spacing;
14
+ // Handle the case where there were multiple newlines before a value
15
+ const lastNewLine = spacing.lastIndexOf("\n");
16
+ return match?.groups.spacing.slice(lastNewLine >= 0 ? lastNewLine + 1 : 0);
17
+ }
18
+ exports.inferJSONIndent = inferJSONIndent;
@@ -0,0 +1,2 @@
1
+ import { TemplateSyncReturn } from "../template-sync";
2
+ export declare function syncResultsToMd(result: TemplateSyncReturn): string;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.syncResultsToMd = void 0;
4
+ const template_sync_1 = require("../template-sync");
5
+ function syncResultsToMd(result) {
6
+ return `# ${template_sync_1.TEMPLATE_SYNC_LOCAL_CONFIG}
7
+
8
+ ## Stopped the following files from syncing:
9
+
10
+ ${result.localSkipFiles.reduce((s, file) => {
11
+ return `${s}* ${file}\n`;
12
+ }, "")}
13
+
14
+ ## Changed the following files from what they would have synced:
15
+
16
+ ${Object.keys(result.localFileChanges).reduce((s, file) => {
17
+ return `${s}${file}
18
+ \`\`\`diff
19
+ ${result.localFileChanges[file].reduce((diffS, change) => {
20
+ return `${diffS}\n${makeChangeIntoDiffLines(change)}`;
21
+ }, "")}
22
+ \`\`\``;
23
+ }, "")}
24
+ `;
25
+ }
26
+ exports.syncResultsToMd = syncResultsToMd;
27
+ function makeChangeIntoDiffLines(change, nonchangeMax = 3) {
28
+ const operator = change.added ? "+" : change.removed ? "-" : "";
29
+ if (!operator &&
30
+ nonchangeMax > 0 &&
31
+ change.count &&
32
+ change.count > nonchangeMax) {
33
+ const lines = change.value.split("\n");
34
+ const partial = lines.slice(lines.length - nonchangeMax);
35
+ return `...\n${partial.join("\n")}\n`;
36
+ }
37
+ return change.value.split("\n").reduce((s, line) => {
38
+ return `${s}${operator}${line}\n`;
39
+ }, "");
40
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./types";
2
+ export * from "./template-sync";
3
+ export * from "./formatting";
@@ -0,0 +1,19 @@
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("./types"), exports);
18
+ __exportStar(require("./template-sync"), exports);
19
+ __exportStar(require("./formatting"), exports);
@@ -0,0 +1,2 @@
1
+ import { MergeConfig, MergePlugin } from "./types";
2
+ export declare function loadPlugin<T>(mergeConfig: MergeConfig<T>, forExt: string, configDir: string): Promise<MergePlugin<T>>;
@@ -0,0 +1,63 @@
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.loadPlugin = void 0;
27
+ const plugins_1 = require("./plugins");
28
+ const fs_1 = require("fs");
29
+ const path_1 = require("path");
30
+ async function loadPlugin(mergeConfig, forExt, configDir) {
31
+ let handler;
32
+ if (mergeConfig.plugin) {
33
+ // First check if this is a loal .js file
34
+ const localPath = (0, path_1.resolve)(configDir, mergeConfig.plugin);
35
+ const importPath = (0, fs_1.existsSync)(localPath) ? localPath : mergeConfig.plugin;
36
+ try {
37
+ // Sad workaround for testing since dynamic import segfaults
38
+ if (process.env.JEST_WORKER_ID !== undefined) {
39
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
40
+ handler = require(importPath);
41
+ }
42
+ else {
43
+ handler = (await Promise.resolve(`${importPath}`).then(s => __importStar(require(s))));
44
+ }
45
+ if (!handler.merge) {
46
+ handler = handler
47
+ .default;
48
+ }
49
+ }
50
+ catch (err) {
51
+ console.error(err);
52
+ throw err;
53
+ }
54
+ }
55
+ else {
56
+ if (!plugins_1.defaultExtensionMap[forExt]) {
57
+ throw new Error(`No default merge function supplied for ${forExt}. Cannot have mere config without custom plugin supplied.`);
58
+ }
59
+ handler = plugins_1.defaultExtensionMap[forExt];
60
+ }
61
+ return handler;
62
+ }
63
+ exports.loadPlugin = loadPlugin;
@@ -0,0 +1,10 @@
1
+ export declare function invertMatchPatterns(patterns: string[]): string[];
2
+ /**
3
+ * Gets all the files in the directory recursively while avoiding any micromatch patterns
4
+ * that would match for ignoring
5
+ *
6
+ * @param dir
7
+ * @param ignorePatterns
8
+ * @returns
9
+ */
10
+ export declare function getAllFilesInDir(dir: string, ignorePatterns: string[]): string[];
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAllFilesInDir = exports.invertMatchPatterns = void 0;
4
+ const fs_1 = require("fs");
5
+ const micromatch_1 = require("micromatch");
6
+ const path_1 = require("path");
7
+ function invertMatchPatterns(patterns) {
8
+ return patterns.map((pattern) => {
9
+ if (pattern.startsWith("!")) {
10
+ return pattern.slice(1);
11
+ }
12
+ return `!${pattern}`;
13
+ });
14
+ }
15
+ exports.invertMatchPatterns = invertMatchPatterns;
16
+ /**
17
+ * Gets all the files in the directory recursively while avoiding any micromatch patterns
18
+ * that would match for ignoring
19
+ *
20
+ * @param dir
21
+ * @param ignorePatterns
22
+ * @returns
23
+ */
24
+ function getAllFilesInDir(dir, ignorePatterns) {
25
+ return recurseDirsForFiles(dir, ignorePatterns);
26
+ }
27
+ exports.getAllFilesInDir = getAllFilesInDir;
28
+ function recurseDirsForFiles(dirpath, ignorePatterns, relativeRoot = "") {
29
+ return (0, fs_1.readdirSync)(dirpath, {
30
+ withFileTypes: true,
31
+ }).reduce((files, f) => {
32
+ const relPath = (0, path_1.join)(relativeRoot, f.name);
33
+ if ((0, micromatch_1.some)(relPath, ignorePatterns)) {
34
+ return files;
35
+ }
36
+ // Ensure we aren't ignoring these folders explicitly
37
+ if (f.isDirectory()) {
38
+ files.push(...recurseDirsForFiles((0, path_1.join)(dirpath, f.name), ignorePatterns, relPath));
39
+ }
40
+ else {
41
+ files.push(relPath);
42
+ }
43
+ return files;
44
+ }, []);
45
+ }