@zokugun/artifact 0.5.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) 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 +123 -80
  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 +17 -9
  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 +159 -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 +68 -0
  51. package/lib/configs/utils/normalize-file-always.d.ts +3 -0
  52. package/lib/configs/utils/normalize-file-always.js +28 -0
  53. package/lib/configs/utils/normalize-file-uninstall.d.ts +3 -0
  54. package/lib/configs/utils/normalize-file-uninstall.js +31 -0
  55. package/lib/configs/utils/normalize-file-upsert.d.ts +3 -0
  56. package/lib/configs/utils/normalize-file-upsert.js +54 -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 +19 -15
  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 +41 -86
  112. package/lib/steps/configure-uninstall-file-actions.d.ts +3 -0
  113. package/lib/steps/configure-uninstall-file-actions.js +53 -0
  114. package/lib/steps/configure-update-file-actions.d.ts +3 -0
  115. package/lib/steps/configure-update-file-actions.js +64 -97
  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 +41 -27
  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 +19 -8
  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 +73 -0
  144. package/lib/steps/unmerge-text-files.d.ts +3 -0
  145. package/lib/steps/unmerge-text-files.js +63 -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 +58 -0
  157. package/lib/types/context.d.ts +56 -0
  158. package/lib/types/format.d.ts +10 -0
  159. package/lib/types/step.d.ts +3 -0
  160. package/lib/types/text-file.d.ts +7 -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 +5 -0
  199. package/lib/utils/detect-indent.js +60 -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 +123 -101
  216. package/lib/utils/dev-null.js +0 -7
