@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
@@ -1,134 +1,86 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.configureUpdateFileActions = configureUpdateFileActions;
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 configureUpdateFileActions(context) {
83
9
  const { update } = context.incomingConfig;
84
- if (typeof update === 'boolean') {
85
- if (!update) {
86
- context.onExisting = () => 'skip';
87
- context.onMissing = () => 'skip';
88
- }
10
+ if (update === false) {
11
+ context.onExisting = () => 'skip';
12
+ context.onMissing = () => 'skip';
89
13
  }
90
- else if ((0, lodash_1.isPlainObject)(update)) {
91
- const overwriteExistings = [];
92
- const skipExistings = [];
14
+ else {
15
+ const existingActions = [];
93
16
  const skipMissings = [];
94
17
  const filters = {};
95
18
  const routes = {};
96
- for (const [file, fileUpdate] of Object.entries(update)) {
97
- const { missing, update, overwrite, filter, route } = fileUpdate;
98
- if (missing === false) {
99
- skipMissings.push(file);
19
+ const transformations = {};
20
+ for (const file of update) {
21
+ const { filter, ifExists, ifMissing, pattern, rename, route, transforms } = file;
22
+ if (rename) {
23
+ context.renamedPatterns.push({
24
+ from: pattern,
25
+ to: rename,
26
+ });
27
+ continue;
100
28
  }
101
- if (update === false) {
102
- skipExistings.push(file);
29
+ if (ifMissing === 'skip') {
30
+ skipMissings.push(pattern);
103
31
  }
104
- else if (overwrite) {
105
- overwriteExistings.push(file);
32
+ if (ifExists === 'force-merge') {
33
+ existingActions.push({ pattern, action: 'merge' });
34
+ }
35
+ else if (ifExists === 'overwrite') {
36
+ existingActions.push({ pattern, action: 'overwrite' });
37
+ }
38
+ else if (ifExists === 'remove') {
39
+ context.removedPatterns.push(pattern);
40
+ continue;
41
+ }
42
+ else if (ifExists === 'skip') {
43
+ existingActions.push({ pattern, action: 'skip' });
106
44
  }
107
45
  if (filter) {
108
- filters[file] = filter;
46
+ filters[pattern] = filter;
109
47
  }
110
48
  if (route) {
111
49
  const { alias } = route;
50
+ const travel = (0, build_travel_js_1.buildTravel)(route);
51
+ if (travel.fails) {
52
+ return travel;
53
+ }
112
54
  if (alias) {
113
- routes[file] = {
55
+ routes[pattern] = {
114
56
  alias,
115
- travel: buildTravel(route),
57
+ travel: travel.value,
116
58
  };
117
59
  }
118
60
  else {
119
- routes[file] = {
120
- travel: buildTravel(route),
61
+ routes[pattern] = {
62
+ travel: travel.value,
121
63
  };
122
64
  }
123
65
  }
66
+ if (transforms) {
67
+ transformations[pattern] = transforms;
68
+ }
124
69
  }
125
70
  if (skipMissings.length > 0) {
126
71
  context.onMissing = (file) => (0, micromatch_1.isMatch)(file, skipMissings) ? 'skip' : 'continue';
127
72
  }
128
- if (skipExistings.length > 0 || overwriteExistings.length > 0) {
129
- context.onExisting = (file) => (0, micromatch_1.isMatch)(file, skipExistings) ? 'skip' : ((0, micromatch_1.isMatch)(file, overwriteExistings) ? 'overwrite' : 'merge');
73
+ if (existingActions.length > 0) {
74
+ context.onExisting = (file) => {
75
+ for (const { pattern, action } of existingActions) {
76
+ if ((0, micromatch_1.isMatch)(file, pattern)) {
77
+ return action;
78
+ }
79
+ }
80
+ return 'merge';
81
+ };
130
82
  }
131
- if (!(0, lodash_1.isEmpty)(filters)) {
83
+ if ((0, is_it_type_1.isNonEmptyRecord)(filters)) {
132
84
  context.filters = (file) => {
133
85
  for (const [pattern, value] of Object.entries(filters)) {
134
86
  if ((0, micromatch_1.isMatch)(file, pattern)) {
@@ -138,7 +90,7 @@ async function configureUpdateFileActions(context) {
138
90
  return undefined;
139
91
  };
140
92
  }
141
- if (!(0, lodash_1.isEmpty)(routes)) {
93
+ if ((0, is_it_type_1.isNonEmptyRecord)(routes)) {
142
94
  context.routes = (file) => {
143
95
  for (const [pattern, route] of Object.entries(routes)) {
144
96
  if ((0, micromatch_1.isMatch)(file, pattern)) {
@@ -148,5 +100,16 @@ async function configureUpdateFileActions(context) {
148
100
  return undefined;
149
101
  };
150
102
  }
103
+ if ((0, is_it_type_1.isNonEmptyRecord)(transformations)) {
104
+ context.transforms = (file) => {
105
+ for (const [pattern, transforms] of Object.entries(transformations)) {
106
+ if ((0, micromatch_1.isMatch)(file, pattern)) {
107
+ return transforms;
108
+ }
109
+ }
110
+ return undefined;
111
+ };
112
+ }
151
113
  }
114
+ return xtry_1.OK;
152
115
  }
@@ -0,0 +1,3 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type Context } from '../types/context.js';
3
+ export declare function copyBinaryFiles({ binaryFiles, incomingPath, targetPath, onExisting, onMissing, options }: Context): AsyncDResult;
@@ -5,37 +5,50 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.copyBinaryFiles = copyBinaryFiles;
7
7
  const path_1 = __importDefault(require("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
  async function copyBinaryFiles({ binaryFiles, incomingPath, targetPath, onExisting, onMissing, options }) {
10
12
  const cwd = path_1.default.join(incomingPath, 'configs');
11
13
  for (const file of binaryFiles) {
12
14
  const source = path_1.default.join(cwd, file.source);
13
15
  const target = path_1.default.join(targetPath, file.target);
14
- const exists = await fs_extra_1.default.pathExists(target);
15
- if (exists) {
16
+ if (await async_1.default.isExisting(target)) {
16
17
  switch (onExisting(file.source)) {
17
- case 'merge':
18
+ case 'merge': {
18
19
  break;
19
- case 'overwrite':
20
+ }
21
+ case 'overwrite': {
20
22
  break;
21
- case 'skip':
23
+ }
24
+ case 'skip': {
22
25
  continue;
26
+ }
23
27
  }
24
28
  }
25
29
  else {
26
30
  switch (onMissing(file.source)) {
27
- case 'continue':
31
+ case 'continue': {
28
32
  break;
29
- case 'skip':
33
+ }
34
+ case 'skip': {
30
35
  continue;
36
+ }
31
37
  }
32
38
  }
33
39
  if (!options.dryRun) {
34
- await fs_extra_1.default.ensureFile(target);
35
- await fs_extra_1.default.copyFile(source, target);
40
+ const ensureResult = await async_1.default.ensureFile(target);
41
+ if (ensureResult.fails) {
42
+ return (0, xtry_1.err)((0, xtry_1.stringifyError)(ensureResult.error));
43
+ }
44
+ const copyResult = await async_1.default.copyFile(source, target);
45
+ if (copyResult.fails) {
46
+ return (0, xtry_1.err)((0, xtry_1.stringifyError)(copyResult.error));
47
+ }
36
48
  }
37
49
  if (options.verbose) {
38
- console.log(`${file.target} has been written as a binary file`);
50
+ cli_utils_1.logger.debug(`${file.target} has been written as a binary file`);
39
51
  }
40
52
  }
53
+ return xtry_1.OK;
41
54
  }
@@ -0,0 +1,3 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type Context } from '../types/context.js';
3
+ export declare function executeFirstBlock(context: Context): AsyncDResult<boolean | void>;
@@ -5,28 +5,36 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.executeFirstBlock = executeFirstBlock;
7
7
  const node_path_1 = __importDefault(require("node:path"));
8
- const lodash_1 = require("lodash");
9
- const configs_1 = require("../configs");
8
+ const xtry_1 = require("@zokugun/xtry");
9
+ const lodash_es_1 = require("lodash-es");
10
+ const index_js_1 = require("../configs/index.js");
10
11
  async function executeFirstBlock(context) {
11
12
  const { name, version } = context.incomingPackage;
12
13
  const root = String(context.incomingConfig.variants?.root ?? '');
13
14
  if (context.incomingVariant) {
14
15
  let variant;
15
16
  let alias;
16
- if ((0, lodash_1.isNil)(context.incomingConfig.variants[context.incomingVariant])) {
17
+ if ((0, lodash_es_1.isNil)(context.incomingConfig.variants[context.incomingVariant])) {
17
18
  variant = context.incomingVariant;
18
19
  alias = false;
19
20
  }
20
21
  else {
21
- variant = String(context.incomingConfig.variants[context.incomingVariant]);
22
+ variant = context.incomingConfig.variants[context.incomingVariant];
22
23
  alias = true;
23
24
  }
24
25
  const variantPath = node_path_1.default.join(context.packagePath, 'variants', variant);
25
- const variantConfig = await (0, configs_1.readPackageConfig)(variantPath);
26
+ const configResult = await (0, index_js_1.readPackageConfig)(variantPath);
27
+ if (configResult.fails) {
28
+ return configResult;
29
+ }
30
+ const variantConfig = configResult.value;
26
31
  if (variantConfig.orphan) {
27
32
  pushToResult(name, version, variant, alias, context);
28
33
  context.incomingConfig = variantConfig;
29
- await context.commonFlow(name, version, variant, undefined, variantPath, context);
34
+ const result = await context.commonFlow(name, version, variant, undefined, variantPath, context);
35
+ if (result.fails) {
36
+ return result;
37
+ }
30
38
  }
31
39
  else if (variantConfig.extends) {
32
40
  context.blocks.unshift({
@@ -36,21 +44,24 @@ async function executeFirstBlock(context) {
36
44
  incomingPath: node_path_1.default.join(context.packagePath, 'variants', variant),
37
45
  });
38
46
  pushToResult(name, version, variant, alias, context);
39
- const extend = String(context.incomingConfig.variants[variantConfig.extends] ?? variantConfig.extends);
47
+ const extend = context.incomingConfig.variants[variantConfig.extends] ?? variantConfig.extends;
40
48
  context.incomingVariant = extend;
41
49
  return executeFirstBlock(context);
42
50
  }
43
51
  else {
44
52
  if (root.length === 0) {
45
- throw new Error('No root variant has been defined');
53
+ return (0, xtry_1.err)('No root variant has been defined');
46
54
  }
47
55
  if (root === variant) {
48
56
  pushToResult(name, version, variant, alias, context);
49
57
  context.incomingConfig = variantConfig;
50
- await context.commonFlow(name, version, variant, undefined, variantPath, context);
58
+ const result = await context.commonFlow(name, version, variant, undefined, variantPath, context);
59
+ if (result.fails) {
60
+ return result;
61
+ }
51
62
  }
52
63
  else {
53
- const variant = String(context.incomingConfig.variants[context.request.variant] ?? context.request.variant);
64
+ const variant = context.incomingConfig.variants[context.request.variant] ?? context.request.variant;
54
65
  context.blocks.unshift({
55
66
  name,
56
67
  version,
@@ -60,7 +71,10 @@ async function executeFirstBlock(context) {
60
71
  pushToResult(name, version, variant, alias, context);
61
72
  const incomingPath = node_path_1.default.join(context.packagePath, 'variants', root);
62
73
  context.incomingConfig = undefined;
63
- await context.commonFlow(name, version, root, undefined, incomingPath, context);
74
+ const result = await context.commonFlow(name, version, root, undefined, incomingPath, context);
75
+ if (result.fails) {
76
+ return result;
77
+ }
64
78
  }
65
79
  }
66
80
  }
@@ -68,16 +82,23 @@ async function executeFirstBlock(context) {
68
82
  context.result = {
69
83
  name,
70
84
  version,
71
- provides: [root],
85
+ requires: [root],
72
86
  };
73
87
  const incomingPath = node_path_1.default.join(context.packagePath, 'variants', root);
74
88
  context.incomingConfig = undefined;
75
- await context.commonFlow(name, version, root, undefined, incomingPath, context);
89
+ const result = await context.commonFlow(name, version, root, undefined, incomingPath, context);
90
+ if (result.fails) {
91
+ return result;
92
+ }
76
93
  }
77
94
  else {
78
95
  context.result = { name, version };
79
- await context.commonFlow(name, version, undefined, undefined, context.incomingPath, context);
96
+ const result = await context.commonFlow(name, version, undefined, undefined, context.incomingPath, context);
97
+ if (result.fails) {
98
+ return result;
99
+ }
80
100
  }
101
+ return xtry_1.OK;
81
102
  }
82
103
  function pushToResult(name, version, variant, alias, context) {
83
104
  context.result ??= {
@@ -0,0 +1,3 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type Context } from '../types/context.js';
3
+ export declare function executeNextBlock(context: Context): AsyncDResult;
@@ -1,11 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.executeNextBlock = executeNextBlock;
4
- const lodash_1 = require("lodash");
4
+ const xtry_1 = require("@zokugun/xtry");
5
+ const lodash_es_1 = require("lodash-es");
5
6
  async function executeNextBlock(context) {
6
7
  const block = context.blocks.shift();
7
- if (!(0, lodash_1.isNil)(block)) {
8
+ if (!(0, lodash_es_1.isNil)(block)) {
8
9
  const { name, version, variant, branch, incomingPath } = block;
9
- await context.commonFlow(name, version, variant, branch, incomingPath, context);
10
+ const result = await context.commonFlow(name, version, variant, branch, incomingPath, context);
11
+ if (result.fails) {
12
+ return result;
13
+ }
10
14
  }
15
+ return xtry_1.OK;
11
16
  }
@@ -0,0 +1,54 @@
1
+ import { type CommonFlow, type MainFlow } from '../types/context.js';
2
+ import { type Step } from '../types/step.js';
3
+ import { applyFormatting } from './apply-formatting.js';
4
+ import { configureBranches } from './configure-branches.js';
5
+ import { configureInstallFileActions } from './configure-install-file-actions.js';
6
+ import { configureUninstallFileActions } from './configure-uninstall-file-actions.js';
7
+ import { configureUpdateFileActions } from './configure-update-file-actions.js';
8
+ import { copyBinaryFiles } from './copy-binary-files.js';
9
+ import { executeFirstBlock } from './execute-first-block.js';
10
+ import { executeNextBlock } from './execute-next-block.js';
11
+ import { insertFinalNewLine } from './insert-final-new-line.js';
12
+ import { mergeTextFiles } from './merge-text-files.js';
13
+ import { readEditorConfig } from './read-editor-config.js';
14
+ import { readFiles } from './read-files.js';
15
+ import { readIncomingConfig } from './read-incoming-config.js';
16
+ import { readIncomingPackage } from './read-incoming-package.js';
17
+ import { removeFiles } from './remove-files.js';
18
+ import { renameFiles } from './rename-files.js';
19
+ import { replaceTemplates } from './replace-templates.js';
20
+ import { transformUntouchedFiles } from './transform-untouched-files.js';
21
+ import { unmergeTextFiles } from './unmerge-text-files.js';
22
+ import { validateNewerPackage } from './validate-newer-package.js';
23
+ import { validateNotPresentPackage } from './validate-not-present-package.js';
24
+ import { validatePresentPackage } from './validate-present-package.js';
25
+ import { writeTextFiles } from './write-text-files.js';
26
+ export declare const steps: {
27
+ applyFormatting: typeof applyFormatting;
28
+ configureBranches: typeof configureBranches;
29
+ configureInstallFileActions: typeof configureInstallFileActions;
30
+ configureUninstallFileActions: typeof configureUninstallFileActions;
31
+ configureUpdateFileActions: typeof configureUpdateFileActions;
32
+ copyBinaryFiles: typeof copyBinaryFiles;
33
+ executeFirstBlock: typeof executeFirstBlock;
34
+ executeNextBlock: typeof executeNextBlock;
35
+ insertFinalNewLine: typeof insertFinalNewLine;
36
+ mergeTextFiles: typeof mergeTextFiles;
37
+ readEditorConfig: typeof readEditorConfig;
38
+ readFiles: typeof readFiles;
39
+ readIncomingConfig: typeof readIncomingConfig;
40
+ readIncomingPackage: typeof readIncomingPackage;
41
+ removeFiles: typeof removeFiles;
42
+ renameFiles: typeof renameFiles;
43
+ replaceTemplates: typeof replaceTemplates;
44
+ transformUntouchedFiles: typeof transformUntouchedFiles;
45
+ unmergeTextFiles: typeof unmergeTextFiles;
46
+ validateNewerPackage: typeof validateNewerPackage;
47
+ validateNotPresentPackage: typeof validateNotPresentPackage;
48
+ validatePresentPackage: typeof validatePresentPackage;
49
+ writeTextFiles: typeof writeTextFiles;
50
+ };
51
+ export declare function composeSteps(validations: Step[], processes: Step[]): {
52
+ mainFlow: MainFlow;
53
+ commonFlow: CommonFlow;
54
+ };
@@ -2,75 +2,93 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.steps = void 0;
4
4
  exports.composeSteps = composeSteps;
5
- const ansi_colors_1 = require("ansi-colors");
6
- const apply_formatting_1 = require("./apply-formatting");
7
- const configure_branches_1 = require("./configure-branches");
8
- const configure_install_file_actions_1 = require("./configure-install-file-actions");
9
- const configure_update_file_actions_1 = require("./configure-update-file-actions");
10
- const copy_binary_files_1 = require("./copy-binary-files");
11
- const execute_first_block_1 = require("./execute-first-block");
12
- const execute_next_block_1 = require("./execute-next-block");
13
- const insert_final_new_line_1 = require("./insert-final-new-line");
14
- const merge_text_files_1 = require("./merge-text-files");
15
- const read_editor_config_1 = require("./read-editor-config");
16
- const read_files_1 = require("./read-files");
17
- const read_incoming_config_1 = require("./read-incoming-config");
18
- const read_incoming_package_1 = require("./read-incoming-package");
19
- const remove_files_1 = require("./remove-files");
20
- const replace_templates_1 = require("./replace-templates");
21
- const validate_newer_package_1 = require("./validate-newer-package");
22
- const validate_not_present_package_1 = require("./validate-not-present-package");
23
- const write_text_files_1 = require("./write-text-files");
5
+ const cli_utils_1 = require("@zokugun/cli-utils");
6
+ const xtry_1 = require("@zokugun/xtry");
7
+ const apply_formatting_js_1 = require("./apply-formatting.js");
8
+ const configure_branches_js_1 = require("./configure-branches.js");
9
+ const configure_install_file_actions_js_1 = require("./configure-install-file-actions.js");
10
+ const configure_uninstall_file_actions_js_1 = require("./configure-uninstall-file-actions.js");
11
+ const configure_update_file_actions_js_1 = require("./configure-update-file-actions.js");
12
+ const copy_binary_files_js_1 = require("./copy-binary-files.js");
13
+ const execute_first_block_js_1 = require("./execute-first-block.js");
14
+ const execute_next_block_js_1 = require("./execute-next-block.js");
15
+ const insert_final_new_line_js_1 = require("./insert-final-new-line.js");
16
+ const merge_text_files_js_1 = require("./merge-text-files.js");
17
+ const read_editor_config_js_1 = require("./read-editor-config.js");
18
+ const read_files_js_1 = require("./read-files.js");
19
+ const read_incoming_config_js_1 = require("./read-incoming-config.js");
20
+ const read_incoming_package_js_1 = require("./read-incoming-package.js");
21
+ const remove_files_js_1 = require("./remove-files.js");
22
+ const rename_files_js_1 = require("./rename-files.js");
23
+ const replace_templates_js_1 = require("./replace-templates.js");
24
+ const transform_untouched_files_js_1 = require("./transform-untouched-files.js");
25
+ const unmerge_text_files_js_1 = require("./unmerge-text-files.js");
26
+ const validate_newer_package_js_1 = require("./validate-newer-package.js");
27
+ const validate_not_present_package_js_1 = require("./validate-not-present-package.js");
28
+ const validate_present_package_js_1 = require("./validate-present-package.js");
29
+ const write_text_files_js_1 = require("./write-text-files.js");
24
30
  exports.steps = {
25
- applyFormatting: apply_formatting_1.applyFormatting,
26
- configureBranches: configure_branches_1.configureBranches,
27
- configureInstallFileActions: configure_install_file_actions_1.configureInstallFileActions,
28
- configureUpdateFileActions: configure_update_file_actions_1.configureUpdateFileActions,
29
- copyBinaryFiles: copy_binary_files_1.copyBinaryFiles,
30
- executeFirstBlock: execute_first_block_1.executeFirstBlock,
31
- executeNextBlock: execute_next_block_1.executeNextBlock,
32
- insertFinalNewLine: insert_final_new_line_1.insertFinalNewLine,
33
- mergeTextFiles: merge_text_files_1.mergeTextFiles,
34
- readEditorConfig: read_editor_config_1.readEditorConfig,
35
- readFiles: read_files_1.readFiles,
36
- readIncomingConfig: read_incoming_config_1.readIncomingConfig,
37
- readIncomingPackage: read_incoming_package_1.readIncomingPackage,
38
- removeFiles: remove_files_1.removeFiles,
39
- replaceTemplates: replace_templates_1.replaceTemplates,
40
- validateNewerPackage: validate_newer_package_1.validateNewerPackage,
41
- validateNotPresentPackage: validate_not_present_package_1.validateNotPresentPackage,
42
- writeTextFiles: write_text_files_1.writeTextFiles,
31
+ applyFormatting: apply_formatting_js_1.applyFormatting,
32
+ configureBranches: configure_branches_js_1.configureBranches,
33
+ configureInstallFileActions: configure_install_file_actions_js_1.configureInstallFileActions,
34
+ configureUninstallFileActions: configure_uninstall_file_actions_js_1.configureUninstallFileActions,
35
+ configureUpdateFileActions: configure_update_file_actions_js_1.configureUpdateFileActions,
36
+ copyBinaryFiles: copy_binary_files_js_1.copyBinaryFiles,
37
+ executeFirstBlock: execute_first_block_js_1.executeFirstBlock,
38
+ executeNextBlock: execute_next_block_js_1.executeNextBlock,
39
+ insertFinalNewLine: insert_final_new_line_js_1.insertFinalNewLine,
40
+ mergeTextFiles: merge_text_files_js_1.mergeTextFiles,
41
+ readEditorConfig: read_editor_config_js_1.readEditorConfig,
42
+ readFiles: read_files_js_1.readFiles,
43
+ readIncomingConfig: read_incoming_config_js_1.readIncomingConfig,
44
+ readIncomingPackage: read_incoming_package_js_1.readIncomingPackage,
45
+ removeFiles: remove_files_js_1.removeFiles,
46
+ renameFiles: rename_files_js_1.renameFiles,
47
+ replaceTemplates: replace_templates_js_1.replaceTemplates,
48
+ transformUntouchedFiles: transform_untouched_files_js_1.transformUntouchedFiles,
49
+ unmergeTextFiles: unmerge_text_files_js_1.unmergeTextFiles,
50
+ validateNewerPackage: validate_newer_package_js_1.validateNewerPackage,
51
+ validateNotPresentPackage: validate_not_present_package_js_1.validateNotPresentPackage,
52
+ validatePresentPackage: validate_present_package_js_1.validatePresentPackage,
53
+ writeTextFiles: write_text_files_js_1.writeTextFiles,
43
54
  };
44
55
  function composeSteps(validations, processes) {
45
56
  const mainFlow = async (targetPath, incomingPath, request, config, options) => {
46
57
  const context = {
47
- packagePath: incomingPath,
48
- request,
49
- targetPath,
58
+ binaryFiles: [],
59
+ blocks: [],
60
+ commonFlow,
61
+ config,
62
+ filters: () => undefined,
63
+ formats: [],
50
64
  incomingPath,
51
65
  incomingVariant: request.variant,
66
+ mergedTextFiles: [],
52
67
  onExisting: () => 'merge',
53
68
  onMissing: () => 'continue',
54
- filters: () => undefined,
69
+ options,
70
+ packagePath: incomingPath,
71
+ removedPatterns: [],
72
+ renamedPatterns: [],
73
+ request,
55
74
  routes: () => undefined,
56
- binaryFiles: [],
75
+ targetPath,
57
76
  textFiles: [],
58
- mergedTextFiles: [],
59
- removedPatterns: [],
60
- formats: [],
61
- config,
62
- options,
63
- commonFlow,
64
- blocks: [],
77
+ transformedFiles: [],
78
+ transforms: () => undefined,
65
79
  };
66
80
  let skipped = false;
67
81
  for (const step of validations) {
68
- if (await step(context)) {
82
+ const result = await step(context);
83
+ if (result.fails) {
84
+ return result;
85
+ }
86
+ if (result.value) {
69
87
  skipped = true;
70
88
  break;
71
89
  }
72
90
  }
73
- return skipped ? undefined : context;
91
+ return skipped ? xtry_1.OK_UNDEFINED : (0, xtry_1.ok)(context);
74
92
  };
75
93
  const commonFlow = async (name, version, variant, branch, incomingPath, mainContext) => {
76
94
  if (mainContext.options.verbose) {
@@ -81,7 +99,7 @@ function composeSteps(validations, processes) {
81
99
  if (branch) {
82
100
  message += ` branch=${branch}`;
83
101
  }
84
- console.log((0, ansi_colors_1.bgBlue)(`\n=== ${message} ===\n`));
102
+ cli_utils_1.logger.print(cli_utils_1.c.bgBlue(`\n=== ${message} ===\n`));
85
103
  }
86
104
  const context = {
87
105
  ...mainContext,
@@ -102,12 +120,16 @@ function composeSteps(validations, processes) {
102
120
  };
103
121
  let skipped = false;
104
122
  for (const step of processes) {
105
- if (await step(context)) {
123
+ const result = await step(context);
124
+ if (result.fails) {
125
+ return result;
126
+ }
127
+ if (result.value) {
106
128
  skipped = true;
107
129
  break;
108
130
  }
109
131
  }
110
- return skipped ? undefined : context;
132
+ return skipped ? xtry_1.OK_UNDEFINED : (0, xtry_1.ok)(context);
111
133
  };
112
134
  return { mainFlow, commonFlow };
113
135
  }