@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.
Files changed (295) hide show
  1. package/CHANGELOG.md +37 -46
  2. package/dist/cjs/checkout-drivers/git-checkout.js +37 -0
  3. package/dist/cjs/checkout-drivers/git-checkout.spec.js +60 -0
  4. package/dist/cjs/checkout-drivers/index.js +21 -0
  5. package/dist/cjs/checkout-drivers/types.js +11 -0
  6. package/dist/cjs/clone-drivers/git-clone.js +25 -0
  7. package/dist/cjs/clone-drivers/index.js +21 -0
  8. package/dist/cjs/clone-drivers/types.js +8 -0
  9. package/dist/cjs/diff-drivers/git-diff.js +30 -0
  10. package/dist/cjs/diff-drivers/git-diff.spec.js +138 -0
  11. package/dist/cjs/diff-drivers/index.js +21 -0
  12. package/dist/cjs/diff-drivers/types.js +6 -0
  13. package/dist/cjs/formatting/index.js +21 -0
  14. package/dist/cjs/formatting/infer-json-indent.js +26 -0
  15. package/dist/cjs/formatting/infer-json-indent.spec.js +50 -0
  16. package/dist/cjs/formatting/sync-results-to-md.js +62 -0
  17. package/dist/cjs/formatting/sync-results-to-md.spec.js +45 -0
  18. package/dist/cjs/index.js +22 -0
  19. package/dist/cjs/load-plugin.js +44 -0
  20. package/dist/cjs/match.js +51 -0
  21. package/dist/cjs/match.spec.js +75 -0
  22. package/dist/cjs/merge-file.js +91 -0
  23. package/dist/cjs/merge-file.spec.js +508 -0
  24. package/dist/cjs/plugins/index.js +20 -0
  25. package/dist/cjs/plugins/json-merge.js +228 -0
  26. package/dist/cjs/plugins/json-merge.spec.js +514 -0
  27. package/dist/cjs/ref-drivers/git-current-ref.js +18 -0
  28. package/dist/cjs/ref-drivers/git-current-ref.spec.js +15 -0
  29. package/dist/cjs/ref-drivers/index.js +20 -0
  30. package/dist/cjs/ref-drivers/types.js +11 -0
  31. package/dist/cjs/template-sync.js +236 -0
  32. package/dist/cjs/template-sync.spec.js +521 -0
  33. package/dist/cjs/test-utils/index.js +26 -0
  34. package/dist/cjs/types.js +12 -0
  35. package/dist/esm/checkout-drivers/git-checkout.mjs +27 -0
  36. package/dist/esm/checkout-drivers/git-checkout.spec.mjs +56 -0
  37. package/dist/esm/checkout-drivers/index.mjs +4 -0
  38. package/dist/esm/checkout-drivers/types.mjs +8 -0
  39. package/dist/esm/clone-drivers/git-clone.mjs +15 -0
  40. package/dist/esm/clone-drivers/index.mjs +4 -0
  41. package/dist/esm/clone-drivers/types.mjs +8 -0
  42. package/dist/esm/diff-drivers/git-diff.mjs +26 -0
  43. package/dist/esm/diff-drivers/git-diff.spec.mjs +93 -0
  44. package/dist/esm/diff-drivers/index.mjs +4 -0
  45. package/dist/esm/diff-drivers/types.mjs +6 -0
  46. package/dist/esm/formatting/index.mjs +4 -0
  47. package/dist/esm/formatting/infer-json-indent.mjs +16 -0
  48. package/dist/esm/formatting/infer-json-indent.spec.mjs +46 -0
  49. package/dist/esm/formatting/sync-results-to-md.mjs +52 -0
  50. package/dist/esm/formatting/sync-results-to-md.spec.mjs +41 -0
  51. package/dist/esm/index.mjs +5 -0
  52. package/dist/esm/load-plugin.mjs +40 -0
  53. package/dist/esm/match.mjs +40 -0
  54. package/dist/esm/match.spec.mjs +71 -0
  55. package/dist/esm/merge-file.mjs +88 -0
  56. package/dist/esm/merge-file.spec.mjs +504 -0
  57. package/dist/esm/plugins/index.mjs +10 -0
  58. package/dist/esm/plugins/json-merge.mjs +164 -0
  59. package/dist/esm/plugins/json-merge.spec.mjs +469 -0
  60. package/dist/esm/ref-drivers/git-current-ref.mjs +8 -0
  61. package/dist/esm/ref-drivers/git-current-ref.spec.mjs +11 -0
  62. package/dist/esm/ref-drivers/index.mjs +3 -0
  63. package/dist/esm/ref-drivers/types.mjs +8 -0
  64. package/dist/esm/template-sync.mjs +174 -0
  65. package/dist/esm/template-sync.spec.mjs +517 -0
  66. package/dist/esm/test-utils/index.mjs +10 -0
  67. package/dist/esm/types.mjs +9 -0
  68. package/{lib/cjs → dist/types}/checkout-drivers/git-checkout.d.ts +1 -0
  69. package/dist/types/checkout-drivers/git-checkout.d.ts.map +1 -0
  70. package/dist/types/checkout-drivers/git-checkout.spec.d.ts +2 -0
  71. package/dist/types/checkout-drivers/git-checkout.spec.d.ts.map +1 -0
  72. package/{lib/cjs → dist/types}/checkout-drivers/index.d.ts +1 -0
  73. package/dist/types/checkout-drivers/index.d.ts.map +1 -0
  74. package/{lib/cjs → dist/types}/checkout-drivers/types.d.ts +1 -0
  75. package/dist/types/checkout-drivers/types.d.ts.map +1 -0
  76. package/{lib/cjs → dist/types}/clone-drivers/git-clone.d.ts +2 -1
  77. package/dist/types/clone-drivers/git-clone.d.ts.map +1 -0
  78. package/{lib/cjs → dist/types}/clone-drivers/index.d.ts +2 -1
  79. package/dist/types/clone-drivers/index.d.ts.map +1 -0
  80. package/{lib/cjs → dist/types}/clone-drivers/types.d.ts +1 -0
  81. package/dist/types/clone-drivers/types.d.ts.map +1 -0
  82. package/{lib/cjs → dist/types}/diff-drivers/git-diff.d.ts +1 -0
  83. package/dist/types/diff-drivers/git-diff.d.ts.map +1 -0
  84. package/dist/types/diff-drivers/git-diff.spec.d.ts +2 -0
  85. package/dist/types/diff-drivers/git-diff.spec.d.ts.map +1 -0
  86. package/{lib/cjs → dist/types}/diff-drivers/index.d.ts +2 -1
  87. package/dist/types/diff-drivers/index.d.ts.map +1 -0
  88. package/{lib/cjs → dist/types}/diff-drivers/types.d.ts +1 -0
  89. package/dist/types/diff-drivers/types.d.ts.map +1 -0
  90. package/{lib/cjs → dist/types}/formatting/index.d.ts +2 -1
  91. package/dist/types/formatting/index.d.ts.map +1 -0
  92. package/{lib/cjs → dist/types}/formatting/infer-json-indent.d.ts +1 -0
  93. package/dist/types/formatting/infer-json-indent.d.ts.map +1 -0
  94. package/dist/types/formatting/infer-json-indent.spec.d.ts +2 -0
  95. package/dist/types/formatting/infer-json-indent.spec.d.ts.map +1 -0
  96. package/dist/types/formatting/sync-results-to-md.d.ts +3 -0
  97. package/dist/types/formatting/sync-results-to-md.d.ts.map +1 -0
  98. package/dist/types/formatting/sync-results-to-md.spec.d.ts +2 -0
  99. package/dist/types/formatting/sync-results-to-md.spec.d.ts.map +1 -0
  100. package/{lib/cjs → dist/types}/index.d.ts +3 -2
  101. package/dist/types/index.d.ts.map +1 -0
  102. package/{lib/cjs → dist/types}/load-plugin.d.ts +2 -1
  103. package/dist/types/load-plugin.d.ts.map +1 -0
  104. package/{lib/cjs → dist/types}/match.d.ts +1 -0
  105. package/dist/types/match.d.ts.map +1 -0
  106. package/dist/types/match.spec.d.ts +2 -0
  107. package/dist/types/match.spec.d.ts.map +1 -0
  108. package/{lib/cjs → dist/types}/merge-file.d.ts +3 -2
  109. package/dist/types/merge-file.d.ts.map +1 -0
  110. package/dist/types/merge-file.spec.d.ts +2 -0
  111. package/dist/types/merge-file.spec.d.ts.map +1 -0
  112. package/{lib/cjs → dist/types}/plugins/index.d.ts +2 -1
  113. package/dist/types/plugins/index.d.ts.map +1 -0
  114. package/{lib/cjs → dist/types}/plugins/json-merge.d.ts +2 -1
  115. package/dist/types/plugins/json-merge.d.ts.map +1 -0
  116. package/dist/types/plugins/json-merge.spec.d.ts +2 -0
  117. package/dist/types/plugins/json-merge.spec.d.ts.map +1 -0
  118. package/{lib/cjs → dist/types}/ref-drivers/git-current-ref.d.ts +1 -0
  119. package/dist/types/ref-drivers/git-current-ref.d.ts.map +1 -0
  120. package/dist/types/ref-drivers/git-current-ref.spec.d.ts +2 -0
  121. package/dist/types/ref-drivers/git-current-ref.spec.d.ts.map +1 -0
  122. package/{lib/cjs → dist/types}/ref-drivers/index.d.ts +1 -0
  123. package/dist/types/ref-drivers/index.d.ts.map +1 -0
  124. package/{lib/cjs → dist/types}/ref-drivers/types.d.ts +1 -0
  125. package/dist/types/ref-drivers/types.d.ts.map +1 -0
  126. package/{lib/cjs → dist/types}/template-sync.d.ts +6 -5
  127. package/dist/types/template-sync.d.ts.map +1 -0
  128. package/dist/types/template-sync.spec.d.ts +2 -0
  129. package/dist/types/template-sync.spec.d.ts.map +1 -0
  130. package/{lib/cjs → dist/types}/test-utils/index.d.ts +1 -0
  131. package/dist/types/test-utils/index.d.ts.map +1 -0
  132. package/{lib/cjs → dist/types}/types.d.ts +1 -0
  133. package/dist/types/types.d.ts.map +1 -0
  134. package/package.json +26 -23
  135. package/.eslintrc.js +0 -10
  136. package/.github/CODEOWNERS +0 -6
  137. package/.github/workflows/pr-checks.yaml +0 -12
  138. package/.github/workflows/release.yaml +0 -47
  139. package/.github/workflows/test-flow.yaml +0 -63
  140. package/.husky/commit-msg +0 -4
  141. package/.prettierignore +0 -1
  142. package/.prettierrc +0 -1
  143. package/action.yml +0 -13
  144. package/commitlint.config.js +0 -3
  145. package/docs/merge-plugins/CURRENT_PLUGINS.md +0 -168
  146. package/docs/merge-plugins/PLUGIN_DEVELOPMENT.md +0 -122
  147. package/docs/merge-plugins/README.md +0 -75
  148. package/jest.config.js +0 -19
  149. package/lib/cjs/checkout-drivers/git-checkout.js +0 -29
  150. package/lib/cjs/checkout-drivers/index.js +0 -18
  151. package/lib/cjs/checkout-drivers/types.js +0 -2
  152. package/lib/cjs/clone-drivers/git-clone.js +0 -17
  153. package/lib/cjs/clone-drivers/index.js +0 -18
  154. package/lib/cjs/clone-drivers/types.js +0 -2
  155. package/lib/cjs/diff-drivers/git-diff.js +0 -41
  156. package/lib/cjs/diff-drivers/index.js +0 -18
  157. package/lib/cjs/diff-drivers/types.js +0 -2
  158. package/lib/cjs/formatting/index.js +0 -18
  159. package/lib/cjs/formatting/infer-json-indent.js +0 -18
  160. package/lib/cjs/formatting/sync-results-to-md.d.ts +0 -2
  161. package/lib/cjs/formatting/sync-results-to-md.js +0 -57
  162. package/lib/cjs/index.js +0 -19
  163. package/lib/cjs/load-plugin.js +0 -69
  164. package/lib/cjs/match.js +0 -45
  165. package/lib/cjs/merge-file.js +0 -98
  166. package/lib/cjs/plugins/index.js +0 -11
  167. package/lib/cjs/plugins/json-merge.js +0 -208
  168. package/lib/cjs/ref-drivers/git-current-ref.js +0 -12
  169. package/lib/cjs/ref-drivers/index.js +0 -17
  170. package/lib/cjs/ref-drivers/types.js +0 -2
  171. package/lib/cjs/template-sync.js +0 -204
  172. package/lib/cjs/test-utils/index.js +0 -10
  173. package/lib/cjs/types.js +0 -2
  174. package/lib/esm/checkout-drivers/git-checkout.js +0 -29
  175. package/lib/esm/checkout-drivers/index.js +0 -18
  176. package/lib/esm/checkout-drivers/types.js +0 -2
  177. package/lib/esm/clone-drivers/git-clone.js +0 -17
  178. package/lib/esm/clone-drivers/index.js +0 -18
  179. package/lib/esm/clone-drivers/types.js +0 -2
  180. package/lib/esm/diff-drivers/git-diff.js +0 -41
  181. package/lib/esm/diff-drivers/index.js +0 -18
  182. package/lib/esm/diff-drivers/types.js +0 -2
  183. package/lib/esm/formatting/index.js +0 -18
  184. package/lib/esm/formatting/infer-json-indent.js +0 -18
  185. package/lib/esm/formatting/sync-results-to-md.js +0 -57
  186. package/lib/esm/index.js +0 -19
  187. package/lib/esm/load-plugin.js +0 -46
  188. package/lib/esm/match.js +0 -45
  189. package/lib/esm/merge-file.js +0 -98
  190. package/lib/esm/plugins/index.js +0 -11
  191. package/lib/esm/plugins/json-merge.js +0 -208
  192. package/lib/esm/ref-drivers/git-current-ref.js +0 -12
  193. package/lib/esm/ref-drivers/index.js +0 -17
  194. package/lib/esm/ref-drivers/types.js +0 -2
  195. package/lib/esm/template-sync.js +0 -204
  196. package/lib/esm/test-utils/index.js +0 -10
  197. package/lib/esm/types.js +0 -2
  198. package/release.config.js +0 -40
  199. package/src/checkout-drivers/git-checkout.spec.ts +0 -69
  200. package/src/checkout-drivers/git-checkout.ts +0 -38
  201. package/src/checkout-drivers/index.ts +0 -2
  202. package/src/checkout-drivers/types.ts +0 -14
  203. package/src/clone-drivers/git-clone.ts +0 -20
  204. package/src/clone-drivers/index.ts +0 -2
  205. package/src/clone-drivers/types.ts +0 -20
  206. package/src/diff-drivers/git-diff.spec.ts +0 -73
  207. package/src/diff-drivers/git-diff.ts +0 -39
  208. package/src/diff-drivers/index.ts +0 -2
  209. package/src/diff-drivers/types.ts +0 -14
  210. package/src/formatting/__snapshots__/sync-results-to-md.spec.ts.snap +0 -39
  211. package/src/formatting/index.ts +0 -2
  212. package/src/formatting/infer-json-indent.spec.ts +0 -49
  213. package/src/formatting/infer-json-indent.ts +0 -16
  214. package/src/formatting/sync-results-to-md.spec.ts +0 -31
  215. package/src/formatting/sync-results-to-md.ts +0 -63
  216. package/src/index.ts +0 -3
  217. package/src/load-plugin.ts +0 -51
  218. package/src/match.spec.ts +0 -68
  219. package/src/match.ts +0 -52
  220. package/src/merge-file.spec.ts +0 -506
  221. package/src/merge-file.ts +0 -154
  222. package/src/plugins/index.ts +0 -12
  223. package/src/plugins/json-merge.spec.ts +0 -436
  224. package/src/plugins/json-merge.ts +0 -215
  225. package/src/ref-drivers/git-current-ref.spec.ts +0 -12
  226. package/src/ref-drivers/git-current-ref.ts +0 -9
  227. package/src/ref-drivers/index.ts +0 -1
  228. package/src/ref-drivers/types.ts +0 -10
  229. package/src/template-sync.spec.ts +0 -602
  230. package/src/template-sync.ts +0 -304
  231. package/src/test-utils/index.ts +0 -13
  232. package/src/types.ts +0 -129
  233. package/templatesync.local.json +0 -15
  234. package/test-fixtures/downstream/README.md +0 -3
  235. package/test-fixtures/downstream/package.json +0 -18
  236. package/test-fixtures/downstream/plugins/custom-plugin.js +0 -14
  237. package/test-fixtures/downstream/plugins/fail-validate-plugin.js +0 -14
  238. package/test-fixtures/downstream/src/index.js +0 -2
  239. package/test-fixtures/downstream/src/index.ts +0 -1
  240. package/test-fixtures/downstream/src/templated.js +0 -2
  241. package/test-fixtures/downstream/src/templated.ts +0 -1
  242. package/test-fixtures/downstream/templatesync.json +0 -16
  243. package/test-fixtures/downstream/templatesync.local.json +0 -10
  244. package/test-fixtures/dummy-plugin.js +0 -8
  245. package/test-fixtures/glob-test/folder1/something.js +0 -1
  246. package/test-fixtures/glob-test/folder1/something.ts +0 -0
  247. package/test-fixtures/glob-test/toplevel.js +0 -0
  248. package/test-fixtures/glob-test/toplevel.txt +0 -0
  249. package/test-fixtures/template/custom-bin/something.txt +0 -1
  250. package/test-fixtures/template/dummy-fail-plugin.js +0 -8
  251. package/test-fixtures/template/package.json +0 -17
  252. package/test-fixtures/template/src/index.js +0 -2
  253. package/test-fixtures/template/src/index.ts +0 -1
  254. package/test-fixtures/template/src/templated.js +0 -2
  255. package/test-fixtures/template/src/templated.ts +0 -1
  256. package/test-fixtures/template/templatesync.json +0 -16
  257. package/test-fixtures/testGitRepo/README.md +0 -17
  258. package/test-fixtures/testGitRepo/gitDir/COMMIT_EDITMSG +0 -14
  259. package/test-fixtures/testGitRepo/gitDir/HEAD +0 -1
  260. package/test-fixtures/testGitRepo/gitDir/config +0 -7
  261. package/test-fixtures/testGitRepo/gitDir/description +0 -1
  262. package/test-fixtures/testGitRepo/gitDir/hooks/applypatch-msg.sample +0 -15
  263. package/test-fixtures/testGitRepo/gitDir/hooks/commit-msg.sample +0 -24
  264. package/test-fixtures/testGitRepo/gitDir/hooks/fsmonitor-watchman.sample +0 -174
  265. package/test-fixtures/testGitRepo/gitDir/hooks/post-update.sample +0 -8
  266. package/test-fixtures/testGitRepo/gitDir/hooks/pre-applypatch.sample +0 -14
  267. package/test-fixtures/testGitRepo/gitDir/hooks/pre-commit.sample +0 -49
  268. package/test-fixtures/testGitRepo/gitDir/hooks/pre-merge-commit.sample +0 -13
  269. package/test-fixtures/testGitRepo/gitDir/hooks/pre-push.sample +0 -53
  270. package/test-fixtures/testGitRepo/gitDir/hooks/pre-rebase.sample +0 -169
  271. package/test-fixtures/testGitRepo/gitDir/hooks/pre-receive.sample +0 -24
  272. package/test-fixtures/testGitRepo/gitDir/hooks/prepare-commit-msg.sample +0 -42
  273. package/test-fixtures/testGitRepo/gitDir/hooks/push-to-checkout.sample +0 -78
  274. package/test-fixtures/testGitRepo/gitDir/hooks/sendemail-validate.sample +0 -77
  275. package/test-fixtures/testGitRepo/gitDir/hooks/update.sample +0 -128
  276. package/test-fixtures/testGitRepo/gitDir/index +0 -0
  277. package/test-fixtures/testGitRepo/gitDir/info/exclude +0 -6
  278. package/test-fixtures/testGitRepo/gitDir/logs/HEAD +0 -5
  279. package/test-fixtures/testGitRepo/gitDir/logs/refs/heads/master +0 -2
  280. package/test-fixtures/testGitRepo/gitDir/logs/refs/heads/test-branch +0 -2
  281. package/test-fixtures/testGitRepo/gitDir/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 +0 -0
  282. package/test-fixtures/testGitRepo/gitDir/objects/6e/187bee8d02f39d0a1be8331dd8fe6a00c9b613 +0 -0
  283. package/test-fixtures/testGitRepo/gitDir/objects/73/185f1f3f5a6345e087d9f46dc4af77cc59449f +0 -2
  284. package/test-fixtures/testGitRepo/gitDir/objects/90/e7ea1089f939840e9649fd617584c1ad117159 +0 -3
  285. package/test-fixtures/testGitRepo/gitDir/objects/ba/99a452b9097047e9bfa8d5a08b3e452fcb364a +0 -0
  286. package/test-fixtures/testGitRepo/gitDir/objects/c5/8d400177cd5180b8566f82a127fafc5bf394b7 +0 -0
  287. package/test-fixtures/testGitRepo/gitDir/objects/e2/e668265db019249a7e8296d85f79000e3d71cf +0 -0
  288. package/test-fixtures/testGitRepo/gitDir/objects/e4/243e430c1ab69f3e344249f5b1859e90abc883 +0 -1
  289. package/test-fixtures/testGitRepo/gitDir/objects/ec/6c1cb72312605282ac61858cf1eaf1ea9f1d02 +0 -0
  290. package/test-fixtures/testGitRepo/gitDir/objects/fc/89cecc4ac0b5b075bd7d0ce9e09b2f50598b82 +0 -0
  291. package/test-fixtures/testGitRepo/gitDir/refs/heads/master +0 -1
  292. package/test-fixtures/testGitRepo/gitDir/refs/heads/test-branch +0 -1
  293. package/tsconfig.cjs.json +0 -12
  294. package/tsconfig.esm.json +0 -10
  295. package/tsconfig.json +0 -22