@@ -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,12 @@ 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 read_buffer_js_1 = require("../utils/read-buffer.js");
12
14
  async function readFiles({ incomingPath, textFiles, binaryFiles, options }) {
13
15
  const cwd = path_1.default.join(incomingPath, 'configs');
14
16
  const files = await (0, globby_1.default)(['**/*', '!**/*.lock', '!**/*-lock.*'], {
@@ -18,12 +20,20 @@ async function readFiles({ incomingPath, textFiles, binaryFiles, options }) {
18
20
  for (const file of files) {
19
21
  const filePath = path_1.default.join(cwd, file);
20
22
  // 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
+ if ((0, istextorbinary_1.isText)(file) || (0, istextorbinary_1.getEncoding)(await (0, read_buffer_js_1.readBuffer)(filePath, 24)) === 'utf8') {
24
+ const result = await async_1.default.readFile(filePath, 'utf8');
25
+ if (result.fails) {
26
+ return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
27
+ }
28
+ const data = result.value;
23
29
  const finalNewLine = data.endsWith('\n');
24
30
  if (data.startsWith('#!')) {
25
31
  // the text file might be executable
26
- const { mode } = await fs_extra_1.default.stat(filePath);
32
+ const result = await async_1.default.stat(filePath);
33
+ if (result.fails) {
34
+ return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
35
+ }
36
+ const { mode } = result.value;
27
37
  textFiles.push({
28
38
  name: file,
29
39
  data,
@@ -31,7 +41,7 @@ async function readFiles({ incomingPath, textFiles, binaryFiles, options }) {
31
41
  finalNewLine,
32
42
  });
33
43
  if (options.verbose) {
34
- console.log(`${file} is a shebang file`);
44
+ cli_utils_1.logger.debug(`${file} is a shebang file`);
35
45
  }
36
46
  }
37
47
  else {
@@ -41,7 +51,7 @@ async function readFiles({ incomingPath, textFiles, binaryFiles, options }) {
41
51
  finalNewLine,
42
52
  });
43
53
  if (options.verbose) {
44
- console.log(`${file} is a text file`);
54
+ cli_utils_1.logger.debug(`${file} is a text file`);
45
55
  }
46
56
  }
47
57
  }
@@ -51,8 +61,9 @@ async function readFiles({ incomingPath, textFiles, binaryFiles, options }) {
51
61
  target: file,
52
62
  });
53
63
  if (options.verbose) {
54
- console.log(`${file} is a binary file`);
64
+ cli_utils_1.logger.debug(`${file} is a binary file`);
55
65
  }
56
66
  }
57
67
  }
68
+ return xtry_1.OK;
58
69
  }
@@ -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,73 @@
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 get_format_js_1 = require("../utils/get-format.js");
16
+ const has_final_new_line_js_1 = require("../utils/has-final-new-line.js");
17
+ async function transformUntouchedFiles({ formats, options, routes, targetPath, textFiles, transformedFiles, transforms }) {
18
+ if (transforms.length === 0) {
19
+ return xtry_1.OK;
20
+ }
21
+ const cwd = path_1.default.join(targetPath);
22
+ const files = await (0, globby_1.default)(['**/*', '!**/*.lock', '!**/*-lock.*'], {
23
+ cwd,
24
+ dot: true,
25
+ });
26
+ for (const file of files) {
27
+ if (textFiles.some(({ name }) => name === file)) {
28
+ continue;
29
+ }
30
+ const transformations = transforms(file);
31
+ if (!transformations || (0, is_it_type_1.isEmptyArray)(transformations)) {
32
+ continue;
33
+ }
34
+ const journey = routes(file) ?? (0, index_js_1.getJourney)(file);
35
+ if (!journey) {
36
+ continue;
37
+ }
38
+ if (options.verbose) {
39
+ cli_utils_1.logger.debug(`${file} is going to be transformed`);
40
+ }
41
+ const filePath = path_1.default.join(cwd, file);
42
+ const result = await async_1.default.readFile(filePath, 'utf8');
43
+ if (result.fails) {
44
+ return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
45
+ }
46
+ const data = result.value;
47
+ const finalNewLine = data.endsWith('\n');
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: finalNewLine,
57
+ });
58
+ if (options.verbose) {
59
+ cli_utils_1.logger.debug(`${file} has been transformed`);
60
+ }
61
+ const format = (0, get_format_js_1.getFormat)(file, formats);
62
+ if (!format) {
63
+ const indent = (0, detect_indent_js_1.detectIndent)(data);
64
+ formats.push({
65
+ glob: file,
66
+ indentStyle: indent.style,
67
+ indentSize: indent.size,
68
+ insertFinalNewline: (0, has_final_new_line_js_1.hasFinalNewLine)(data),
69
+ });
70
+ }
71
+ }
72
+ return xtry_1.OK;
73
+ }
@@ -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;
@@ -0,0 +1,63 @@
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.unmergeTextFiles = unmergeTextFiles;
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 compose_js_1 = require("../compositors/compose.js");
13
+ const fork_js_1 = require("../compositors/fork.js");
14
+ const json_js_1 = require("../compositors/json.js");
15
+ const yaml_js_1 = require("../compositors/yaml.js");
16
+ const index_js_1 = require("../routes/index.js");
17
+ const build_travel_plan_js_1 = require("../utils/build-travel-plan.js");
18
+ const mainRoute = (0, compose_js_1.compose)({
19
+ $$default: (0, fork_js_1.fork)([is_it_type_1.isArray, async ({ current }) => current], [is_it_type_1.isRecord, index_js_1.mapDelete], async ({ current }) => current),
20
+ });
21
+ const jsonRoute = (0, json_js_1.json)(mainRoute);
22
+ const yamlRoute = (0, yaml_js_1.yaml)(mainRoute);
23
+ const travelPlan = (0, build_travel_plan_js_1.buildTravelPlan)([/\.json$/, jsonRoute], [/\.ya?ml$/, yamlRoute]);
24
+ async function unmergeTextFiles({ targetPath, textFiles, mergedTextFiles, options }) {
25
+ for (const file of textFiles) {
26
+ if (options.verbose) {
27
+ cli_utils_1.logger.debug(`${file.name} is going to be unmerged`);
28
+ }
29
+ const filePath = path_1.default.join(targetPath, file.name);
30
+ if (!await async_1.default.isExisting(filePath)) {
31
+ continue;
32
+ }
33
+ const current = await async_1.default.readFile(filePath, 'utf8');
34
+ if (current.fails) {
35
+ return (0, xtry_1.err)((0, xtry_1.stringifyError)(current.error));
36
+ }
37
+ const travel = travelPlan(file.name);
38
+ if (travel) {
39
+ if (options.verbose) {
40
+ cli_utils_1.logger.debug(`${file.name}, an unmerger has been found`);
41
+ }
42
+ const data = await travel({
43
+ current: current.value,
44
+ incoming: file.data,
45
+ });
46
+ mergedTextFiles.push({
47
+ name: file.name,
48
+ data,
49
+ finalNewLine: file.finalNewLine,
50
+ mode: file.mode,
51
+ });
52
+ if (options.verbose) {
53
+ cli_utils_1.logger.debug(`${file.name} has been unmerged`);
54
+ }
55
+ }
56
+ else {
57
+ if (options.verbose) {
58
+ cli_utils_1.logger.debug(`${file.name}, no unmerger has been found`);
59
+ }
60
+ }
61
+ }
62
+ return xtry_1.OK;
63
+ }
@@ -0,0 +1,3 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type Context } from '../types/context.js';
3
+ export declare function validateNewerPackage({ incomingPackage, config, options }: Context): AsyncDResult<boolean | void>;
@@ -1,13 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateNewerPackage = validateNewerPackage;
4
+ const xtry_1 = require("@zokugun/xtry");
4
5
  const semver_1 = require("semver");
