@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,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.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
+ indent: file.indent,
51
+ mode: file.mode,
52
+ });
53
+ if (options.verbose) {
54
+ cli_utils_1.logger.debug(`${file.name} has been unmerged`);
55
+ }
56
+ }
57
+ else {
58
+ if (options.verbose) {
59
+ cli_utils_1.logger.debug(`${file.name}, no unmerger has been found`);
60
+ }
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 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
+ };
@@ -0,0 +1,59 @@
1
+ import { type Indent } from './format.js';
2
+ export type Request = {
3
+ name: string;
4
+ variant?: string;
5
+ };
6
+ export type PackageManifest = {
7
+ name: string;
8
+ version: string;
9
+ };
10
+ export type PackageConfig = {
11
+ constants: Record<string, string>;
12
+ extends?: string;
13
+ install: InstallFileConfig[];
14
+ orphan: boolean;
15
+ uninstall: UninstallFileConfig[];
16
+ update: false | UpdateFileConfig[];
17
+ variables: Record<string, string>;
18
+ variants: Record<string, string>;
19
+ };
20
+ export type Artifact = {
21
+ version: string;
22
+ provides?: string[];
23
+ requires?: string[];
24
+ };
25
+ export type ArtifactResult = Artifact & {
26
+ name: string;
27
+ };
28
+ export type InstallConfig = {
29
+ artifacts: Record<string, Artifact>;
30
+ constants: Record<string, string>;
31
+ install: Record<string, InstallFileConfig>;
32
+ update: false | Record<string, UpdateFileConfig>;
33
+ variables: Record<string, string>;
34
+ };
35
+ export type FileConfig<E> = {
36
+ ifExists: E;
37
+ pattern: string;
38
+ transforms: FileTransform[];
39
+ };
40
+ export type AlwaysFileConfig = FileConfig<'force-merge' | 'merge' | 'overwrite' | 'remove' | 'skip'>;
41
+ export type InstallFileConfig = UpsertFileConfig;
42
+ export type UninstallFileConfig = FileConfig<'remove' | 'skip' | 'unmerge'>;
43
+ export type UpdateFileConfig = UpsertFileConfig;
44
+ export type UpsertFileConfig = AlwaysFileConfig & {
45
+ filter?: string[];
46
+ ifMissing: 'merge' | 'skip';
47
+ rename?: string;
48
+ route?: Record<string, any>;
49
+ };
50
+ export type FileTransform = {
51
+ description?: string;
52
+ jq: string;
53
+ };
54
+ export type InstallConfigStats = {
55
+ name: string;
56
+ type: string;
57
+ finalNewLine: boolean;
58
+ indent?: Indent;
59
+ };
@@ -0,0 +1,62 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type BinaryFile } from './binary-file.js';
3
+ import { type Request, type InstallConfig, type PackageConfig, type ArtifactResult, type PackageManifest, type FileTransform } from './config.js';
4
+ import { type Indent, type Format } from './format.js';
5
+ import { type Journey } from './travel.js';
6
+ export type ExistingAction = 'merge' | 'overwrite' | 'skip';
7
+ export type MissingAction = 'continue' | 'skip';
8
+ export type RenameAction = {
9
+ from: string;
10
+ to: string;
11
+ };
12
+ export type Context = {
13
+ binaryFiles: BinaryFile[];
14
+ blocks: Block[];
15
+ commonFlow: CommonFlow;
16
+ config: InstallConfig;
17
+ filters: (file: string) => string[] | undefined;
18
+ formats: Format[];
19
+ incomingName?: string;
20
+ incomingVersion?: string;
21
+ incomingVariant?: string;
22
+ incomingBranch?: string;
23
+ incomingConfig?: PackageConfig;
24
+ incomingPackage?: PackageManifest;
25
+ incomingPath: string;
26
+ mergedTextFiles: TextFile[];
27
+ onExisting: (file: string) => ExistingAction;
28
+ onMissing: (file: string) => MissingAction;
29
+ options: Options;
30
+ packagePath: string;
31
+ removedPatterns: string[];
32
+ renamedPatterns: RenameAction[];
33
+ request: Request;
34
+ result?: ArtifactResult;
35
+ routes: (file: string) => Journey | undefined;
36
+ targetPath: string;
37
+ textFiles: TextFile[];
38
+ transformedFiles: TextFile[];
39
+ transforms: (file: string) => FileTransform[] | undefined;
40
+ };
41
+ export type MainFlow = (targetPath: string, incomingPath: string, request: Request, config: InstallConfig, options: Options) => AsyncDResult<Context | undefined>;
42
+ export type CommonFlow = (name: string, version: string, variant: string | undefined, branch: string | undefined, incomingPath: string, commonContext: Context) => AsyncDResult<Context | undefined>;
43
+ export type Options = {
44
+ force: boolean;
45
+ skip: boolean;
46
+ verbose: boolean;
47
+ dryRun: boolean;
48
+ };
49
+ export type Block = {
50
+ name: string;
51
+ version: string;
52
+ variant?: string;
53
+ branch?: string;
54
+ incomingPath: string;
55
+ };
56
+ export type TextFile = {
57
+ data: string;
58
+ finalNewLine: boolean;
59
+ indent?: Indent;
60
+ mode?: number;
61
+ name: string;
62
+ };
@@ -1,2 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ // export type OutputTextFile = {
4
+ // data: string;
5
+ // name: string;
6
+ // };
@@ -0,0 +1,14 @@
1
+ export declare enum IndentStyle {
2
+ SPACE = "space",
3
+ TAB = "tab"
4
+ }
5
+ export type Format = {
6
+ glob: string;
7
+ indentStyle: IndentStyle;
8
+ indentSize: number;
9
+ insertFinalNewline: boolean;
10
+ };
11
+ export type Indent = {
12
+ style: IndentStyle;
13
+ size: number;
14
+ };
@@ -0,0 +1,3 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type Context } from './context.js';
3
+ export type Step = (context: Context) => AsyncDResult<boolean | void>;
@@ -0,0 +1,14 @@
1
+ import { type FileTransform } from './config.js';
2
+ export type Args<T> = {
3
+ current: T | undefined;
4
+ incoming: T | undefined;
5
+ filters?: string[];
6
+ ignores?: string[];
7
+ transforms?: FileTransform[];
8
+ };
9
+ export type Route<T> = (args: Args<T>) => Promise<T>;
10
+ export type TravelPlan = (basename: string) => Route<string> | undefined;
11
+ export type Journey = {
12
+ alias?: string;
13
+ travel: Route<string>;
14
+ };
@@ -0,0 +1,2 @@
1
+ import { type FileTransform } from '../types/config.js';
2
+ export declare function applyTransforms(transforms: FileTransform[] | undefined): (data: Record<string, unknown>) => Promise<Record<string, unknown>>;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.applyTransforms = applyTransforms;
37
+ const jq = __importStar(require("jq-wasm"));
38
+ function applyTransforms(transforms) {
39
+ if (!transforms) {
40
+ return async (data) => data;
41
+ }
42
+ return async (data) => {
43
+ for (const transform of transforms) {
44
+ data = await jq.json(data, transform.jq);
45
+ }
46
+ return data;
47
+ };
48
+ }
@@ -0,0 +1,2 @@
1
+ import { type Journey, type TravelPlan } from '../types/travel.js';
2
+ export declare function buildJourneyPlan(plan: TravelPlan, alias?: string): (basename: string) => Journey | undefined;
@@ -0,0 +1,3 @@
1
+ import { type DResult } from '@zokugun/xtry';
2
+ import { type Route } from '../types/travel.js';
3
+ export declare function buildRoute(route: any): DResult<Route<any>>;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildRoute = buildRoute;
4
+ const is_it_type_1 = require("@zokugun/is-it-type");
5
+ const xtry_1 = require("@zokugun/xtry");
6
+ const fork_js_1 = require("../compositors/fork.js");
7
+ const index_js_1 = require("../compositors/index.js");
8
+ const index_js_2 = require("../routes/index.js");
9
+ function buildRoute(route) {
10
+ if (Array.isArray(route) && route.length > 0) {
11
+ const buildResult = buildRoute(route[0]);
12
+ if (buildResult.fails) {
13
+ return buildResult;
14
+ }
15
+ let result = buildResult.value;
16
+ for (let i = 1; i < route.length; i++) {
17
+ if (route[i] === 'mapSort') {
18
+ result = (0, index_js_1.mapSort)(result);
19
+ }
20
+ else {
21
+ return (0, xtry_1.err)('Can\'t build route');
22
+ }
23
+ }
24
+ return (0, xtry_1.ok)(result);
25
+ }
26
+ else if ((0, is_it_type_1.isRecord)(route)) {
27
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
28
+ const { compose: rtCompose, fork: rtFork, mapSort: rtMapSort } = route;
29
+ if (rtCompose) {
30
+ const map = {};
31
+ for (const [name, route] of Object.entries(rtCompose)) {
32
+ const result = buildRoute(route);
33
+ if (result.fails) {
34
+ return result;
35
+ }
36
+ map[name] = result.value;
37
+ }
38
+ return (0, xtry_1.ok)((0, index_js_1.compose)(map));
39
+ }
40
+ else if (rtFork) {
41
+ const map = [];
42
+ if (rtFork.array) {
43
+ const result = buildRoute(rtFork.array);
44
+ if (result.fails) {
45
+ return result;
46
+ }
47
+ map.push([Array.isArray, result.value]);
48
+ }
49
+ if (rtFork.object) {
50
+ const result = buildRoute(rtFork.object);
51
+ if (result.fails) {
52
+ return result;
53
+ }
54
+ map.push([is_it_type_1.isRecord, result.value]);
55
+ }
56
+ if (rtFork.default) {
57
+ const result = buildRoute(rtFork.default);
58
+ if (result.fails) {
59
+ return result;
60
+ }
61
+ map.push(result.value);
62
+ }
63
+ return (0, xtry_1.ok)((0, fork_js_1.fork)(...map));
64
+ }
65
+ else if (rtMapSort) {
66
+ const result = buildRoute(rtMapSort);
67
+ if (result.fails) {
68
+ return result;
69
+ }
70
+ return (0, xtry_1.ok)((0, index_js_1.mapSort)(result.value));
71
+ }
72
+ }
73
+ else if (route === 'command') {
74
+ return (0, xtry_1.ok)(index_js_2.command);
75
+ }
76
+ else if (route === 'linesConcat') {
77
+ return (0, xtry_1.ok)(index_js_2.linesConcat);
78
+ }
79
+ else if (route === 'listConcat') {
80
+ return (0, xtry_1.ok)(index_js_2.listConcat);
81
+ }
82
+ else if (route === 'mapConcat') {
83
+ return (0, xtry_1.ok)(index_js_2.mapConcat);
84
+ }
85
+ else if (route === 'overwrite') {
86
+ return (0, xtry_1.ok)(index_js_2.overwrite);
87
+ }
88
+ else if (route === 'primitive') {
89
+ return (0, xtry_1.ok)(index_js_2.primitive);
90
+ }
91
+ return (0, xtry_1.err)('Can\'t build route');
92
+ } // }}}
@@ -0,0 +1,2 @@
1
+ import { type Route, type TravelPlan } from '../types/travel.js';
2
+ export declare function buildTravelPlan(...mappers: Array<[RegExp | string, Route<string>]>): TravelPlan;
@@ -0,0 +1,3 @@
1
+ import { type DResult } from '@zokugun/xtry';
2
+ import { type Route } from '../types/travel.js';
3
+ export declare function buildTravel(route: Record<string, any>): DResult<Route<string>>;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildTravel = buildTravel;
4
+ const xtry_1 = require("@zokugun/xtry");
5
+ const index_js_1 = require("../compositors/index.js");
6
+ const build_route_js_1 = require("./build-route.js");
7
+ function buildTravel(route) {
8
+ if (route.json) {
9
+ const result = (0, build_route_js_1.buildRoute)(route.json);
10
+ if (result.fails) {
11
+ return result;
12
+ }
13
+ return (0, xtry_1.ok)((0, index_js_1.json)(result.value));
14
+ }
15
+ else if (route.rc) {
16
+ const result = (0, build_route_js_1.buildRoute)(route.rc);
17
+ if (result.fails) {
18
+ return result;
19
+ }
20
+ return (0, xtry_1.ok)((0, index_js_1.rc)(result.value));
21
+ }
22
+ else if (route.yaml) {
23
+ const result = (0, build_route_js_1.buildRoute)(route.yaml);
24
+ if (result.fails) {
25
+ return result;
26
+ }
27
+ return (0, xtry_1.ok)((0, index_js_1.yaml)(result.value));
28
+ }
29
+ else {
30
+ return (0, xtry_1.err)('Can\'t build route');
31
+ }
32
+ } // }}}
@@ -0,0 +1 @@
1
+ export declare function dedupeStrings(items: string[]): string[];
@@ -0,0 +1,8 @@
1
+ export type { Command } from '../../types/command.js';
2
+ export { joinCommand } from './join-command.js';
3
+ export { mergeAndChains } from './merge-and-chains.js';
4
+ export { mergeCommandRecords } from './merge-command-records.js';
5
+ export { mergeOrSegments } from './merge-or-segments.js';
6
+ export { mergeSemicolonSegments } from './merge-semicolon-segments.js';
7
+ export { mergeWithSemicolonMix } from './merge-with-semicolon-mix.js';
8
+ export { splitCommand } from './split-command.js';
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.splitCommand = exports.mergeWithSemicolonMix = exports.mergeSemicolonSegments = exports.mergeOrSegments = exports.mergeCommandRecords = exports.mergeAndChains = exports.joinCommand = void 0;
4
- var join_command_1 = require("./join-command");
5
- Object.defineProperty(exports, "joinCommand", { enumerable: true, get: function () { return join_command_1.joinCommand; } });
6
- var merge_and_chains_1 = require("./merge-and-chains");
7
- Object.defineProperty(exports, "mergeAndChains", { enumerable: true, get: function () { return merge_and_chains_1.mergeAndChains; } });
8
- var merge_command_records_1 = require("./merge-command-records");
9
- Object.defineProperty(exports, "mergeCommandRecords", { enumerable: true, get: function () { return merge_command_records_1.mergeCommandRecords; } });
10
- var merge_or_segments_1 = require("./merge-or-segments");
11
- Object.defineProperty(exports, "mergeOrSegments", { enumerable: true, get: function () { return merge_or_segments_1.mergeOrSegments; } });
12
- var merge_semicolon_segments_1 = require("./merge-semicolon-segments");
13
- Object.defineProperty(exports, "mergeSemicolonSegments", { enumerable: true, get: function () { return merge_semicolon_segments_1.mergeSemicolonSegments; } });
14
- var merge_with_semicolon_mix_1 = require("./merge-with-semicolon-mix");
15
- Object.defineProperty(exports, "mergeWithSemicolonMix", { enumerable: true, get: function () { return merge_with_semicolon_mix_1.mergeWithSemicolonMix; } });
16
- var split_command_1 = require("./split-command");
17
- Object.defineProperty(exports, "splitCommand", { enumerable: true, get: function () { return split_command_1.splitCommand; } });
4
+ var join_command_js_1 = require("./join-command.js");
5
+ Object.defineProperty(exports, "joinCommand", { enumerable: true, get: function () { return join_command_js_1.joinCommand; } });
6
+ var merge_and_chains_js_1 = require("./merge-and-chains.js");
7
+ Object.defineProperty(exports, "mergeAndChains", { enumerable: true, get: function () { return merge_and_chains_js_1.mergeAndChains; } });
8
+ var merge_command_records_js_1 = require("./merge-command-records.js");
9
+ Object.defineProperty(exports, "mergeCommandRecords", { enumerable: true, get: function () { return merge_command_records_js_1.mergeCommandRecords; } });
10
+ var merge_or_segments_js_1 = require("./merge-or-segments.js");
11
+ Object.defineProperty(exports, "mergeOrSegments", { enumerable: true, get: function () { return merge_or_segments_js_1.mergeOrSegments; } });
12
+ var merge_semicolon_segments_js_1 = require("./merge-semicolon-segments.js");
13
+ Object.defineProperty(exports, "mergeSemicolonSegments", { enumerable: true, get: function () { return merge_semicolon_segments_js_1.mergeSemicolonSegments; } });
14
+ var merge_with_semicolon_mix_js_1 = require("./merge-with-semicolon-mix.js");
15
+ Object.defineProperty(exports, "mergeWithSemicolonMix", { enumerable: true, get: function () { return merge_with_semicolon_mix_js_1.mergeWithSemicolonMix; } });
16
+ var split_command_js_1 = require("./split-command.js");
17
+ Object.defineProperty(exports, "splitCommand", { enumerable: true, get: function () { return split_command_js_1.splitCommand; } });
@@ -0,0 +1,2 @@
1
+ import { type Command } from '../../types/command.js';
2
+ export declare function joinCommand(commands: Record<string, Command[]>): string;
@@ -0,0 +1 @@
1
+ export declare function mergeAndChains(current: string, incoming: string): string | undefined;