@@ -1,73 +0,0 @@
1
- import { execSync } from "child_process";
2
- import * as fs from "fs";
3
- import * as path from "path";
4
- import { gitDiff } from "./git-diff";
5
-
6
- describe("gitDiff", () => {
7
- let tempDir: string;
8
-
9
- beforeEach(() => {
10
- tempDir = fs.mkdtempSync("gitdiff-test");
11
- // Initialize a git repo
12
- execSync("git init", { cwd: tempDir });
13
- fs.writeFileSync(path.join(tempDir, "file1.txt"), "hello");
14
- fs.writeFileSync(path.join(tempDir, "second.txt"), "second");
15
- fs.writeFileSync(path.join(tempDir, "third.txt"), "third");
16
- execSync("git add . && git commit -m 'initial'", { cwd: tempDir });
17
- });
18
-
19
- afterEach(() => {
20
- fs.rmSync(tempDir, { recursive: true, force: true });
21
- });
22
-
23
- it("handles a rename as a delete and an add", async () => {
24
- const firstCommit = execSync("git rev-parse HEAD", { cwd: tempDir })
25
- .toString()
26
- .trim();
27
-
28
- // Perform a rename
29
- execSync("git mv file1.txt file2.txt", { cwd: tempDir });
30
- execSync("git commit -m 'rename'", { cwd: tempDir });
31
-
32
- const result = await gitDiff(tempDir, firstCommit);
33
-
34
- // Because of --no-renames:
35
- expect(result).toEqual({
36
- deleted: ["file1.txt"],
37
- added: ["file2.txt"],
38
- modified: [],
39
- });
40
- });
41
- it("handles a added, deleted, and modified appropriately across multiple commits", async () => {
42
- const firstCommit = execSync("git rev-parse HEAD", { cwd: tempDir })
43
- .toString()
44
- .trim();
45
-
46
- // Perform a rename
47
- execSync("git mv file1.txt file2.txt", { cwd: tempDir });
48
- execSync("git commit -m 'rename'", { cwd: tempDir });
49
-
50
- // Perform adds
51
- fs.writeFileSync(path.join(tempDir, "another.txt"), "another file");
52
- execSync("git add . && git commit -m 'adding another file'", {
53
- cwd: tempDir,
54
- });
55
-
56
- // Perform a modify
57
- fs.writeFileSync(path.join(tempDir, "third.txt"), "third+");
58
- execSync("git add . && git commit -m 'modifying third'", { cwd: tempDir });
59
-
60
- // Perform a delete
61
- fs.rmSync(path.join(tempDir, "second.txt"));
62
- execSync("git add . && git commit -m 'deleting second'", { cwd: tempDir });
63
-
64
- const result = await gitDiff(tempDir, firstCommit);
65
-
66
- // Because of --no-renames:
67
- expect(result).toEqual({
68
- deleted: expect.arrayContaining(["file1.txt", "second.txt"]),
69
- added: expect.arrayContaining(["file2.txt", "another.txt"]),
70
- modified: ["third.txt"],
71
- });
72
- });
73
- });
@@ -1,39 +0,0 @@
1
- import { execSync } from "child_process";
2
-
3
- /**
4
- * For a given directory with a git configuration, this will return the modified, added, and
5
- * deleted files since the last afterRef
6
- * @param gitDir The git directory folder
7
- * @param afterRef The git ref to look for diffs after
8
- * @returns
9
- */
10
- export async function gitDiff(gitDir: string, afterRef: string) {
11
- const baseCommand = `git diff ${afterRef}.. --no-renames --name-only`;
12
- const modifiedFiles = execSync(`${baseCommand} --diff-filter=M`, {
13
- cwd: gitDir,
14
- })
15
- .toString()
16
- .trim()
17
- .split("\n")
18
- .filter((s) => s !== "");
19
- const addedFiles = execSync(`${baseCommand} --diff-filter=A`, {
20
- cwd: gitDir,
21
- })
22
- .toString()
23
- .trim()
24
- .split("\n")
25
- .filter((s) => s !== "");
26
- const deletedFiles = execSync(`${baseCommand} --diff-filter=D`, {
27
- cwd: gitDir,
28
- })
29
- .toString()
30
- .trim()
31
- .split("\n")
32
- .filter((s) => s !== "");
33
-
34
- return {
35
- modified: modifiedFiles,
36
- added: addedFiles,
37
- deleted: deletedFiles,
38
- };
39
- }
@@ -1,2 +0,0 @@
1
- export * from "./types";
2
- export * from "./git-diff";
@@ -1,14 +0,0 @@
1
- export interface DiffResult {
2
- modified: string[];
3
- added: string[];
4
- deleted: string[];
5
- }
6
-
7
- /**
8
- * A function that operates within the gitDir, and returns the list of file paths
9
- * since the last sha
10
- */
11
- export type TemplateDiffDriverFn = (
12
- gitDir: string,
13
- afterRef: string,
14
- ) => Promise<DiffResult>;
@@ -1,39 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`syncResultsToMd snapshots 1`] = `
4
- "# templatesync.local
5
-
6
- ## Stopped the following files from syncing:
7
-
8
- * src/file1.ts
9
-
10
-
11
- ## Changed the following files from what they would have synced:
12
-
13
- package.json
14
- \`\`\`diff
15
-
16
- +my thing
17
-
18
- -your thang
19
-
20
- \`\`\`
21
-
22
- ## Files Modified (6)
23
-
24
- Added:
25
-
26
- - src/something.ts
27
- - new_settings.toml
28
-
29
- Modified:
30
-
31
- - something.txt
32
- - .env
33
-
34
- Deleted:
35
-
36
- - TODO.md
37
- - throwaway.ts
38
- "
39
- `;
@@ -1,2 +0,0 @@
1
- export * from "./sync-results-to-md";
2
- export * from "./infer-json-indent";
@@ -1,49 +0,0 @@
1
- import { inferJSONIndent } from "./infer-json-indent";
2
-
3
- const withNewLine = `{
4
-
5
- "whoa": true,
6
- "thing": here,
7
- "something": {
8
- "nested": false
9
- }
10
- }`;
11
-
12
- const fourSpaces = `{
13
- "whoa": true,
14
- "thing": here,
15
- "something": {
16
- "nested": false
17
- }
18
- }`;
19
-
20
- const tabSpaces = `{
21
- "whoa": true,
22
- "thing": here,
23
- "something": {
24
- "nested": false
25
- }
26
- }`;
27
-
28
- const twoSpaces = `{
29
- "whoa": true,
30
- "thing": here,
31
- "something": {
32
- "nested": false
33
- }
34
- }`;
35
-
36
- describe("inferJSONIndent", () => {
37
- it("returns spaces when the first indent is spaces with a new line", () => {
38
- expect(inferJSONIndent(withNewLine)).toBe(" ");
39
- });
40
- it("returns spaces when the first indent is spaces", () => {
41
- expect(inferJSONIndent(fourSpaces)).toBe(" ");
42
- });
43
- it("returns spaces when the first indent is spaces", () => {
44
- expect(inferJSONIndent(twoSpaces)).toBe(" ");
45
- });
46
- it("returns tabs when the first indent is a tab", () => {
47
- expect(inferJSONIndent(tabSpaces)).toBe("\t");
48
- });
49
- });
@@ -1,16 +0,0 @@
1
- const spacingRegex = /[{[]\n?(?<spacing>\s+)["tf\d]/;
2
- export function inferJSONIndent(rawJSON: string) {
3
- const match = spacingRegex.exec(rawJSON);
4
- if (!match?.groups?.spacing) {
5
- // eslint-disable-next-line no-console
6
- console.warn(
7
- `Could not find json indentation for json string: ${rawJSON.slice(40)} ... \nDefaulting to 4 spaces`,
8
- );
9
- // Four spaces
10
- return " ";
11
- }
12
- const spacing = match.groups.spacing;
13
- // Handle the case where there were multiple newlines before a value
14
- const lastNewLine = spacing.lastIndexOf("\n");
15
- return match?.groups.spacing.slice(lastNewLine >= 0 ? lastNewLine + 1 : 0);
16
- }
@@ -1,31 +0,0 @@
1
- import { syncResultsToMd } from "./sync-results-to-md";
2
-
3
- describe("syncResultsToMd", () => {
4
- it("snapshots", () => {
5
- expect(
6
- syncResultsToMd({
7
- localSkipFiles: ["src/file1.ts"],
8
- localFileChanges: {
9
- "package.json": [
10
- {
11
- count: 8,
12
- value: "my thing",
13
- added: true,
14
- },
15
- {
16
- count: 10,
17
- value: "your thang",
18
- removed: true,
19
- },
20
- ],
21
- },
22
- modifiedFiles: {
23
- added: ["src/something.ts", "new_settings.toml"],
24
- deleted: ["TODO.md", "throwaway.ts"],
25
- modified: ["something.txt", ".env"],
26
- total: 6,
27
- },
28
- }),
29
- ).toMatchSnapshot();
30
- });
31
- });
@@ -1,63 +0,0 @@
1
- import { Change } from "diff";
2
- import {
3
- TEMPLATE_SYNC_LOCAL_CONFIG,
4
- TemplateSyncReturn,
5
- } from "../template-sync";
6
-
7
- export function syncResultsToMd(result: TemplateSyncReturn) {
8
- return `# ${TEMPLATE_SYNC_LOCAL_CONFIG}
9
-
10
- ## Stopped the following files from syncing:
11
-
12
- ${result.localSkipFiles.reduce((s, file) => {
13
- return `${s}* ${file}\n`;
14
- }, "")}
15
-
16
- ## Changed the following files from what they would have synced:
17
-
18
- ${Object.keys(result.localFileChanges).reduce((s, file) => {
19
- return `${s}${file}
20
- \`\`\`diff
21
- ${result.localFileChanges[file].reduce((diffS, change) => {
22
- return `${diffS}\n${makeChangeIntoDiffLines(change)}`;
23
- }, "")}
24
- \`\`\``;
25
- }, "")}
26
-
27
- ## Files Modified (${result.modifiedFiles.total})
28
-
29
- Added:
30
- ${result.modifiedFiles.added.reduce((s, f) => {
31
- return `${s}\n- ${f}`;
32
- }, "")}
33
-
34
- Modified:
35
- ${result.modifiedFiles.modified.reduce((s, f) => {
36
- return `${s}\n- ${f}`;
37
- }, "")}
38
-
39
- Deleted:
40
- ${result.modifiedFiles.deleted.reduce((s, f) => {
41
- return `${s}\n- ${f}`;
42
- }, "")}
43
- `;
44
- }
45
-
46
- function makeChangeIntoDiffLines(change: Change, nonchangeMax = 3) {
47
- const operator = change.added ? "+" : change.removed ? "-" : "";
48
-
49
- if (
50
- !operator &&
51
- nonchangeMax > 0 &&
52
- change.count &&
53
- change.count > nonchangeMax
54
- ) {
55
- const lines = change.value.split("\n");
56
- const partial = lines.slice(lines.length - nonchangeMax);
57
- return `...\n${partial.join("\n")}\n`;
58
- }
59
-
60
- return change.value.split("\n").reduce((s, line) => {
61
- return `${s}${operator}${line}\n`;
62
- }, "");
63
- }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from "./types";
2
- export * from "./template-sync";
3
- export * from "./formatting";
@@ -1,51 +0,0 @@
1
- import { defaultExtensionMap } from "./plugins";
2
- import { MergeConfig, MergePlugin } from "./types";
3
- import { existsSync } from "fs";
4
- import { resolve } from "path";
5
-
6
- /**
7
- * Loads the plugin associated with the merge config
8
- * @param mergeConfig
9
- * @param forExt
10
- * @param configDir
11
- * @returns
12
- */
13
- export async function loadPlugin<T>(
14
- mergeConfig: MergeConfig<T>,
15
- configDir: string,
16
- ): Promise<MergePlugin<T>> {
17
- if (mergeConfig.plugin.startsWith("_")) {
18
- const defaultHandler = Object.values(defaultExtensionMap).find(
19
- (el) => el.builtinName === mergeConfig.plugin,
20
- );
21
- if (!defaultHandler) {
22
- throw new Error(
23
- `No builtin merge function supplied for ${mergeConfig.plugin}. Cannot have merge config without custom plugin supplied.`,
24
- );
25
- }
26
- return defaultHandler as MergePlugin<T>;
27
- }
28
-
29
- let handler: MergePlugin<unknown>;
30
- // First check if this is a local .js file
31
- const localPath = resolve(configDir, mergeConfig.plugin);
32
- const importPath = existsSync(localPath) ? localPath : mergeConfig.plugin;
33
- try {
34
- // Sad workaround for testing since dynamic import segfaults
35
- if (process.env.JEST_WORKER_ID !== undefined) {
36
- // eslint-disable-next-line @typescript-eslint/no-var-requires
37
- handler = require(importPath) as MergePlugin<unknown>;
38
- } else {
39
- handler = (await import(importPath)) as MergePlugin<unknown>;
40
- }
41
- if (!handler.merge) {
42
- handler = (handler as unknown as { default: MergePlugin<unknown> })
43
- .default;
44
- }
45
- } catch (err) {
46
- console.error(err);
47
- throw err;
48
- }
49
-
50
- return handler as MergePlugin<T>;
51
- }
package/src/match.spec.ts DELETED
@@ -1,68 +0,0 @@
1
- import { resolve } from "path";
2
- import { getAllFilesInDir } from "./match";
3
- import { TEST_FIXTURES_DIR } from "./test-utils";
4
-
5
- const TEST_GLOB_DIR = resolve(TEST_FIXTURES_DIR, "glob-test");
6
-
7
- describe("getAllFilesInDir", () => {
8
- it("gets all files in the directory with no ignores", () => {
9
- const files = getAllFilesInDir(TEST_GLOB_DIR, []);
10
- expect(files).toEqual(
11
- expect.arrayContaining([
12
- "folder1/something.js",
13
- "folder1/something.ts",
14
- "toplevel.js",
15
- "toplevel.txt",
16
- ]),
17
- );
18
- try {
19
- expect(files.length).toBe(4);
20
- } catch (err) {
21
- console.error("All found files: " + files);
22
- throw err;
23
- }
24
- });
25
- it("gets all files in the directory that do not match the ignore (single)", () => {
26
- const files = getAllFilesInDir(TEST_GLOB_DIR, ["**/*.ts"]);
27
- expect(files).toEqual(
28
- expect.arrayContaining([
29
- "folder1/something.js",
30
- "toplevel.js",
31
- "toplevel.txt",
32
- ]),
33
- );
34
- try {
35
- expect(files.length).toBe(3);
36
- } catch (err) {
37
- console.error("All found files: " + files);
38
- throw err;
39
- }
40
- });
41
- it("gets all files in the directory that do not match the ignore (multiple)", () => {
42
- const files = getAllFilesInDir(TEST_GLOB_DIR, ["**/*.ts", "**/*.txt"]);
43
- expect(files).toEqual(
44
- expect.arrayContaining(["folder1/something.js", "toplevel.js"]),
45
- );
46
- try {
47
- expect(files.length).toBe(2);
48
- } catch (err) {
49
- console.error("All found files: " + files);
50
- throw err;
51
- }
52
- });
53
-
54
- it("gets all files in the directory that do not match the ignore with a folder level directive (multiple)", () => {
55
- const files = getAllFilesInDir(TEST_GLOB_DIR, [
56
- "**/*.ts",
57
- "**/*.txt",
58
- "folder1",
59
- ]);
60
- expect(files).toEqual(expect.arrayContaining(["toplevel.js"]));
61
- try {
62
- expect(files.length).toBe(1);
63
- } catch (err) {
64
- console.error("All found files: " + files);
65
- throw err;
66
- }
67
- });
68
- });
package/src/match.ts DELETED
@@ -1,52 +0,0 @@
1
- import { readdirSync } from "fs";
2
- import { some } from "micromatch";
3
- import { join } from "path";
4
-
5
- export function invertMatchPatterns(patterns: string[]) {
6
- return patterns.map((pattern) => {
7
- if (pattern.startsWith("!")) {
8
- return pattern.slice(1);
9
- }
10
- return `!${pattern}`;
11
- });
12
- }
13
-
14
- /**
15
- * Gets all the files in the directory recursively while avoiding any micromatch patterns
16
- * that would match for ignoring
17
- *
18
- * @param dir
19
- * @param ignorePatterns
20
- * @returns
21
- */
22
- export function getAllFilesInDir(
23
- dir: string,
24
- ignorePatterns: string[],
25
- ): string[] {
26
- return recurseDirsForFiles(dir, ignorePatterns);
27
- }
28
-
29
- function recurseDirsForFiles(
30
- dirpath: string,
31
- ignorePatterns: string[],
32
- relativeRoot = "",
33
- ): string[] {
34
- return readdirSync(dirpath, {
35
- withFileTypes: true,
36
- }).reduce((files, f) => {
37
- const relPath = join(relativeRoot, f.name);
38
- if (some(relPath, ignorePatterns)) {
39
- return files;
40
- }
41
-
42
- // Ensure we aren't ignoring these folders explicitly
43
- if (f.isDirectory()) {
44
- files.push(
45
- ...recurseDirsForFiles(join(dirpath, f.name), ignorePatterns, relPath),
46
- );
47
- } else {
48
- files.push(relPath);
49
- }
50
- return files;
51
- }, [] as string[]);
52
- }