@hanseltime/template-repo-sync 2.2.1 → 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 (293) hide show
  1. package/CHANGELOG.md +43 -45
  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 -163
  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 -163
  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 -509
  230. package/src/template-sync.ts +0 -256
  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 -11
  237. package/test-fixtures/downstream/src/index.js +0 -2
  238. package/test-fixtures/downstream/src/index.ts +0 -1
  239. package/test-fixtures/downstream/src/templated.js +0 -2
  240. package/test-fixtures/downstream/src/templated.ts +0 -1
  241. package/test-fixtures/downstream/templatesync.json +0 -16
  242. package/test-fixtures/downstream/templatesync.local.json +0 -10
  243. package/test-fixtures/dummy-plugin.js +0 -8
  244. package/test-fixtures/glob-test/folder1/something.js +0 -1
  245. package/test-fixtures/glob-test/folder1/something.ts +0 -0
  246. package/test-fixtures/glob-test/toplevel.js +0 -0
  247. package/test-fixtures/glob-test/toplevel.txt +0 -0
  248. package/test-fixtures/template/custom-bin/something.txt +0 -1
  249. package/test-fixtures/template/package.json +0 -17
  250. package/test-fixtures/template/src/index.js +0 -2
  251. package/test-fixtures/template/src/index.ts +0 -1
  252. package/test-fixtures/template/src/templated.js +0 -2
  253. package/test-fixtures/template/src/templated.ts +0 -1
  254. package/test-fixtures/template/templatesync.json +0 -16
  255. package/test-fixtures/testGitRepo/README.md +0 -17
  256. package/test-fixtures/testGitRepo/gitDir/COMMIT_EDITMSG +0 -14
  257. package/test-fixtures/testGitRepo/gitDir/HEAD +0 -1
  258. package/test-fixtures/testGitRepo/gitDir/config +0 -7
  259. package/test-fixtures/testGitRepo/gitDir/description +0 -1
  260. package/test-fixtures/testGitRepo/gitDir/hooks/applypatch-msg.sample +0 -15
  261. package/test-fixtures/testGitRepo/gitDir/hooks/commit-msg.sample +0 -24
  262. package/test-fixtures/testGitRepo/gitDir/hooks/fsmonitor-watchman.sample +0 -174
  263. package/test-fixtures/testGitRepo/gitDir/hooks/post-update.sample +0 -8
  264. package/test-fixtures/testGitRepo/gitDir/hooks/pre-applypatch.sample +0 -14
  265. package/test-fixtures/testGitRepo/gitDir/hooks/pre-commit.sample +0 -49
  266. package/test-fixtures/testGitRepo/gitDir/hooks/pre-merge-commit.sample +0 -13
  267. package/test-fixtures/testGitRepo/gitDir/hooks/pre-push.sample +0 -53
  268. package/test-fixtures/testGitRepo/gitDir/hooks/pre-rebase.sample +0 -169
  269. package/test-fixtures/testGitRepo/gitDir/hooks/pre-receive.sample +0 -24
  270. package/test-fixtures/testGitRepo/gitDir/hooks/prepare-commit-msg.sample +0 -42
  271. package/test-fixtures/testGitRepo/gitDir/hooks/push-to-checkout.sample +0 -78
  272. package/test-fixtures/testGitRepo/gitDir/hooks/sendemail-validate.sample +0 -77
  273. package/test-fixtures/testGitRepo/gitDir/hooks/update.sample +0 -128
  274. package/test-fixtures/testGitRepo/gitDir/index +0 -0
  275. package/test-fixtures/testGitRepo/gitDir/info/exclude +0 -6
  276. package/test-fixtures/testGitRepo/gitDir/logs/HEAD +0 -5
  277. package/test-fixtures/testGitRepo/gitDir/logs/refs/heads/master +0 -2
  278. package/test-fixtures/testGitRepo/gitDir/logs/refs/heads/test-branch +0 -2
  279. package/test-fixtures/testGitRepo/gitDir/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 +0 -0
  280. package/test-fixtures/testGitRepo/gitDir/objects/6e/187bee8d02f39d0a1be8331dd8fe6a00c9b613 +0 -0
  281. package/test-fixtures/testGitRepo/gitDir/objects/73/185f1f3f5a6345e087d9f46dc4af77cc59449f +0 -2
  282. package/test-fixtures/testGitRepo/gitDir/objects/90/e7ea1089f939840e9649fd617584c1ad117159 +0 -3
  283. package/test-fixtures/testGitRepo/gitDir/objects/ba/99a452b9097047e9bfa8d5a08b3e452fcb364a +0 -0
  284. package/test-fixtures/testGitRepo/gitDir/objects/c5/8d400177cd5180b8566f82a127fafc5bf394b7 +0 -0
  285. package/test-fixtures/testGitRepo/gitDir/objects/e2/e668265db019249a7e8296d85f79000e3d71cf +0 -0
  286. package/test-fixtures/testGitRepo/gitDir/objects/e4/243e430c1ab69f3e344249f5b1859e90abc883 +0 -1
  287. package/test-fixtures/testGitRepo/gitDir/objects/ec/6c1cb72312605282ac61858cf1eaf1ea9f1d02 +0 -0
  288. package/test-fixtures/testGitRepo/gitDir/objects/fc/89cecc4ac0b5b075bd7d0ce9e09b2f50598b82 +0 -0
  289. package/test-fixtures/testGitRepo/gitDir/refs/heads/master +0 -1
  290. package/test-fixtures/testGitRepo/gitDir/refs/heads/test-branch +0 -1
  291. package/tsconfig.cjs.json +0 -12
  292. package/tsconfig.esm.json +0 -10
  293. package/tsconfig.json +0 -22