5
6
  async function validateNewerPackage({ incomingPackage, config, options }) {
6
7
  if (options.force) {
7
- return;
8
+ return xtry_1.OK;
8
9
  }
9
10
  const artifact = config.artifacts[incomingPackage.name];
10
11
  if (artifact) {
11
- return !(0, semver_1.gt)(incomingPackage.version, artifact.version);
12
+ return (0, xtry_1.ok)(!(0, semver_1.gt)(incomingPackage.version, artifact.version));
12
13
  }
14
+ return xtry_1.OK;
13
15
  }
@@ -0,0 +1,3 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type Context } from '../types/context.js';
3
+ export declare function validateNotPresentPackage({ incomingPackage, config, options }: Context): AsyncDResult<boolean | void>;
@@ -1,21 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateNotPresentPackage = validateNotPresentPackage;
4
+ const cli_utils_1 = require("@zokugun/cli-utils");
5
+ const xtry_1 = require("@zokugun/xtry");
4
6
  async function validateNotPresentPackage({ incomingPackage, config, options }) {
5
7
  if (options.force) {
6
- return;
8
+ return xtry_1.OK;
7
9
  }
8
10
  const { name } = incomingPackage;
9
11
  const artifact = config.artifacts[name];
10
12
  if (artifact) {
11
13
  if (options.skip) {
12
14
  if (options.verbose) {
13
- console.log('The incoming artifact is already present, skipping...');
15
+ cli_utils_1.logger.debug('The incoming artifact is already present, skipping...');
14
16
  }
15
- return true;
17
+ return xtry_1.OK_TRUE;
16
18
  }
17
19
  else {
18
- throw new Error('The incoming artifact has already been added.');
20
+ return (0, xtry_1.err)('The incoming artifact has already been added.');
19
21
  }
20
22
  }
23
+ return xtry_1.OK;
21
24
  }
@@ -0,0 +1,3 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type Context } from '../types/context.js';
3
+ export declare function validatePresentPackage({ incomingPackage, config, options }: Context): AsyncDResult<boolean | void>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validatePresentPackage = validatePresentPackage;
4
+ const cli_utils_1 = require("@zokugun/cli-utils");
5
+ const xtry_1 = require("@zokugun/xtry");
6
+ async function validatePresentPackage({ incomingPackage, config, options }) {
7
+ if (options.force) {
8
+ return xtry_1.OK;
9
+ }
10
+ const { name } = incomingPackage;
11
+ const artifact = config.artifacts[name];
12
+ if (!artifact) {
13
+ if (options.skip) {
14
+ if (options.verbose) {
15
+ cli_utils_1.logger.debug('The outgoing artifact is already absent, skipping...');
16
+ }
17
+ return xtry_1.OK_TRUE;
18
+ }
19
+ else {
20
+ return (0, xtry_1.err)('The outgoing artifact has already been removed.');
21
+ }
22
+ }
23
+ return xtry_1.OK;
24
+ }
@@ -0,0 +1,3 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type Context } from '../types/context.js';
3
+ export declare function writeTextFiles({ mergedTextFiles, options, targetPath, transformedFiles }: Context): AsyncDResult;
@@ -5,25 +5,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.writeTextFiles = writeTextFiles;
7
7
  const path_1 = __importDefault(require("path"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- async function writeTextFiles({ mergedTextFiles, targetPath, 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
+ async function writeTextFiles({ mergedTextFiles, options, targetPath, transformedFiles }) {
10
12
  if (options.dryRun) {
11
13
  if (options.verbose) {
12
14
  for (const file of mergedTextFiles) {
13
- console.log(`${file.name} has been written as a text file`);
15
+ cli_utils_1.logger.debug(`${file.name} has been written as a text file`);
14
16
  }
15
17
  }
16
18
  }
17
19
  else {
18
- for (const file of mergedTextFiles) {
20
+ for (const file of [...mergedTextFiles, ...transformedFiles]) {
19
21
  const filePath = path_1.default.join(targetPath, file.name);
20
- await fs_extra_1.default.outputFile(filePath, file.data, 'utf-8');
22
+ const result = await async_1.default.outputFile(filePath, file.data, 'utf8');
23
+ if (result.fails) {
24
+ return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
25
+ }
21
26
  if (file.mode) {
22
- await fs_extra_1.default.chmod(filePath, file.mode);
27
+ const result = await async_1.default.chmod(filePath, file.mode);
28
+ if (result.fails) {
29
+ return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
30
+ }
23
31
  }
24
32
  if (options.verbose) {
25
- console.log(`${file.name} has been written as a text file`);
33
+ cli_utils_1.logger.debug(`${file.name} has been written as a text file`);
26
34
  }
27
35
  }
28
36
  }
37
+ return xtry_1.OK;
29
38
  }
@@ -0,0 +1,4 @@
1
+ export type BinaryFile = {
2
+ source: string;
3
+ target: string;
4
+ };
@@ -0,0 +1,5 @@
1
+ export type Command = {
2
+ args: string[];
3
+ env: string[];
4
+ separator?: string;
5
+ };