@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,6 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type TextFile } from '../types/context.js';
3
+ export declare function insertFinalNewLine({ mergedTextFiles, transformedFiles }: {
4
+ mergedTextFiles: TextFile[];
5
+ transformedFiles?: TextFile[];
6
+ }): AsyncDResult;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.insertFinalNewLine = insertFinalNewLine;
4
- async function insertFinalNewLine({ mergedTextFiles }) {
4
+ const xtry_1 = require("@zokugun/xtry");
5
+ async function insertFinalNewLine({ mergedTextFiles, transformedFiles }) {
5
6
  for (const file of mergedTextFiles) {
6
7
  if (file.finalNewLine) {
7
8
  const withFinalNewLine = file.data.endsWith('\n');
@@ -10,4 +11,15 @@ async function insertFinalNewLine({ mergedTextFiles }) {
10
11
  }
11
12
  }
12
13
  }
14
+ if (transformedFiles) {
15
+ for (const file of transformedFiles) {
16
+ if (file.finalNewLine) {
17
+ const withFinalNewLine = file.data.endsWith('\n');
18
+ if (!withFinalNewLine) {
19
+ file.data = `${file.data}\n`;
20
+ }
21
+ }
22
+ }
23
+ }
24
+ return xtry_1.OK;
13
25
  }
@@ -0,0 +1,3 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type Context } from '../types/context.js';
3
+ export declare function mergeTextFiles({ targetPath, textFiles, mergedTextFiles, onExisting, onMissing, filters, routes, transforms, options }: Context): AsyncDResult;
@@ -5,94 +5,113 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.mergeTextFiles = mergeTextFiles;
7
7
  const path_1 = __importDefault(require("path"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const journeys_1 = require("../journeys");
10
- async function mergeTextFiles({ targetPath, textFiles, mergedTextFiles, onExisting, onMissing, filters, routes, options }) {
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");
11
+ const index_js_1 = require("../journeys/index.js");
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 mergeTextFiles({ targetPath, textFiles, mergedTextFiles, onExisting, onMissing, filters, routes, transforms, options }) {
11
15
  for (const file of textFiles) {
12
16
  if (options.verbose) {
13
- console.log(`${file.name} is going to be merged`);
17
+ cli_utils_1.logger.debug(`${file.name} is going to be merged`);
14
18
  }
15
- const journey = routes(file.name) ?? (0, journeys_1.getJourney)(file.name);
19
+ const journey = routes(file.name) ?? (0, index_js_1.getJourney)(file.name);
16
20
  if (!journey) {
17
21
  if (options.verbose) {
18
- console.log(`${file.name}, no merger has been found`);
22
+ cli_utils_1.logger.debug(`${file.name}, no merger has been found`);
19
23
  }
20
24
  const filePath = path_1.default.join(targetPath, file.name);
21
- const exists = await fs_extra_1.default.pathExists(filePath);
22
- if (exists) {
25
+ if (await async_1.default.isExisting(filePath)) {
23
26
  switch (onExisting(file.name)) {
24
- case 'merge':
27
+ case 'merge': {
25
28
  break;
26
- case 'overwrite':
29
+ }
30
+ case 'overwrite': {
27
31
  break;
28
- case 'skip':
32
+ }
33
+ case 'skip': {
29
34
  continue;
35
+ }
30
36
  }
31
37
  }
32
38
  else {
33
39
  switch (onMissing(file.name)) {
34
- case 'continue':
40
+ case 'continue': {
35
41
  break;
36
- case 'skip':
42
+ }
43
+ case 'skip': {
37
44
  continue;
45
+ }
38
46
  }
39
47
  }
40
48
  mergedTextFiles.push(file);
41
49
  if (options.verbose) {
42
- console.log(`${file.name} has been copied`);
50
+ cli_utils_1.logger.debug(`${file.name} has been copied`);
43
51
  }
44
52
  continue;
45
53
  }
46
54
  if (options.verbose) {
47
- console.log(`${file.name}, a merger has been found`);
55
+ cli_utils_1.logger.debug(`${file.name}, a merger has been found`);
48
56
  }
49
57
  const fileName = journey.alias ? path_1.default.join(path_1.default.dirname(file.name), journey.alias) : file.name;
50
58
  const filePath = path_1.default.join(targetPath, fileName);
51
- const exists = await fs_extra_1.default.pathExists(filePath);
52
- if (exists) {
59
+ if (await async_1.default.isExisting(filePath)) {
53
60
  switch (onExisting(file.name)) {
54
61
  case 'merge': {
55
- const currentData = await fs_extra_1.default.readFile(filePath, 'utf-8');
56
- const data = journey.travel({
57
- current: currentData,
62
+ const current = await async_1.default.readFile(filePath, 'utf8');
63
+ if (current.fails) {
64
+ return (0, xtry_1.err)((0, xtry_1.stringifyError)(current.error));
65
+ }
66
+ const finalNewLine = (0, has_final_new_line_js_1.hasFinalNewLine)(current.value);
67
+ const indent = (0, detect_indent_js_1.detectIndent)(current.value);
68
+ const data = await journey.travel({
69
+ current: current.value,
58
70
  incoming: file.data,
59
71
  filters: filters(file.name),
72
+ transforms: transforms(file.name),
60
73
  });
61
74
  mergedTextFiles.push({
62
75
  name: fileName,
63
76
  data,
64
- finalNewLine: file.finalNewLine,
77
+ finalNewLine,
78
+ indent,
65
79
  mode: file.mode,
66
80
  });
67
81
  if (options.verbose) {
68
- console.log(`${file.name} has been merged`);
82
+ cli_utils_1.logger.debug(`${file.name} has been merged`);
69
83
  }
70
84
  break;
71
85
  }
72
- case 'overwrite':
86
+ case 'overwrite': {
73
87
  mergedTextFiles.push(file);
74
88
  if (options.verbose) {
75
- console.log(`${file.name} has been overwritten`);
89
+ cli_utils_1.logger.debug(`${file.name} has been overwritten`);
76
90
  }
77
91
  continue;
78
- case 'skip':
92
+ }
93
+ case 'skip': {
79
94
  continue;
95
+ }
80
96
  }
81
97
  }
82
98
  else {
83
99
  switch (onMissing(file.name)) {
84
- case 'continue':
100
+ case 'continue': {
85
101
  mergedTextFiles.push({
86
102
  ...file,
87
103
  name: fileName,
88
104
  });
89
105
  if (options.verbose) {
90
- console.log(`${file.name} has been copied`);
106
+ cli_utils_1.logger.debug(`${file.name} has been copied`);
91
107
  }
92
108
  continue;
93
- case 'skip':
109
+ }
110
+ case 'skip': {
94
111
  continue;
112
+ }
95
113
  }
96
114
  }
97
115
  }
116
+ return xtry_1.OK;
98
117
  }
@@ -0,0 +1,3 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type Context } from '../types/context.js';
3
+ export declare function readEditorConfig({ incomingPath, targetPath, formats }: Context): AsyncDResult;
@@ -38,50 +38,44 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.readEditorConfig = readEditorConfig;
40
40
  const path_1 = __importDefault(require("path"));
41
+ const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
42
+ const xtry_1 = require("@zokugun/xtry");
41
43
  const editorconfig = __importStar(require("editorconfig"));
42
- const fs_extra_1 = __importDefault(require("fs-extra"));
43
- const format_1 = require("../types/format");
44
+ const format_js_1 = require("../types/format.js");
44
45
  function buildFullGlob(glob) {
45
46
  switch (glob.indexOf('/')) {
46
- case -1:
47
+ case -1: {
47
48
  glob = '**/' + glob;
48
49
  break;
49
- case 0:
50
+ }
51
+ case 0: {
50
52
  glob = glob.slice(1);
51
53
  break;
52
- default:
54
+ }
55
+ default: {
53
56
  break;
57
+ }
54
58
  }
55
- return glob.replace(/\*\*/g, '{*,**/**/**}');
59
+ return glob.replaceAll('**', '{*,**/**/**}');
56
60
  } // }}}
57
61
  async function readEditorConfig({ incomingPath, targetPath, formats }) {
58
- let data;
59
- try {
60
- const dir = path_1.default.join(incomingPath, 'configs');
61
- const file = path_1.default.join(dir, '.editorconfig');
62
- data = await fs_extra_1.default.readFile(file, 'utf-8');
63
- }
64
- catch {
65
- }
66
- if (!data) {
67
- try {
68
- const file = path_1.default.join(targetPath, '.editorconfig');
69
- data = await fs_extra_1.default.readFile(file, 'utf-8');
70
- }
71
- catch {
72
- }
62
+ const incomingFile = path_1.default.join(incomingPath, 'configs', '.editorconfig');
63
+ let readResult = await async_1.default.readFile(incomingFile, 'utf8');
64
+ if (readResult.fails) {
65
+ const targetFile = path_1.default.join(targetPath, '.editorconfig');
66
+ readResult = await async_1.default.readFile(targetFile, 'utf8');
73
67
  }
74
- if (!data) {
75
- return;
68
+ if (readResult.fails) {
69
+ return xtry_1.OK;
76
70
  }
77
- const rules = editorconfig.parseString(data);
71
+ const rules = editorconfig.parseString(readResult.value);
78
72
  for (const [glob, rule] of rules) {
79
73
  if (!glob) {
80
74
  continue;
81
75
  }
82
76
  const indentStyle = (rule.indent_style || 'space');
83
77
  const indentSize = (rule.indent_size && Number.parseInt(rule.indent_size, 10)) || 2;
84
- const insertFinalNewline = typeof rule.insert_final_newline === 'undefined' ? true : rule.insert_final_newline === 'true';
78
+ const insertFinalNewline = rule.insert_final_newline === undefined ? true : rule.insert_final_newline === 'true';
85
79
  formats.push({
86
80
  glob: buildFullGlob(glob),
87
81
  indentStyle,
@@ -91,9 +85,10 @@ async function readEditorConfig({ incomingPath, targetPath, formats }) {
91
85
  }
92
86
  formats.push({
93
87
  glob: buildFullGlob('{*.yml,*.yaml}'),
94
- indentStyle: format_1.IndentStyle.SPACE,
88
+ indentStyle: format_js_1.IndentStyle.SPACE,
95
89
  indentSize: 2,
96
90
  insertFinalNewline: true,
97
91
  });
98
92
  formats.reverse();
93
+ return xtry_1.OK;
99
94
  }
@@ -0,0 +1,3 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type Context } from '../types/context.js';
3
+ export declare function readFiles({ incomingPath, textFiles, binaryFiles, options }: Context): AsyncDResult;
@@ -5,10 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.readFiles = readFiles;
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
  const globby_1 = __importDefault(require("globby"));
10
12
  const istextorbinary_1 = require("istextorbinary");
11
- const read_buffer_1 = require("../utils/read-buffer");
13
+ const detect_indent_js_1 = require("../utils/detect-indent.js");
14
+ const has_final_new_line_js_1 = require("../utils/has-final-new-line.js");
15
+ const read_buffer_js_1 = require("../utils/read-buffer.js");
12
16
  async function readFiles({ incomingPath, textFiles, binaryFiles, options }) {
13
17
  const cwd = path_1.default.join(incomingPath, 'configs');
14
18
  const files = await (0, globby_1.default)(['**/*', '!**/*.lock', '!**/*-lock.*'], {
@@ -18,20 +22,30 @@ async function readFiles({ incomingPath, textFiles, binaryFiles, options }) {
18
22
  for (const file of files) {
19
23
  const filePath = path_1.default.join(cwd, file);
20
24
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call
21
- if ((0, istextorbinary_1.isText)(file) || (0, istextorbinary_1.getEncoding)(await (0, read_buffer_1.readBuffer)(filePath, 24)) === 'utf8') {
22
- const data = await fs_extra_1.default.readFile(filePath, 'utf-8');
23
- const finalNewLine = data.endsWith('\n');
25
+ if ((0, istextorbinary_1.isText)(file) || (0, istextorbinary_1.getEncoding)(await (0, read_buffer_js_1.readBuffer)(filePath, 24)) === 'utf8') {
26
+ const result = await async_1.default.readFile(filePath, 'utf8');
27
+ if (result.fails) {
28
+ return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
29
+ }
30
+ const data = result.value;
31
+ const finalNewLine = (0, has_final_new_line_js_1.hasFinalNewLine)(data);
32
+ const indent = (0, detect_indent_js_1.detectIndent)(data);
24
33
  if (data.startsWith('#!')) {
25
34
  // the text file might be executable
26
- const { mode } = await fs_extra_1.default.stat(filePath);
35
+ const result = await async_1.default.stat(filePath);
36
+ if (result.fails) {
37
+ return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
38
+ }
39
+ const { mode } = result.value;
27
40
  textFiles.push({
28
41
  name: file,
29
42
  data,
30
- mode,
31
43
  finalNewLine,
44
+ indent,
45
+ mode,
32
46
  });
33
47
  if (options.verbose) {
34
- console.log(`${file} is a shebang file`);
48
+ cli_utils_1.logger.debug(`${file} is a shebang file`);
35
49
  }
36
50
  }
37
51
  else {
@@ -39,9 +53,10 @@ async function readFiles({ incomingPath, textFiles, binaryFiles, options }) {
39
53
  name: file,
40
54
  data,
41
55
  finalNewLine,
56
+ indent,
42
57
  });
43
58
  if (options.verbose) {
44
- console.log(`${file} is a text file`);
59
+ cli_utils_1.logger.debug(`${file} is a text file`);
45
60
  }
46
61
  }
47
62
  }
@@ -51,8 +66,9 @@ async function readFiles({ incomingPath, textFiles, binaryFiles, options }) {
51
66
  target: file,
52
67
  });
53
68
  if (options.verbose) {
54
- console.log(`${file} is a binary file`);
69
+ cli_utils_1.logger.debug(`${file} is a binary file`);
55
70
  }
56
71
  }
57
72
  }
73
+ return xtry_1.OK;
58
74
  }
@@ -0,0 +1,3 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type Context } from '../types/context.js';
3
+ export declare function readIncomingConfig(context: Context): AsyncDResult<boolean | void>;
@@ -1,13 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.readIncomingConfig = readIncomingConfig;
4
- const configs_1 = require("../configs");
4
+ const xtry_1 = require("@zokugun/xtry");
5
+ const index_js_1 = require("../configs/index.js");
5
6
  async function readIncomingConfig(context) {
6
7
  if (!context.incomingConfig) {
7
- const config = await (0, configs_1.readPackageConfig)(context.incomingPath);
8
- if (!config) {
9
- return true;
8
+ const config = await (0, index_js_1.readPackageConfig)(context.incomingPath);
9
+ if (config.fails) {
10
+ return config;
10
11
  }
11
- context.incomingConfig = config;
12
+ context.incomingConfig = config.value;
12
13
  }
14
+ return xtry_1.OK;
13
15
  }
@@ -0,0 +1,3 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry/sync';
2
+ import { type Context } from '../types/context.js';
3
+ export declare function readIncomingPackage(context: Context): AsyncDResult;
@@ -5,18 +5,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.readIncomingPackage = readIncomingPackage;
7
7
  const path_1 = __importDefault(require("path"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const lodash_1 = require("lodash");
8
+ const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
9
+ const xtry_1 = require("@zokugun/xtry");
10
+ const lodash_es_1 = require("lodash-es");
10
11
  async function readIncomingPackage(context) {
11
12
  const filePath = path_1.default.resolve(context.incomingPath, './package.json');
12
- const incomingPackage = await fs_extra_1.default.readJSON(filePath);
13
- if (!isPackageManifest(incomingPackage)) {
14
- throw new Error('The package of the incoming artifact can\'t be found.');
13
+ const result = await async_1.default.readJSON(filePath);
14
+ if (result.fails) {
15
+ return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
15
16
  }
16
- context.incomingPackage = incomingPackage;
17
+ if (!isPackageManifest(result.value)) {
18
+ return (0, xtry_1.err)('The package of the incoming artifact can\'t be found.');
19
+ }
20
+ context.incomingPackage = result.value;
21
+ return xtry_1.OK;
17
22
  }
18
23
  function isPackageManifest(value) {
19
- if ((0, lodash_1.isNil)(value) || !(0, lodash_1.isPlainObject)(value)) {
24
+ if ((0, lodash_es_1.isNil)(value) || !(0, lodash_es_1.isPlainObject)(value)) {
20
25
  return false;
21
26
  }
22
27
  const manifest = value;
@@ -0,0 +1,3 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type Context } from '../types/context.js';
3
+ export declare function removeFiles({ removedPatterns, targetPath, options }: Context): AsyncDResult;
@@ -5,12 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.removeFiles = removeFiles;
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
  const globby_1 = __importDefault(require("globby"));
10
12
  const micromatch_1 = require("micromatch");
11
13
  async function removeFiles({ removedPatterns, targetPath, options }) {
12
14
  if (removedPatterns.length === 0) {
13
- return;
15
+ return xtry_1.OK;
14
16
  }
15
17
  const cwd = path_1.default.join(targetPath);
16
18
  const files = await (0, globby_1.default)(['**/*', '!**/*.lock', '!**/*-lock.*', '!.git'], {
@@ -21,11 +23,15 @@ async function removeFiles({ removedPatterns, targetPath, options }) {
21
23
  if ((0, micromatch_1.isMatch)(file, removedPatterns)) {
22
24
  if (!options.dryRun) {
23
25
  const filePath = path_1.default.join(cwd, file);
24
- await fs_extra_1.default.unlink(filePath);
26
+ const result = await async_1.default.unlink(filePath);
27
+ if (result.fails) {
28
+ return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
29
+ }
25
30
  }
26
31
  if (options.verbose) {
27
- console.log(`${file} has been removed`);
32
+ cli_utils_1.logger.debug(`${file} has been removed`);
28
33
  }
29
34
  }
30
35
  }
36
+ return xtry_1.OK;
31
37
  }
@@ -0,0 +1,3 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type Context } from '../types/context.js';
3
+ export declare function renameFiles({ renamedPatterns, targetPath }: Context): AsyncDResult;
@@ -0,0 +1,25 @@
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.renameFiles = renameFiles;
7
+ const path_1 = __importDefault(require("path"));
8
+ const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
9
+ const xtry_1 = require("@zokugun/xtry");
10
+ async function renameFiles({ renamedPatterns, targetPath }) {
11
+ if (renamedPatterns.length === 0) {
12
+ return xtry_1.OK;
13
+ }
14
+ const cwd = path_1.default.join(targetPath);
15
+ for (const { from, to } of renamedPatterns) {
16
+ const fromPath = path_1.default.join(cwd, from);
17
+ if (await async_1.default.isExisting(fromPath)) {
18
+ const result = await async_1.default.rename(fromPath, path_1.default.join(cwd, to));
19
+ if (result.fails) {
20
+ return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
21
+ }
22
+ }
23
+ }
24
+ return xtry_1.OK;
25
+ }
@@ -0,0 +1,3 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type Context } from '../types/context.js';
3
+ export declare function replaceTemplates({ textFiles, binaryFiles, targetPath, config, incomingConfig }: Context): AsyncDResult;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.replaceTemplates = replaceTemplates;
4
- const template_1 = require("../utils/template");
4
+ const xtry_1 = require("@zokugun/xtry");
5
+ const template_js_1 = require("../utils/template.js");
5
6
  async function replaceTemplates({ textFiles, binaryFiles, targetPath, config, incomingConfig }) {
6
7
  const variables = {
7
8
  ...incomingConfig?.variables,
@@ -9,12 +10,25 @@ async function replaceTemplates({ textFiles, binaryFiles, targetPath, config, in
9
10
  ...incomingConfig?.constants,
10
11
  ...config?.constants,
11
12
  };
12
- const engine = new template_1.TemplateEngine(targetPath, variables);
13
+ const engine = new template_js_1.TemplateEngine(targetPath, variables);
13
14
  for (const file of textFiles) {
14
- file.data = engine.render(file.data);
15
- file.name = engine.render(file.name);
15
+ const dataResult = engine.render(file.data);
16
+ if (dataResult.fails) {
17
+ return dataResult;
18
+ }
19
+ const nameResult = engine.render(file.name);
20
+ if (nameResult.fails) {
21
+ return nameResult;
22
+ }
23
+ file.data = dataResult.value;
24
+ file.name = nameResult.value;
16
25
  }
17
26
  for (const file of binaryFiles) {
18
- file.target = engine.render(file.target);
27
+ const targetResult = engine.render(file.target);
28
+ if (targetResult.fails) {
29
+ return targetResult;
30
+ }
31
+ file.target = targetResult.value;
19
32
  }
33
+ return xtry_1.OK;
20
34
  }
@@ -0,0 +1,3 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type Context } from '../types/context.js';
3
+ export declare function transformUntouchedFiles({ formats, options, routes, targetPath, textFiles, transformedFiles, transforms }: Context): AsyncDResult;
@@ -0,0 +1,64 @@
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.transformUntouchedFiles = transformUntouchedFiles;
7
+ const path_1 = __importDefault(require("path"));
8
+ const cli_utils_1 = require("@zokugun/cli-utils");
9
+ const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
10
+ const is_it_type_1 = require("@zokugun/is-it-type");
11
+ const xtry_1 = require("@zokugun/xtry");
12
+ const globby_1 = __importDefault(require("globby"));
13
+ const index_js_1 = require("../journeys/index.js");
14
+ const detect_indent_js_1 = require("../utils/detect-indent.js");
15
+ const has_final_new_line_js_1 = require("../utils/has-final-new-line.js");
16
+ async function transformUntouchedFiles({ formats, options, routes, targetPath, textFiles, transformedFiles, transforms }) {
17
+ if (transforms.length === 0) {
18
+ return xtry_1.OK;
19
+ }
20
+ const cwd = path_1.default.join(targetPath);
21
+ const files = await (0, globby_1.default)(['**/*', '!**/*.lock', '!**/*-lock.*'], {
22
+ cwd,
23
+ dot: true,
24
+ });
25
+ for (const file of files) {
26
+ if (textFiles.some(({ name }) => name === file)) {
27
+ continue;
28
+ }
29
+ const transformations = transforms(file);
30
+ if (!transformations || (0, is_it_type_1.isEmptyArray)(transformations)) {
31
+ continue;
32
+ }
33
+ const journey = routes(file) ?? (0, index_js_1.getJourney)(file);
34
+ if (!journey) {
35
+ continue;
36
+ }
37
+ if (options.verbose) {
38
+ cli_utils_1.logger.debug(`${file} is going to be transformed`);
39
+ }
40
+ const filePath = path_1.default.join(cwd, file);
41
+ const result = await async_1.default.readFile(filePath, 'utf8');
42
+ if (result.fails) {
43
+ return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
44
+ }
45
+ const data = result.value;
46
+ const finalNewLine = (0, has_final_new_line_js_1.hasFinalNewLine)(data);
47
+ const indent = (0, detect_indent_js_1.detectIndent)(data);
48
+ const transformed = await journey.travel({
49
+ current: data,
50
+ incoming: undefined,
51
+ transforms: transformations,
52
+ });
53
+ transformedFiles.push({
54
+ name: file,
55
+ data: transformed,
56
+ finalNewLine,
57
+ indent,
58
+ });
59
+ if (options.verbose) {
60
+ cli_utils_1.logger.debug(`${file} has been transformed`);
61
+ }
62
+ }
63
+ return xtry_1.OK;
64
+ }
@@ -0,0 +1,3 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type Context } from '../types/context.js';
3
+ export declare function unmergeTextFiles({ targetPath, textFiles, mergedTextFiles, options }: Context): AsyncDResult;