@@ -1,256 +0,0 @@
1
- import { join } from "path";
2
- import { existsSync, readFileSync, writeFileSync } from "fs";
3
- import { getAllFilesInDir } from "./match";
4
- import { Config, FileOperation, LocalConfig } from "./types";
5
- import { mergeFile } from "./merge-file";
6
- import { gitClone } from "./clone-drivers/git-clone";
7
- import { Change } from "diff";
8
- import { TemplateCloneDriverFn } from "./clone-drivers";
9
- import { DiffResult, TemplateDiffDriverFn, gitDiff } from "./diff-drivers";
10
- import { gitCurrentRef } from "./ref-drivers";
11
- import { TemplateRefDriverFn } from "./ref-drivers/types";
12
- import { inferJSONIndent } from "./formatting";
13
- import * as commentJSON from "comment-json";
14
- import { TemplateCheckoutDriverFn, gitCheckout } from "./checkout-drivers";
15
- import { some } from "micromatch";
16
-
17
- export interface TemplateSyncOptions {
18
- /**
19
- * This is the url of the template repo
20
- */
21
- repoUrl: string;
22
-
23
- /**
24
- * Optional Branch to check out - if not specified, this checks out the
25
- * default branch of the template repo
26
- */
27
- branch?: string;
28
-
29
- /**
30
- * The directory for cloning our template repo into via the cloneDriver
31
- */
32
- tmpCloneDir: string;
33
-
34
- /**
35
- * The repo directory path that we are going to merge toward
36
- */
37
- repoDir: string;
38
-
39
- /**
40
- * If set to true, template sync will apply the current ref
41
- * of the template repo to afterRef
42
- */
43
- updateAfterRef?: boolean;
44
-
45
- /**
46
- * Defaults to using git clone
47
- */
48
- cloneDriver?: TemplateCloneDriverFn;
49
-
50
- /**
51
- * Defaults to using git diff
52
- */
53
- diffDriver?: TemplateDiffDriverFn;
54
-
55
- /**
56
- * Defaults to using git current ref
57
- */
58
- currentRefDriver?: TemplateRefDriverFn;
59
-
60
- /**
61
- * Defaults to using git checkout driver
62
- */
63
- checkoutDriver?: TemplateCheckoutDriverFn;
64
- }
65
-
66
- export interface TemplateSyncReturn {
67
- /**
68
- * An array of files that were skipped outright due to a templatesync.local ignore glob
69
- */
70
- localSkipFiles: string[];
71
- /**
72
- * An object mapping all file paths to any merge rules that would've overridden the merge rules
73
- * of the template sync file.
74
- *
75
- * Note: right now, this shows non-changed diffs as well so you have to look for added or removed
76
- */
77
- localFileChanges: {
78
- [filePath: string]: Change[];
79
- };
80
- /**
81
- * A list of all files that are modified by this operation. You can use total to quickly check if
82
- * there was an actual meaningful change.
83
- *
84
- * Please note, ther may be localSkipfiles and total: 0, which indicates there were changes BUT the local template
85
- * sync file rendered them meaningless.
86
- */
87
- modifiedFiles: DiffResult & {
88
- total: number;
89
- };
90
- }
91
-
92
- export const TEMPLATE_SYNC_CONFIG = "templatesync";
93
- export const TEMPLATE_SYNC_LOCAL_CONFIG = "templatesync.local";
94
-
95
- export async function templateSync(
96
- options: TemplateSyncOptions,
97
- ): Promise<TemplateSyncReturn> {
98
- const cloneDriver = options.cloneDriver ?? gitClone;
99
- const diffDriver = options.diffDriver ?? gitDiff;
100
- const currentRefDriver = options.currentRefDriver ?? gitCurrentRef;
101
- const checkoutDriver = options.checkoutDriver ?? gitCheckout;
102
- const cloneReturn = await cloneDriver(options.tmpCloneDir, options.repoUrl);
103
-
104
- const { dir: tempCloneDir, remoteName } =
105
- typeof cloneReturn === "string"
106
- ? {
107
- dir: cloneReturn,
108
- remoteName: "origin", // Default to this
109
- }
110
- : cloneReturn;
111
-
112
- if (options.branch) {
113
- await checkoutDriver({
114
- tmpDir: tempCloneDir,
115
- remoteName,
116
- branch: options.branch,
117
- });
118
- }
119
-
120
- // Get the clone Config
121
- const cloneConfigPath = join(tempCloneDir, `${TEMPLATE_SYNC_CONFIG}.json`);
122
- const templateSyncConfig: Config = existsSync(cloneConfigPath)
123
- ? (commentJSON.parse(
124
- readFileSync(cloneConfigPath).toString(),
125
- ) as unknown as Config)
126
- : { ignore: [] };
127
-
128
- const localConfigFile = `${TEMPLATE_SYNC_LOCAL_CONFIG}.json`;
129
- const localConfigPath = join(options.repoDir, localConfigFile);
130
- const localTemplateSyncConfig: LocalConfig = existsSync(localConfigPath)
131
- ? (commentJSON.parse(
132
- readFileSync(localConfigPath).toString(),
133
- ) as unknown as LocalConfig)
134
- : { ignore: [] };
135
-
136
- let filesToSync: DiffResult;
137
- const ref = await currentRefDriver({
138
- rootDir: tempCloneDir,
139
- });
140
- if (localTemplateSyncConfig.afterRef) {
141
- if (ref === localTemplateSyncConfig.afterRef) {
142
- // short circuit if the refs match
143
- return {
144
- localSkipFiles: [],
145
- localFileChanges: {},
146
- modifiedFiles: {
147
- added: [],
148
- modified: [],
149
- deleted: [],
150
- total: 0,
151
- },
152
- };
153
- }
154
- filesToSync = await diffDriver(
155
- tempCloneDir,
156
- localTemplateSyncConfig.afterRef,
157
- );
158
- } else {
159
- filesToSync = {
160
- added: getAllFilesInDir(tempCloneDir, [
161
- ...templateSyncConfig.ignore,
162
- ".git/**",
163
- ]),
164
- deleted: [],
165
- modified: [],
166
- };
167
- }
168
-
169
- // Apply ignore filters
170
- filesToSync.added = filesToSync.added.filter(
171
- (f) => !some(f, templateSyncConfig.ignore),
172
- );
173
- filesToSync.modified = filesToSync.modified.filter(
174
- (f) => !some(f, templateSyncConfig.ignore),
175
- );
176
- filesToSync.deleted = filesToSync.deleted.filter(
177
- (f) => !some(f, templateSyncConfig.ignore),
178
- );
179
-
180
- const localSkipFiles: Set<string> = new Set();
181
- const localFileChanges: {
182
- [filePath: string]: Change[];
183
- } = {};
184
-
185
- const fileSyncFactory = (op: FileOperation) => {
186
- return async (f: string) => {
187
- const result = await mergeFile(f, {
188
- localTemplateSyncConfig,
189
- templateSyncConfig,
190
- tempCloneDir,
191
- cwd: options.repoDir,
192
- fileOperation: op,
193
- });
194
- if (result.ignoredDueToLocal) {
195
- localSkipFiles.add(f);
196
- } else if (result?.localChanges && result.localChanges.length > 0) {
197
- localFileChanges[f] = result.localChanges;
198
- }
199
- };
200
- };
201
-
202
- // Added and modified have the same setup for now
203
- await Promise.all(filesToSync.added.map(fileSyncFactory("added")));
204
- await Promise.all(filesToSync.modified.map(fileSyncFactory("modified")));
205
- await Promise.all(filesToSync.deleted.map(fileSyncFactory("deleted")));
206
-
207
- // Report the files that changed in general
208
- const actualAdded = filesToSync.added.filter((f) => !localSkipFiles.has(f));
209
- const actualModified = filesToSync.modified.filter(
210
- (f) => !localSkipFiles.has(f),
211
- );
212
- const actualDeleted = filesToSync.deleted.filter(
213
- (f) => !localSkipFiles.has(f),
214
- );
215
- const modifiedFiles = {
216
- added: actualAdded,
217
- modified: actualModified,
218
- deleted: actualDeleted,
219
- };
220
-
221
- // apply after ref
222
- if (options.updateAfterRef) {
223
- const ref = await currentRefDriver({
224
- rootDir: tempCloneDir,
225
- });
226
-
227
- if (existsSync(localConfigPath)) {
228
- const configStr = readFileSync(localConfigPath).toString();
229
- const config = commentJSON.parse(configStr) as unknown as LocalConfig;
230
- config.afterRef = ref;
231
- writeFileSync(
232
- localConfigPath,
233
- commentJSON.stringify(config, null, inferJSONIndent(configStr)),
234
- );
235
- modifiedFiles.modified.push(localConfigFile);
236
- } else {
237
- writeFileSync(
238
- localConfigPath,
239
- commentJSON.stringify({ afterRef: ref }, null, 4),
240
- );
241
- modifiedFiles.added.push(localConfigFile);
242
- }
243
- }
244
-
245
- return {
246
- localSkipFiles: Array.from(localSkipFiles),
247
- localFileChanges,
248
- modifiedFiles: {
249
- ...modifiedFiles,
250
- total:
251
- modifiedFiles.added.length +
252
- modifiedFiles.deleted.length +
253
- modifiedFiles.modified.length,
254
- },
255
- };
256
- }
@@ -1,13 +0,0 @@
1
- import { resolve } from "path";
2
- import { tmpdir } from "os";
3
-
4
- export const TEST_FIXTURES_DIR = resolve(
5
- __dirname,
6
- "..",
7
- "..",
8
- "test-fixtures",
9
- );
10
-
11
- export function tempDir(): string {
12
- return process.env.RUNNER_TEMP ?? tmpdir();
13
- }
package/src/types.ts DELETED
@@ -1,129 +0,0 @@
1
- /**
2
- * How we want to merge json
3
- *
4
- * overwrite - the template sync overwrites completely
5
- * merge-template - we merge template into the current json with overrides on matching values happening from the template
6
- * merge-current - we merge the current json into the template json with overrides on matching values happening from the current json
7
- */
8
- export type BaseJsonMergeOptions =
9
- | "overwrite"
10
- | "merge-template"
11
- | "merge-current";
12
- export interface JsonPathOverrides {
13
- /**
14
- * If set to true, this means we won't add new properties from the template
15
- */
16
- ignoreNewProperties?: boolean;
17
- /**
18
- * If set to true, overwrite will apply undefined values as deleted for the jsonpaths
19
- * or for values that are supposed to be merged on top of other values
20
- */
21
- missingIsDelete?: boolean;
22
- /**
23
- * Note, if multiple json paths match a rule, we pick the first one in the list that matches
24
- */
25
- paths: /**
26
- * We only override jsonpaths. Anything not specified is kept the same.
27
- */
28
- [jsonPath: `$.${string}`, options: BaseJsonMergeOptions][];
29
- }
30
- export type JsonFileMergeOptions = BaseJsonMergeOptions | JsonPathOverrides;
31
-
32
- // Sum of all basic file merge options
33
- type MergePluginOptions = JsonFileMergeOptions;
34
-
35
- /**
36
- * Configuration object for a given file type merge configuration
37
- */
38
- export interface MergeConfig<T> {
39
- /**
40
- * A glob or array of globs (using micromatch syntax) that selects the files that this applies to
41
- * when merging
42
- */
43
- glob: string | string[];
44
- /**
45
- * The node module, available on the calling node context, that you want to run.
46
- * Built-in plugins can be specified via their built-in name (see documentation):
47
- *
48
- * Example: _json
49
- */
50
- plugin: string;
51
- /**
52
- * An array of first match file globs that will then call the plugin with the appropriate options
53
- */
54
- options: MergePluginOptions | T;
55
- }
56
-
57
- /**
58
- * The shape of a template sync config file
59
- */
60
- export interface Config<T = unknown> {
61
- ignore: string[];
62
- /**
63
- * If there is no merge config, then we will always just overwrite the file for the diff
64
- */
65
- merge?: MergeConfig<T>[];
66
- }
67
-
68
- /**
69
- * The shape of a local template sync config file that overrides the root template repo
70
- */
71
- export interface LocalConfig<T = unknown> {
72
- /**
73
- * This is the ref that we compare against. If empty, we use all files that have changed since the
74
- * beginning of the template repo.
75
- */
76
- afterRef?: string;
77
-
78
- ignore: string[];
79
- /**
80
- * If there is no merge config, then we will always just overwrite the file for the diff
81
- */
82
- merge?: MergeConfig<T>[];
83
- }
84
-
85
- /**
86
- * Information around the file we are trying to merge and that arguments for that merge
87
- * from matching a merge configuration
88
- */
89
- export interface MergeContext<PluginOptions = unknown> {
90
- relFilePath: string;
91
- /**
92
- * If you have provided a custom merge plugin, this will be the "options" section of
93
- * the matching glob
94
- */
95
- mergeArguments: PluginOptions;
96
- /**
97
- * If this run is for the local config. Keep in mind that any local config overrides will
98
- * be run after the template sync options and we would like to report any changes that
99
- * are done
100
- */
101
- isLocalOptions?: boolean;
102
- }
103
-
104
- export interface MergePlugin<PluginOptions> {
105
- /**
106
- * This method will be called when a file from the template and it's analog in the downstream repo
107
- * have some differences. The plugin must perform the merge and return the appropriate file contents
108
- * as a string
109
- *
110
- * TODO: we may create a V2 plugin that could deal with large files and not pass around strings in memory,
111
- * but for now, this is the current implementation
112
- *
113
- * @param current - The downstream repos current file contents
114
- * @param fromTemplateRepo - the current
115
- * @param context - an object defining the context around the file and the specific options
116
- */
117
- merge(
118
- current: string,
119
- fromTemplateRepo: string,
120
- context: MergeContext<PluginOptions>,
121
- ): Promise<string>;
122
- /**
123
- * Given an options object for the merge, this validates the options object and returns error messages if there is anything wrong.
124
- * @param options any json value that the user provided - must be validated against the expected options
125
- */
126
- validate(options: unknown): string[] | undefined;
127
- }
128
-
129
- export type FileOperation = "added" | "modified" | "deleted";
@@ -1,15 +0,0 @@
1
- {
2
- "ignore": ["**/*.md"],
3
- "merge": {
4
- ".json": {
5
- "rules": [
6
- {
7
- "glob": "package.json",
8
- "options": {
9
- "paths": [["$.repository", "merge-template"]]
10
- }
11
- }
12
- ]
13
- }
14
- }
15
- }
@@ -1,3 +0,0 @@
1
- # My custom readme
2
-
3
- This is a custom readme for my file
@@ -1,18 +0,0 @@
1
- {
2
- "name": "mypkg",
3
- "description": "my description",
4
- "dependencies": {
5
- "mypackage": "^1.2.0",
6
- "newpacakge": "^22.2.2",
7
- "package2": "3.22.1",
8
- "huh": "^2.30.0"
9
- },
10
- "engines": {
11
- "node": ">=20"
12
- },
13
- "scripts": {
14
- "build": "build",
15
- "test": "jest",
16
- "myscript": "somescript"
17
- }
18
- }
@@ -1,11 +0,0 @@
1
- module.exports = {
2
- merge: () => {
3
- return JSON.stringify(
4
- {
5
- downstream: true,
6
- },
7
- null,
8
- 4,
9
- );
10
- },
11
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- console.log("This is my custom stuff");
@@ -1 +0,0 @@
1
- console.log("This is my custom stuff");
@@ -1,2 +0,0 @@
1
- "use strict";
2
- console.log("this is downstream stuff that should not change");
@@ -1 +0,0 @@
1
- console.log("this is downstream stuff that should not change");
@@ -1,16 +0,0 @@
1
- {
2
- "ignore": ["src/!(templated).ts", "custom-bin/**"],
3
- "merge": [
4
- {
5
- "glob": "package.json",
6
- "plugin": "_json",
7
- "options": {
8
- "paths": [
9
- ["$.dependencies", "merge-template"],
10
- ["$.devDependencies", "merge-template"],
11
- ["$.engines", "merge-template"]
12
- ]
13
- }
14
- }
15
- ]
16
- }
@@ -1,10 +0,0 @@
1
- {
2
- "ignore": ["custom-bin/**"],
3
- "merge": [
4
- {
5
- "glob": "package.json",
6
- "plugin": "plugins/custom-plugin.js",
7
- "options": {}
8
- }
9
- ]
10
- }
@@ -1,8 +0,0 @@
1
- module.exports = {
2
- merge: () => {
3
- return JSON.stringify({ tested: true }, null, 4);
4
- },
5
- validate: () => {
6
- return [];
7
- },
8
- };
@@ -1 +0,0 @@
1
- "use strict";
File without changes
File without changes
File without changes
@@ -1 +0,0 @@
1
- This is a file that is only meant for the base template maintainers
@@ -1,17 +0,0 @@
1
- {
2
- "name": "some-stub-name",
3
- "description": "some-stub-description",
4
- "dependencies": {
5
- "mypackage": "^1.2.0",
6
- "package2": "3.22.1",
7
- "huh": "~1.0.0"
8
- },
9
- "engines": {
10
- "node": ">=15"
11
- },
12
- "scripts": {
13
- "build": "build",
14
- "test": "fill this in yourself"
15
- },
16
- "version": "new-version"
17
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- console.log("replace this in the downstream");
@@ -1 +0,0 @@
1
- console.log("replace this in the downstream");
@@ -1,2 +0,0 @@
1
- "use strict";
2
- console.log("we changed this up and want to push the changes");
@@ -1 +0,0 @@
1
- console.log("we changed this up and want to push the changes");
@@ -1,16 +0,0 @@
1
- {
2
- "ignore": ["src/!(templated).ts", "custom-bin/**"],
3
- "merge": [
4
- {
5
- "glob": "package.json",
6
- "plugin": "_json",
7
- "options": {
8
- "paths": [
9
- ["$.dependencies", "merge-template"],
10
- ["$.devDependencies", "merge-template"],
11
- ["$.engines", "merge-template"]
12
- ]
13
- }
14
- }
15
- ]
16
- }
@@ -1,17 +0,0 @@
1
- # This is the master branch
2
-
3
- How to update this?
4
-
5
- You will want to "re-initialize this folder" by createing your .git repo
6
-
7
- ```shell
8
- mv gitDir .git
9
- ```
10
-
11
- From here, you can CD into the folder and run git commands. Anything you do will be recorded into the .git
12
-
13
- Before you commit those git history changes, please create the gitDir again from the new .git
14
-
15
- ```shell
16
- mv .git gitDir
17
- ```
@@ -1,14 +0,0 @@
1
- first commit
2
-
3
- # Please enter the commit message for your changes. Lines starting
4
- # with '#' will be ignored, and an empty message aborts the commit.
5
- #
6
- # Date: Sun Jun 9 13:06:24 2024 -0600
7
- #
8
- # On branch master
9
- #
10
- # Initial commit
11
- #
12
- # Changes to be committed:
13
- # new file: README.md
14
- #
@@ -1 +0,0 @@
1
- ref: refs/heads/master
@@ -1,7 +0,0 @@
1
- [core]
2
- repositoryformatversion = 0
3
- filemode = true
4
- bare = false
5
- logallrefupdates = true
6
- ignorecase = true
7
- precomposeunicode = true
@@ -1 +0,0 @@
1
- Unnamed repository; edit this file 'description' to name the repository.
@@ -1,15 +0,0 @@
1
- #!/bin/sh
2
- #
3
- # An example hook script to check the commit log message taken by
4
- # applypatch from an e-mail message.
5
- #
6
- # The hook should exit with non-zero status after issuing an
7
- # appropriate message if it wants to stop the commit. The hook is
8
- # allowed to edit the commit message file.
9
- #
10
- # To enable this hook, rename this file to "applypatch-msg".
11
-
12
- . git-sh-setup
13
- commitmsg="$(git rev-parse --git-path hooks/commit-msg)"
14
- test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"}
15
- :
@@ -1,24 +0,0 @@
1
- #!/bin/sh
2
- #
3
- # An example hook script to check the commit log message.
4
- # Called by "git commit" with one argument, the name of the file
5
- # that has the commit message. The hook should exit with non-zero
6
- # status after issuing an appropriate message if it wants to stop the
7
- # commit. The hook is allowed to edit the commit message file.
8
- #
9
- # To enable this hook, rename this file to "commit-msg".
10
-
11
- # Uncomment the below to add a Signed-off-by line to the message.
12
- # Doing this in a hook is a bad idea in general, but the prepare-commit-msg
13
- # hook is more suited to it.
14
- #
15
- # SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
16
- # grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
17
-
18
- # This example catches duplicate Signed-off-by lines.
19
-
20
- test "" = "$(grep '^Signed-off-by: ' "$1" |
21
- sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
22
- echo >&2 Duplicate Signed-off-by lines.
23
- exit 1
24
- }