@zokugun/artifact 0.5.2 → 0.6.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 (217) hide show
  1. package/bin/artifact +1 -1
  2. package/lib/cli.d.ts +1 -0
  3. package/lib/cli.js +12 -4
  4. package/lib/commands/add.d.ts +6 -0
  5. package/lib/commands/add.js +47 -36
  6. package/lib/commands/index.d.ts +4 -0
  7. package/lib/commands/index.js +9 -7
  8. package/lib/commands/list.d.ts +1 -0
  9. package/lib/commands/list.js +13 -8
  10. package/lib/commands/remove.d.ts +6 -0
  11. package/lib/commands/remove.js +79 -0
  12. package/lib/commands/update.d.ts +5 -0
  13. package/lib/commands/update.js +43 -39
  14. package/lib/compositors/compose.d.ts +7 -0
  15. package/lib/compositors/compose.js +13 -13
  16. package/lib/compositors/fork.d.ts +3 -0
  17. package/lib/compositors/fork.js +4 -4
  18. package/lib/compositors/index.d.ts +6 -0
  19. package/lib/compositors/index.js +12 -12
  20. package/lib/compositors/json.d.ts +2 -0
  21. package/lib/compositors/json.js +14 -12
  22. package/lib/compositors/map-sort.d.ts +2 -0
  23. package/lib/compositors/map-sort.js +2 -2
  24. package/lib/compositors/rc.d.ts +2 -0
  25. package/lib/compositors/rc.js +13 -10
  26. package/lib/compositors/yaml.d.ts +2 -0
  27. package/lib/compositors/yaml.js +8 -11
  28. package/lib/configs/index.d.ts +3 -0
  29. package/lib/configs/index.js +3 -2
  30. package/lib/configs/install/index.d.ts +3 -0
  31. package/lib/configs/install/index.js +6 -6
  32. package/lib/configs/install/read-install-config.d.ts +6 -0
  33. package/lib/configs/install/read-install-config.js +128 -81
  34. package/lib/configs/install/update-install-config.d.ts +2 -0
  35. package/lib/configs/install/write-install-config.d.ts +5 -0
  36. package/lib/configs/install/write-install-config.js +25 -10
  37. package/lib/configs/package/index.d.ts +1 -0
  38. package/lib/configs/package/index.js +2 -2
  39. package/lib/configs/package/read-package-config.d.ts +3 -0
  40. package/lib/configs/package/read-package-config.js +160 -40
  41. package/lib/configs/uninstall/index.d.ts +1 -0
  42. package/lib/configs/uninstall/index.js +5 -0
  43. package/lib/configs/uninstall/update-uninstall-config.d.ts +2 -0
  44. package/lib/configs/uninstall/update-uninstall-config.js +6 -0
  45. package/lib/configs/utils/constants.d.ts +11 -0
  46. package/lib/configs/utils/constants.js +24 -0
  47. package/lib/configs/utils/is-transform.d.ts +2 -0
  48. package/lib/configs/utils/is-transform.js +16 -0
  49. package/lib/configs/utils/merge-upsert-property.d.ts +3 -0
  50. package/lib/configs/utils/merge-upsert-property.js +78 -0
  51. package/lib/configs/utils/normalize-file-always.d.ts +3 -0
  52. package/lib/configs/utils/normalize-file-always.js +29 -0
  53. package/lib/configs/utils/normalize-file-uninstall.d.ts +3 -0
  54. package/lib/configs/utils/normalize-file-uninstall.js +32 -0
  55. package/lib/configs/utils/normalize-file-upsert.d.ts +3 -0
  56. package/lib/configs/utils/normalize-file-upsert.js +55 -0
  57. package/lib/journeys/commitlint/index.d.ts +2 -0
  58. package/lib/journeys/commitlint/index.js +15 -15
  59. package/lib/journeys/config.ts/index.d.ts +2 -0
  60. package/lib/journeys/config.ts/index.js +5 -5
  61. package/lib/journeys/default/index.d.ts +2 -0
  62. package/lib/journeys/default/index.js +11 -14
  63. package/lib/journeys/fixpack/index.d.ts +2 -0
  64. package/lib/journeys/fixpack/index.js +13 -13
  65. package/lib/journeys/gitignore/index.d.ts +2 -0
  66. package/lib/journeys/gitignore/index.js +5 -5
  67. package/lib/journeys/ignore/index.d.ts +2 -0
  68. package/lib/journeys/ignore/index.js +5 -5
  69. package/lib/journeys/index.d.ts +2 -0
  70. package/lib/journeys/index.js +20 -20
  71. package/lib/journeys/npmignore/index.d.ts +2 -0
  72. package/lib/journeys/npmignore/index.js +5 -5
  73. package/lib/journeys/package/index.d.ts +2 -0
  74. package/lib/journeys/package/index.js +27 -30
  75. package/lib/journeys/rc/index.d.ts +2 -0
  76. package/lib/journeys/rc/index.js +12 -12
  77. package/lib/journeys/tsconfig/index.d.ts +2 -0
  78. package/lib/journeys/tsconfig/index.js +13 -16
  79. package/lib/parsers/json.d.ts +2 -0
  80. package/lib/parsers/jsonc/index.d.ts +2 -0
  81. package/lib/parsers/jsonc/index.js +4 -4
  82. package/lib/parsers/jsonc/parse.d.ts +5 -0
  83. package/lib/parsers/jsonc/parse.js +1 -13
  84. package/lib/parsers/jsonc/stringify.d.ts +2 -0
  85. package/lib/parsers/jsonc/stringify.js +2 -2
  86. package/lib/parsers/jsonc/transform.d.ts +10 -0
  87. package/lib/parsers/yaml.d.ts +2 -0
  88. package/lib/routes/command.d.ts +4 -0
  89. package/lib/routes/command.js +10 -10
  90. package/lib/routes/index.d.ts +8 -0
  91. package/lib/routes/index.js +17 -15
  92. package/lib/routes/lines-concat.d.ts +4 -0
  93. package/lib/routes/lines-concat.js +7 -7
  94. package/lib/routes/list-concat.d.ts +4 -0
  95. package/lib/routes/list-concat.js +3 -7
  96. package/lib/routes/list-sort-concat.d.ts +4 -0
  97. package/lib/routes/list-sort-concat.js +1 -1
  98. package/lib/routes/map-concat.d.ts +4 -0
  99. package/lib/routes/map-concat.js +1 -1
  100. package/lib/routes/map-delete.d.ts +4 -0
  101. package/lib/routes/map-delete.js +32 -0
  102. package/lib/routes/overwrite.d.ts +4 -0
  103. package/lib/routes/overwrite.js +2 -2
  104. package/lib/routes/primitive.d.ts +4 -0
  105. package/lib/routes/primitive.js +3 -3
  106. package/lib/steps/apply-formatting.d.ts +8 -0
  107. package/lib/steps/apply-formatting.js +50 -25
  108. package/lib/steps/configure-branches.d.ts +3 -0
  109. package/lib/steps/configure-branches.js +8 -5
  110. package/lib/steps/configure-install-file-actions.d.ts +3 -0
  111. package/lib/steps/configure-install-file-actions.js +59 -94
  112. package/lib/steps/configure-uninstall-file-actions.d.ts +3 -0
  113. package/lib/steps/configure-uninstall-file-actions.js +57 -0
  114. package/lib/steps/configure-update-file-actions.d.ts +3 -0
  115. package/lib/steps/configure-update-file-actions.js +65 -102
  116. package/lib/steps/copy-binary-files.d.ts +3 -0
  117. package/lib/steps/copy-binary-files.js +24 -11
  118. package/lib/steps/execute-first-block.d.ts +3 -0
  119. package/lib/steps/execute-first-block.js +35 -14
  120. package/lib/steps/execute-next-block.d.ts +3 -0
  121. package/lib/steps/execute-next-block.js +8 -3
  122. package/lib/steps/index.d.ts +54 -0
  123. package/lib/steps/index.js +76 -54
  124. package/lib/steps/insert-final-new-line.d.ts +6 -0
  125. package/lib/steps/insert-final-new-line.js +13 -1
  126. package/lib/steps/merge-text-files.d.ts +3 -0
  127. package/lib/steps/merge-text-files.js +47 -28
  128. package/lib/steps/read-editor-config.d.ts +3 -0
  129. package/lib/steps/read-editor-config.js +21 -26
  130. package/lib/steps/read-files.d.ts +3 -0
  131. package/lib/steps/read-files.js +26 -10
  132. package/lib/steps/read-incoming-config.d.ts +3 -0
  133. package/lib/steps/read-incoming-config.js +7 -5
  134. package/lib/steps/read-incoming-package.d.ts +3 -0
  135. package/lib/steps/read-incoming-package.js +12 -7
  136. package/lib/steps/remove-files.d.ts +3 -0
  137. package/lib/steps/remove-files.js +10 -4
  138. package/lib/steps/rename-files.d.ts +3 -0
  139. package/lib/steps/rename-files.js +25 -0
  140. package/lib/steps/replace-templates.d.ts +3 -0
  141. package/lib/steps/replace-templates.js +19 -5
  142. package/lib/steps/transform-untouched-files.d.ts +3 -0
  143. package/lib/steps/transform-untouched-files.js +64 -0
  144. package/lib/steps/unmerge-text-files.d.ts +3 -0
  145. package/lib/steps/unmerge-text-files.js +64 -0
  146. package/lib/steps/validate-newer-package.d.ts +3 -0
  147. package/lib/steps/validate-newer-package.js +4 -2
  148. package/lib/steps/validate-not-present-package.d.ts +3 -0
  149. package/lib/steps/validate-not-present-package.js +7 -4
  150. package/lib/steps/validate-present-package.d.ts +3 -0
  151. package/lib/steps/validate-present-package.js +24 -0
  152. package/lib/steps/write-text-files.d.ts +3 -0
  153. package/lib/steps/write-text-files.js +16 -7
  154. package/lib/types/binary-file.d.ts +4 -0
  155. package/lib/types/command.d.ts +5 -0
  156. package/lib/types/config.d.ts +59 -0
  157. package/lib/types/context.d.ts +62 -0
  158. package/lib/types/context.js +4 -0
  159. package/lib/types/format.d.ts +14 -0
  160. package/lib/types/step.d.ts +3 -0
  161. package/lib/types/travel.d.ts +14 -0
  162. package/lib/utils/apply-transforms.d.ts +2 -0
  163. package/lib/utils/apply-transforms.js +48 -0
  164. package/lib/utils/build-journey-plan.d.ts +2 -0
  165. package/lib/utils/build-route.d.ts +3 -0
  166. package/lib/utils/build-route.js +92 -0
  167. package/lib/utils/build-travel-plan.d.ts +2 -0
  168. package/lib/utils/build-travel.d.ts +3 -0
  169. package/lib/utils/build-travel.js +32 -0
  170. package/lib/utils/command/dedupe-strings.d.ts +1 -0
  171. package/lib/utils/command/index.d.ts +8 -0
  172. package/lib/utils/command/index.js +14 -14
  173. package/lib/utils/command/join-command.d.ts +2 -0
  174. package/lib/utils/command/merge-and-chains.d.ts +1 -0
  175. package/lib/utils/command/merge-and-chains.js +21 -21
  176. package/lib/utils/command/merge-command-records.d.ts +2 -0
  177. package/lib/utils/command/merge-command-records.js +43 -22
  178. package/lib/utils/command/merge-flag-tokens.d.ts +1 -0
  179. package/lib/utils/command/merge-flag-tokens.js +1 -1
  180. package/lib/utils/command/merge-flags-as-string.d.ts +4 -0
  181. package/lib/utils/command/merge-flags-as-string.js +4 -4
  182. package/lib/utils/command/merge-or-segments.d.ts +1 -0
  183. package/lib/utils/command/merge-or-segments.js +28 -28
  184. package/lib/utils/command/merge-parts-by-prefix.d.ts +1 -0
  185. package/lib/utils/command/merge-parts-by-prefix.js +6 -6
  186. package/lib/utils/command/merge-semicolon-segments.d.ts +1 -0
  187. package/lib/utils/command/merge-semicolon-segments.js +35 -35
  188. package/lib/utils/command/merge-with-semicolon-mix.d.ts +1 -0
  189. package/lib/utils/command/merge-with-semicolon-mix.js +12 -12
  190. package/lib/utils/command/prefix-of-command.d.ts +1 -0
  191. package/lib/utils/command/prefix-of-command.js +2 -2
  192. package/lib/utils/command/split-chain.d.ts +1 -0
  193. package/lib/utils/command/split-command.d.ts +2 -0
  194. package/lib/utils/command/split-command.js +8 -8
  195. package/lib/utils/command/split-prefix-and-flags.d.ts +4 -0
  196. package/lib/utils/command/split-prefix-and-flags.js +5 -5
  197. package/lib/utils/command/split-segments.d.ts +1 -0
  198. package/lib/utils/detect-indent.d.ts +2 -0
  199. package/lib/utils/detect-indent.js +63 -0
  200. package/lib/utils/flow.d.ts +3 -0
  201. package/lib/utils/flow.js +12 -0
  202. package/lib/utils/get-format.d.ts +2 -0
  203. package/lib/utils/get-format.js +19 -0
  204. package/lib/utils/has-final-new-line.d.ts +1 -0
  205. package/lib/utils/has-final-new-line.js +7 -0
  206. package/lib/utils/read-buffer.d.ts +2 -0
  207. package/lib/utils/resolve-request.d.ts +3 -0
  208. package/lib/utils/resolve-request.js +4 -3
  209. package/lib/utils/template.d.ts +17 -0
  210. package/lib/utils/template.js +79 -57
  211. package/lib/utils/to-lines.d.ts +1 -0
  212. package/lib/utils/trim-final-newline.d.ts +1 -0
  213. package/lib/utils/try-json.d.ts +1 -0
  214. package/lib/utils/try-json.js +2 -2
  215. package/package.json +74 -51
  216. package/lib/types/text-file.js +0 -2
  217. package/lib/utils/dev-null.js +0 -7
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapDelete = mapDelete;
4
+ const is_it_type_1 = require("@zokugun/is-it-type");
5
+ async function mapDelete({ current, incoming }) {
6
+ if (!incoming) {
7
+ return current ?? {};
8
+ }
9
+ if (!current) {
10
+ return {};
11
+ }
12
+ for (const [key, value] of Object.entries(incoming)) {
13
+ if ((0, is_it_type_1.isArray)(value) && (0, is_it_type_1.isArray)(current[key])) {
14
+ return current;
15
+ }
16
+ else if ((0, is_it_type_1.isRecord)(value) && (0, is_it_type_1.isRecord)(current[key])) {
17
+ const newValue = await mapDelete({ current: current[key], incoming: value });
18
+ if ((0, is_it_type_1.isEmptyRecord)(newValue)) {
19
+ delete current[key];
20
+ }
21
+ else {
22
+ current[key] = newValue;
23
+ }
24
+ }
25
+ else {
26
+ if (current[key] === value) {
27
+ delete current[key];
28
+ }
29
+ }
30
+ }
31
+ return current;
32
+ }
@@ -0,0 +1,4 @@
1
+ export declare function overwrite({ current, incoming }: {
2
+ current: unknown | undefined;
3
+ incoming: unknown | undefined;
4
+ }): Promise<unknown>;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.overwrite = overwrite;
4
- function overwrite({ current, incoming }) {
5
- if (typeof incoming === 'undefined') {
4
+ async function overwrite({ current, incoming }) {
5
+ if (incoming === undefined) {
6
6
  return current ?? [];
7
7
  }
8
8
  else {
@@ -0,0 +1,4 @@
1
+ export declare function primitive({ current, incoming }: {
2
+ current: unknown | undefined;
3
+ incoming: unknown | undefined;
4
+ }): Promise<unknown>;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.primitive = primitive;
4
- function primitive({ current, incoming }) {
5
- if (typeof incoming === 'undefined') {
4
+ async function primitive({ current, incoming }) {
5
+ if (incoming === undefined) {
6
6
  return current ?? [];
7
7
  }
8
- if (typeof current === 'undefined') {
8
+ if (current === undefined) {
9
9
  return incoming;
10
10
  }
11
11
  if (current === incoming) {
@@ -0,0 +1,8 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type TextFile } from '../types/context.js';
3
+ import { type Format } from '../types/format.js';
4
+ export declare function applyFormatting({ formats, mergedTextFiles, transformedFiles }: {
5
+ formats: Format[];
6
+ mergedTextFiles: TextFile[];
7
+ transformedFiles?: TextFile[];
8
+ }): AsyncDResult;
@@ -1,14 +1,12 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.applyFormatting = applyFormatting;
7
- const detect_indent_1 = __importDefault(require("detect-indent"));
8
- const fnmatch_1 = __importDefault(require("editorconfig/src/lib/fnmatch"));
9
- const format_1 = require("../types/format");
4
+ const xtry_1 = require("@zokugun/xtry");
5
+ const format_js_1 = require("../types/format.js");
6
+ const detect_indent_js_1 = require("../utils/detect-indent.js");
7
+ const get_format_js_1 = require("../utils/get-format.js");
10
8
  function applyFormat(file, format) {
11
- if (format.indentStyle === format_1.IndentStyle.SPACE) {
9
+ if (format.indentStyle === format_js_1.IndentStyle.SPACE) {
12
10
  file.data = indentWithSpace(file.data, format.indentSize);
13
11
  }
14
12
  else {
@@ -21,46 +19,73 @@ function applyFormat(file, format) {
21
19
  }
22
20
  }
23
21
  } // }}}
24
- function fnmatch(filepath, glob) {
25
- const matchOptions = { matchBase: true, dot: true, noext: true };
26
- return (0, fnmatch_1.default)(filepath, glob, matchOptions);
27
- } // }}}
28
22
  function indentWithSpace(data, size) {
29
- const { type, indent } = (0, detect_indent_1.default)(data);
30
- if (type === 'space') {
31
- if (indent.length === size) {
23
+ const indent = (0, detect_indent_js_1.detectIndent)(data);
24
+ if (!indent) {
25
+ return data;
26
+ }
27
+ else if (indent.style === format_js_1.IndentStyle.SPACE) {
28
+ if (indent.size === size) {
32
29
  return data;
33
30
  }
34
31
  else {
35
- data = data.replace(new RegExp(indent, 'gm'), '\t');
32
+ const oldIndent = ' '.repeat(indent.size);
36
33
  const newIndent = ' '.repeat(size);
37
- return data.replace(/\t/gm, newIndent);
34
+ const space2tab = new RegExp(`^(?:${oldIndent})+`, 'gm');
35
+ data = data.replaceAll(space2tab, (spaces) => '\t'.repeat(spaces.length / indent.size));
36
+ return data.replaceAll(/^\t+/gm, (tabs) => newIndent.repeat(tabs.length));
38
37
  }
39
38
  }
40
- else if (type === 'tab') {
39
+ else if (indent.style === format_js_1.IndentStyle.TAB) {
41
40
  const newIndent = ' '.repeat(size);
42
- return data.replace(new RegExp(indent, 'gm'), newIndent);
41
+ return data.replaceAll(/^\t+/gm, (tabs) => newIndent.repeat(tabs.length));
43
42
  }
44
43
  else {
45
44
  return data;
46
45
  }
47
46
  } // }}}
48
47
  function indentWithTab(data) {
49
- const { type, indent, amount } = (0, detect_indent_1.default)(data);
50
- if (type === 'space' && amount > 1) {
51
- return data.replace(new RegExp(indent, 'gm'), '\t');
48
+ const indent = (0, detect_indent_js_1.detectIndent)(data);
49
+ if (!indent) {
50
+ return data;
51
+ }
52
+ else if (indent.style === format_js_1.IndentStyle.SPACE) {
53
+ const oldIndent = ' '.repeat(indent.size);
54
+ const space2tab = new RegExp(`^(?:${oldIndent})+`, 'gm');
55
+ return data.replaceAll(space2tab, (spaces) => '\t'.repeat(spaces.length / indent.size));
52
56
  }
53
57
  else {
54
58
  return data;
55
59
  }
56
60
  } // }}}
57
- async function applyFormatting({ mergedTextFiles, formats }) {
61
+ async function applyFormatting({ formats, mergedTextFiles, transformedFiles }) {
58
62
  for (const file of mergedTextFiles) {
59
- for (const format of formats) {
60
- if (fnmatch(file.name, format.glob)) {
63
+ const format = (0, get_format_js_1.getFormat)(file.name, formats);
64
+ if (format) {
65
+ applyFormat(file, format);
66
+ }
67
+ else if (file.indent) {
68
+ applyFormat(file, {
69
+ indentStyle: file.indent.style,
70
+ indentSize: file.indent.size,
71
+ insertFinalNewline: file.finalNewLine,
72
+ });
73
+ }
74
+ }
75
+ if (transformedFiles) {
76
+ for (const file of transformedFiles) {
77
+ const format = (0, get_format_js_1.getFormat)(file.name, formats);
78
+ if (format) {
61
79
  applyFormat(file, format);
62
- break;
80
+ }
81
+ else if (file.indent) {
82
+ applyFormat(file, {
83
+ indentStyle: file.indent.style,
84
+ indentSize: file.indent.size,
85
+ insertFinalNewline: file.finalNewLine,
86
+ });
63
87
  }
64
88
  }
65
89
  }
90
+ return xtry_1.OK;
66
91
  }
@@ -0,0 +1,3 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type Context } from '../types/context.js';
3
+ export declare function configureBranches(context: Context): AsyncDResult;
@@ -5,11 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.configureBranches = configureBranches;
7
7
  const node_path_1 = __importDefault(require("node:path"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
8
+ const cli_utils_1 = require("@zokugun/cli-utils");
9
+ const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
10
+ const xtry_1 = require("@zokugun/xtry");
9
11
  const globby_1 = __importDefault(require("globby"));
10
12
  async function configureBranches(context) {
11
13
  const cwd = node_path_1.default.join(context.incomingPath, 'branches');
12
- if (await fs_extra_1.default.pathExists(cwd)) {
14
+ if (await async_1.default.isExisting(cwd)) {
13
15
  const directories = await (0, globby_1.default)('*', {
14
16
  cwd,
15
17
  onlyDirectories: true,
@@ -19,7 +21,7 @@ async function configureBranches(context) {
19
21
  const match = /^\[(@[\w-]+:[\w-]+|[\w-]+)(?::([\w-]+))?]$/.exec(directory);
20
22
  if (match) {
21
23
  const [branch, name, variant] = match;
22
- const packageName = name.replace(/:(artifact-)?/g, '/artifact-');
24
+ const packageName = name.replaceAll(/:(artifact-)?/g, '/artifact-');
23
25
  const artifact = context.config.artifacts[packageName];
24
26
  let found = false;
25
27
  if (artifact) {
@@ -44,7 +46,7 @@ async function configureBranches(context) {
44
46
  }
45
47
  if (found) {
46
48
  if (context.options.verbose) {
47
- console.log(`- branch: ${name}${variant ? `:${variant}` : ''} has been matched`);
49
+ cli_utils_1.logger.debug(`- branch: ${name}${variant ? `:${variant}` : ''} has been matched`);
48
50
  }
49
51
  bucket.push({
50
52
  name: context.incomingName,
@@ -56,11 +58,12 @@ async function configureBranches(context) {
56
58
  }
57
59
  else {
58
60
  if (context.options.verbose) {
59
- console.log(`- branch: ${name}${variant ? `:${variant}` : ''} hasn't been matched (${artifact ? 'variant' : 'artifact'} not found)`);
61
+ cli_utils_1.logger.debug(`- branch: ${name}${variant ? `:${variant}` : ''} hasn't been matched (${artifact ? 'variant' : 'artifact'} not found)`);
60
62
  }
61
63
  }
62
64
  }
63
65
  }
64
66
  context.blocks.unshift(...bucket);
65
67
  }
68
+ return xtry_1.OK;
66
69
  }
@@ -0,0 +1,3 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type Context } from '../types/context.js';
3
+ export declare function configureInstallFileActions(context: Context): AsyncDResult;
@@ -1,123 +1,77 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.configureInstallFileActions = configureInstallFileActions;
4
- const lodash_1 = require("lodash");
4
+ const is_it_type_1 = require("@zokugun/is-it-type");
5
+ const xtry_1 = require("@zokugun/xtry");
5
6
  const micromatch_1 = require("micromatch");
6
- const compositors_1 = require("../compositors");
7
- const routes_1 = require("../routes");
8
- function buildRoute(route) {
9
- if (Array.isArray(route) && route.length > 0) {
10
- let result = buildRoute(route[0]);
11
- for (let i = 1; i < route.length; i++) {
12
- if (route[i] === 'mapSort') {
13
- result = (0, compositors_1.mapSort)(result);
14
- }
15
- else {
16
- throw new Error('Can\'t build route');
17
- }
18
- }
19
- return result;
20
- }
21
- else if ((0, lodash_1.isPlainObject)(route)) {
22
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
23
- const { compose: rtCompose, fork: rtFork, mapSort: rtMapSort } = route;
24
- if (rtCompose) {
25
- const map = {};
26
- for (const [name, route] of Object.entries(rtCompose)) {
27
- map[name] = buildRoute(route);
28
- }
29
- return (0, compositors_1.compose)(map);
30
- }
31
- else if (rtFork) {
32
- const map = [];
33
- if (rtFork.array) {
34
- map.push([Array.isArray, buildRoute(rtFork.array)]);
35
- }
36
- if (rtFork.object) {
37
- map.push([lodash_1.isPlainObject, buildRoute(rtFork.object)]);
38
- }
39
- if (rtFork.default) {
40
- map.push(buildRoute(rtFork.default));
41
- }
42
- return (0, compositors_1.fork)(...map);
43
- }
44
- else if (rtMapSort) {
45
- return (0, compositors_1.mapSort)(buildRoute(rtMapSort));
46
- }
47
- }
48
- else if (route === 'command') {
49
- return routes_1.command;
50
- }
51
- else if (route === 'linesConcat') {
52
- return routes_1.linesConcat;
53
- }
54
- else if (route === 'listConcat') {
55
- return routes_1.listConcat;
56
- }
57
- else if (route === 'mapConcat') {
58
- return routes_1.mapConcat;
59
- }
60
- else if (route === 'overwrite') {
61
- return routes_1.overwrite;
62
- }
63
- else if (route === 'primitive') {
64
- return routes_1.primitive;
65
- }
66
- throw new Error('Can\'t build route');
67
- } // }}}
68
- function buildTravel(route) {
69
- if (route.json) {
70
- return (0, compositors_1.json)(buildRoute(route.json));
71
- }
72
- else if (route.rc) {
73
- return (0, compositors_1.rc)(buildRoute(route.rc));
74
- }
75
- else if (route.yaml) {
76
- return (0, compositors_1.yaml)(buildRoute(route.yaml));
77
- }
78
- else {
79
- throw new Error('Can\'t build route');
80
- }
81
- } // }}}
7
+ const build_travel_js_1 = require("../utils/build-travel.js");
82
8
  async function configureInstallFileActions(context) {
83
9
  const { install } = context.incomingConfig;
84
10
  if (!install) {
85
- return;
11
+ return xtry_1.OK;
86
12
  }
87
- const overwrites = [];
13
+ const existingActions = [];
88
14
  const filters = {};
89
15
  const routes = {};
90
- for (const [file, fileUpdate] of Object.entries(install)) {
91
- const { overwrite, remove, filter, route } = fileUpdate;
92
- if (remove) {
93
- context.removedPatterns.push(file);
16
+ const transformations = {};
17
+ for (const file of install) {
18
+ const { filter, ifExists, pattern, rename, route, transforms } = file;
19
+ if (rename) {
20
+ context.renamedPatterns.push({
21
+ from: pattern,
22
+ to: rename,
23
+ });
24
+ continue;
25
+ }
26
+ if (ifExists === 'force-merge') {
27
+ existingActions.push({ pattern, action: 'merge' });
28
+ }
29
+ else if (ifExists === 'overwrite') {
30
+ existingActions.push({ pattern, action: 'overwrite' });
31
+ }
32
+ else if (ifExists === 'remove') {
33
+ context.removedPatterns.push(pattern);
94
34
  continue;
95
35
  }
96
- if (overwrite) {
97
- overwrites.push(file);
36
+ else if (ifExists === 'skip') {
37
+ continue;
98
38
  }
99
39
  if (filter) {
100
- filters[file] = filter;
40
+ filters[pattern] = filter;
101
41
  }
102
42
  if (route) {
103
43
  const { alias } = route;
44
+ const travel = (0, build_travel_js_1.buildTravel)(route);
45
+ if (travel.fails) {
46
+ return travel;
47
+ }
104
48
  if (alias) {
105
- routes[file] = {
49
+ routes[pattern] = {
106
50
  alias,
107
- travel: buildTravel(route),
51
+ travel: travel.value,
108
52
  };
109
53
  }
110
54
  else {
111
- routes[file] = {
112
- travel: buildTravel(route),
55
+ routes[pattern] = {
56
+ travel: travel.value,
113
57
  };
114
58
  }
115
59
  }
60
+ if (transforms) {
61
+ transformations[pattern] = transforms;
62
+ }
116
63
  }
117
- if (overwrites.length > 0) {
118
- context.onExisting = (file) => (0, micromatch_1.isMatch)(file, overwrites) ? 'overwrite' : 'merge';
64
+ if (existingActions.length > 0) {
65
+ context.onExisting = (file) => {
66
+ for (const { pattern, action } of existingActions) {
67
+ if ((0, micromatch_1.isMatch)(file, pattern)) {
68
+ return action;
69
+ }
70
+ }
71
+ return 'merge';
72
+ };
119
73
  }
120
- if (!(0, lodash_1.isEmpty)(filters)) {
74
+ if ((0, is_it_type_1.isNonEmptyRecord)(filters)) {
121
75
  context.filters = (file) => {
122
76
  for (const [pattern, value] of Object.entries(filters)) {
123
77
  if ((0, micromatch_1.isMatch)(file, pattern)) {
@@ -127,7 +81,7 @@ async function configureInstallFileActions(context) {
127
81
  return undefined;
128
82
  };
129
83
  }
130
- if (!(0, lodash_1.isEmpty)(routes)) {
84
+ if ((0, is_it_type_1.isNonEmptyRecord)(routes)) {
131
85
  context.routes = (file) => {
132
86
  for (const [pattern, route] of Object.entries(routes)) {
133
87
  if ((0, micromatch_1.isMatch)(file, pattern)) {
@@ -137,4 +91,15 @@ async function configureInstallFileActions(context) {
137
91
  return undefined;
138
92
  };
139
93
  }
94
+ if ((0, is_it_type_1.isNonEmptyRecord)(transformations)) {
95
+ context.transforms = (file) => {
96
+ for (const [pattern, transforms] of Object.entries(transformations)) {
97
+ if ((0, micromatch_1.isMatch)(file, pattern)) {
98
+ return transforms;
99
+ }
100
+ }
101
+ return undefined;
102
+ };
103
+ }
104
+ return xtry_1.OK;
140
105
  }
@@ -0,0 +1,3 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type Context } from '../types/context.js';
3
+ export declare function configureUninstallFileActions(context: Context): AsyncDResult;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.configureUninstallFileActions = configureUninstallFileActions;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
9
+ const is_it_type_1 = require("@zokugun/is-it-type");
10
+ const xtry_1 = require("@zokugun/xtry");
11
+ const micromatch_1 = require("micromatch");
12
+ const detect_indent_js_1 = require("../utils/detect-indent.js");
13
+ const has_final_new_line_js_1 = require("../utils/has-final-new-line.js");
14
+ async function configureUninstallFileActions(context) {
15
+ const { uninstall } = context.incomingConfig;
16
+ if (!uninstall) {
17
+ return xtry_1.OK;
18
+ }
19
+ const cwd = node_path_1.default.join(context.incomingPath, 'configs');
20
+ const transformations = {};
21
+ for (const file of uninstall) {
22
+ const { ifExists, pattern, transforms } = file;
23
+ if (ifExists === 'remove') {
24
+ context.removedPatterns.push(pattern);
25
+ }
26
+ else if (ifExists === 'unmerge') {
27
+ const filePath = node_path_1.default.join(cwd, pattern);
28
+ const result = await async_1.default.readFile(filePath, 'utf8');
29
+ if (result.fails) {
30
+ return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
31
+ }
32
+ const data = result.value;
33
+ const finalNewLine = (0, has_final_new_line_js_1.hasFinalNewLine)(data);
34
+ const indent = (0, detect_indent_js_1.detectIndent)(data);
35
+ context.textFiles.push({
36
+ name: pattern,
37
+ data,
38
+ finalNewLine,
39
+ indent,
40
+ });
41
+ }
42
+ if (transforms) {
43
+ transformations[pattern] = transforms;
44
+ }
45
+ }
46
+ if ((0, is_it_type_1.isNonEmptyRecord)(transformations)) {
47
+ context.transforms = (file) => {
48
+ for (const [pattern, transforms] of Object.entries(transformations)) {
49
+ if ((0, micromatch_1.isMatch)(file, pattern)) {
50
+ return transforms;
51
+ }
52
+ }
53
+ return undefined;
54
+ };
55
+ }
56
+ return xtry_1.OK;
57
+ }
@@ -0,0 +1,3 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type Context } from '../types/context.js';
3
+ export declare function configureUpdateFileActions(context: Context): AsyncDResult;