@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
@@ -34,12 +34,14 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.json = json;
37
- const lodash_1 = require("lodash");
38
- const JSON = __importStar(require("../parsers/json"));
39
- const JSONC = __importStar(require("../parsers/jsonc"));
40
- const routes_1 = require("../routes");
41
- const compose_1 = require("./compose");
42
- const fork_1 = require("./fork");
37
+ const is_it_type_1 = require("@zokugun/is-it-type");
38
+ const JSON = __importStar(require("../parsers/json.js"));
39
+ const JSONC = __importStar(require("../parsers/jsonc/index.js"));
40
+ const index_js_1 = require("../routes/index.js");
41
+ const apply_transforms_js_1 = require("../utils/apply-transforms.js");
42
+ const flow_js_1 = require("../utils/flow.js");
43
+ const compose_js_1 = require("./compose.js");
44
+ const fork_js_1 = require("./fork.js");
43
45
  function tryJson(value) {
44
46
  try {
45
47
  return JSON.parse(value);
@@ -48,22 +50,22 @@ function tryJson(value) {
48
50
  return undefined;
49
51
  }
50
52
  }
51
- const merge = (0, compose_1.compose)({
52
- $$default: (0, fork_1.fork)([Array.isArray, routes_1.listConcat], [lodash_1.isPlainObject, (...args) => merge(...args)], routes_1.primitive),
53
+ const merge = (0, compose_js_1.compose)({
54
+ $$default: (0, fork_js_1.fork)([is_it_type_1.isArray, index_js_1.listConcat], [is_it_type_1.isRecord, async (...args) => merge(...args)], index_js_1.primitive),
53
55
  });
54
56
  function json(...routes) {
55
- return ({ current, incoming, filters, ignores }) => {
57
+ return async ({ current, incoming, filters, ignores, transforms }) => {
56
58
  const currentData = current && tryJson(current);
57
59
  const incomingData = incoming && tryJson(incoming);
58
60
  if ((!current || currentData) && (!incoming || incomingData)) {
59
- return (0, lodash_1.flow)(...routes, JSON.stringify)({ current: currentData, incoming: incomingData, filters, ignores });
61
+ return await (0, flow_js_1.flow)(...routes, (0, apply_transforms_js_1.applyTransforms)(transforms), JSON.stringify)({ current: currentData, incoming: incomingData, filters, ignores, transforms });
60
62
  }
61
63
  else {
62
64
  const { data: currentData, transform: currentTransform } = JSONC.parse(current);
63
65
  const { data: incomingData, transform: incomingTransform } = JSONC.parse(incoming);
64
- const mergedTransform = merge({ current: currentTransform, incoming: incomingTransform });
66
+ const mergedTransform = await merge({ current: currentTransform, incoming: incomingTransform });
65
67
  const toJSON = (data) => JSONC.stringify(data, mergedTransform);
66
- return (0, lodash_1.flow)(...routes, toJSON)({ current: currentData, incoming: incomingData, filters, ignores });
68
+ return await (0, flow_js_1.flow)(...routes, (0, apply_transforms_js_1.applyTransforms)(transforms), toJSON)({ current: currentData, incoming: incomingData, filters, ignores, transforms });
67
69
  }
68
70
  };
69
71
  }
@@ -0,0 +1,2 @@
1
+ import { type Route } from '../types/travel.js';
2
+ export declare function mapSort(route: Route<Record<string, unknown>>): Route<Record<string, unknown>>;
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mapSort = mapSort;
4
4
  const { compare } = new Intl.Collator('en');
5
5
  function mapSort(route) {
6
- return (args) => {
7
- const result = route(args);
6
+ return async (args) => {
7
+ const result = await route(args);
8
8
  const sorted = {};
9
9
  const keys = Object.keys(result).sort((a, b) => compare(a, b));
10
10
  for (const key of keys) {
@@ -0,0 +1,2 @@
1
+ import { type Route } from '../types/travel.js';
2
+ export declare function rc(...routes: Array<Route<Record<string, any>>>): Route<string>;
@@ -34,21 +34,24 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.rc = rc;
37
- const lodash_1 = require("lodash");
38
- const JSON = __importStar(require("../parsers/json"));
39
- const YAML = __importStar(require("../parsers/yaml"));
40
- const try_json_1 = require("../utils/try-json");
37
+ const is_it_type_1 = require("@zokugun/is-it-type");
38
+ const lodash_es_1 = require("lodash-es");
39
+ const JSON = __importStar(require("../parsers/json.js"));
40
+ const YAML = __importStar(require("../parsers/yaml.js"));
41
+ const apply_transforms_js_1 = require("../utils/apply-transforms.js");
42
+ const flow_js_1 = require("../utils/flow.js");
43
+ const try_json_js_1 = require("../utils/try-json.js");
41
44
  function rc(...routes) {
42
- return ({ current, incoming, filters, ignores }) => {
43
- const currentData = current && ((0, try_json_1.tryJson)(current) ?? YAML.parse(current));
44
- const incomingData = incoming && (0, try_json_1.tryJson)(incoming);
45
+ return async ({ current, incoming, filters, ignores, transforms }) => {
46
+ const currentData = current && ((0, try_json_js_1.tryJSON)(current) ?? YAML.parse(current));
47
+ const incomingData = incoming && (0, try_json_js_1.tryJSON)(incoming);
45
48
  if (incomingData) {
46
- return (0, lodash_1.flow)(...routes, JSON.stringify)({ current: currentData, incoming: incomingData, filters, ignores });
49
+ return await (0, flow_js_1.flow)(...routes, (0, apply_transforms_js_1.applyTransforms)(transforms), JSON.stringify)({ current: currentData, incoming: incomingData, filters, ignores });
47
50
  }
48
51
  else {
49
52
  const incomingData = incoming && YAML.parse(incoming);
50
- if ((0, lodash_1.isPlainObject)(incomingData) || Array.isArray(incomingData)) {
51
- return (0, lodash_1.flow)(...routes, YAML.stringify)({ current: currentData, incoming: incomingData, filters, ignores });
53
+ if ((0, lodash_es_1.isArray)(incomingData) || (0, is_it_type_1.isRecord)(incomingData)) {
54
+ return await (0, flow_js_1.flow)(...routes, (0, apply_transforms_js_1.applyTransforms)(transforms), YAML.stringify)({ current: currentData, incoming: incomingData, filters, ignores });
52
55
  }
53
56
  else {
54
57
  return incoming;
@@ -0,0 +1,2 @@
1
+ import { type Route } from '../types/travel.js';
2
+ export declare function yaml(...routes: Array<Route<Record<string, any>>>): Route<string>;
@@ -34,16 +34,13 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.yaml = yaml;
37
- const lodash_1 = require("lodash");
38
- const YAML = __importStar(require("../parsers/yaml"));
39
- function fromYaml({ current, incoming, filters, ignores }) {
40
- return {
41
- current: typeof current === 'undefined' ? undefined : YAML.parse(current),
42
- incoming: YAML.parse(incoming),
43
- filters,
44
- ignores,
45
- };
46
- }
37
+ const YAML = __importStar(require("../parsers/yaml.js"));
38
+ const apply_transforms_js_1 = require("../utils/apply-transforms.js");
39
+ const flow_js_1 = require("../utils/flow.js");
47
40
  function yaml(...routes) {
48
- return (0, lodash_1.flow)(fromYaml, ...routes, YAML.stringify);
41
+ return async ({ current, incoming, filters, ignores, transforms }) => {
42
+ const currentData = current === undefined ? undefined : YAML.parse(current);
43
+ const incomingData = YAML.parse(incoming);
44
+ return await (0, flow_js_1.flow)(...routes, (0, apply_transforms_js_1.applyTransforms)(transforms), YAML.stringify)({ current: currentData, incoming: incomingData, filters, ignores, transforms });
45
+ };
49
46
  }
@@ -0,0 +1,3 @@
1
+ export * from './install/index.js';
2
+ export * from './package/index.js';
3
+ export * from './uninstall/index.js';
@@ -14,5 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./install"), exports);
18
- __exportStar(require("./package"), exports);
17
+ __exportStar(require("./install/index.js"), exports);
18
+ __exportStar(require("./package/index.js"), exports);
19
+ __exportStar(require("./uninstall/index.js"), exports);
@@ -0,0 +1,3 @@
1
+ export { readInstallConfig } from './read-install-config.js';
2
+ export { writeInstallConfig } from './write-install-config.js';
3
+ export { updateInstallConfig } from './update-install-config.js';
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateInstallConfig = exports.writeInstallConfig = exports.readInstallConfig = void 0;
4
- var read_install_config_1 = require("./read-install-config");
5
- Object.defineProperty(exports, "readInstallConfig", { enumerable: true, get: function () { return read_install_config_1.readInstallConfig; } });
6
- var write_install_config_1 = require("./write-install-config");
7
- Object.defineProperty(exports, "writeInstallConfig", { enumerable: true, get: function () { return write_install_config_1.writeInstallConfig; } });
8
- var update_install_config_1 = require("./update-install-config");
9
- Object.defineProperty(exports, "updateInstallConfig", { enumerable: true, get: function () { return update_install_config_1.updateInstallConfig; } });
4
+ var read_install_config_js_1 = require("./read-install-config.js");
5
+ Object.defineProperty(exports, "readInstallConfig", { enumerable: true, get: function () { return read_install_config_js_1.readInstallConfig; } });
6
+ var write_install_config_js_1 = require("./write-install-config.js");
7
+ Object.defineProperty(exports, "writeInstallConfig", { enumerable: true, get: function () { return write_install_config_js_1.writeInstallConfig; } });
8
+ var update_install_config_js_1 = require("./update-install-config.js");
9
+ Object.defineProperty(exports, "updateInstallConfig", { enumerable: true, get: function () { return update_install_config_js_1.updateInstallConfig; } });
@@ -0,0 +1,6 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type InstallConfig, type InstallConfigStats } from '../../types/config.js';
3
+ export declare function readInstallConfig(targetPath: string): AsyncDResult<{
4
+ config: InstallConfig;
5
+ configStats: InstallConfigStats;
6
+ }>;
@@ -5,108 +5,151 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.readInstallConfig = readInstallConfig;
7
7
  const path_1 = __importDefault(require("path"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
8
+ const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
9
+ const is_it_type_1 = require("@zokugun/is-it-type");
10
+ const xtry_1 = require("@zokugun/xtry");
9
11
  const yaml_1 = __importDefault(require("yaml"));
10
- const places = [
11
- {
12
- name: '.artifactrc.yml',
13
- type: 'yaml',
14
- },
15
- {
16
- name: '.artifactrc.yaml',
17
- type: 'yaml',
18
- },
19
- {
20
- name: '.artifactrc.json',
21
- type: 'json',
22
- },
23
- {
24
- name: '.artifactrc',
25
- },
26
- ];
12
+ const constants_js_1 = require("../utils/constants.js");
13
+ const normalize_file_upsert_js_1 = require("../utils/normalize-file-upsert.js");
27
14
  async function readInstallConfig(targetPath) {
28
15
  let content;
29
16
  let name;
30
17
  let type;
31
- for (const place of places) {
32
- try {
33
- content = await fs_extra_1.default.readFile(path_1.default.join(targetPath, place.name), 'utf-8');
34
- name = place.name;
35
- type = place.type;
36
- break;
37
- }
38
- catch {
18
+ for (const place of constants_js_1.CONFIG_LOCATIONS) {
19
+ const result = await async_1.default.readFile(path_1.default.join(targetPath, place.name), 'utf8');
20
+ if (!result.fails) {
21
+ content = result.value;
22
+ ({ name, type } = place);
39
23
  }
40
24
  }
41
- if (!content) {
42
- return {
43
- config: {
44
- artifacts: {},
45
- install: {},
46
- update: {},
47
- },
48
- configStats: {
49
- name: '.artifactrc.yml',
50
- type: 'yaml',
51
- finalNewLine: true,
52
- },
53
- };
25
+ if (!content || !name) {
26
+ return normalizeConfig(content, {
27
+ name: '.artifactrc.yml',
28
+ type: 'yaml',
29
+ finalNewLine: true,
30
+ });
54
31
  }
55
32
  const finalNewLine = content.endsWith('\n');
56
- let data;
57
33
  if (type === 'json') {
58
- data = JSON.parse(content);
34
+ return normalizeConfig(JSON.parse(content), {
35
+ name,
36
+ type: 'json',
37
+ finalNewLine,
38
+ });
59
39
  }
60
40
  else if (type === 'yaml') {
61
- data = yaml_1.default.parse(content);
41
+ return normalizeConfig(yaml_1.default.parse(content), {
42
+ name,
43
+ type: 'yaml',
44
+ finalNewLine,
45
+ });
62
46
  }
63
47
  else {
64
48
  try {
65
- data = JSON.parse(content);
66
- type = 'json';
49
+ return normalizeConfig(JSON.parse(content), {
50
+ name,
51
+ type: 'json',
52
+ finalNewLine,
53
+ });
67
54
  }
68
55
  catch {
69
- data = yaml_1.default.parse(content);
70
- type = 'yaml';
56
+ return normalizeConfig(yaml_1.default.parse(content), {
57
+ name,
58
+ type: 'yaml',
59
+ finalNewLine,
60
+ });
71
61
  }
72
62
  }
73
- if (typeof data.artifacts === 'undefined') {
74
- data.artifacts = {};
63
+ }
64
+ function normalizeConfig(data, configStats) {
65
+ const artifacts = {};
66
+ let constants = {};
67
+ const install = {};
68
+ let update = {};
69
+ let variables = {};
70
+ if (!data) {
71
+ return (0, xtry_1.ok)({
72
+ config: {
73
+ artifacts,
74
+ constants,
75
+ install,
76
+ update,
77
+ variables,
78
+ },
79
+ configStats,
80
+ });
75
81
  }
76
- if (typeof data.update === 'undefined') {
77
- data.update = {};
82
+ if (!(0, is_it_type_1.isRecord)(data)) {
83
+ return (0, xtry_1.err)(`Config file ${configStats.name} must export an object.`);
78
84
  }
79
- if (isOldInstallConfig(data)) {
80
- const config = {
81
- artifacts: {},
82
- install: data.install,
83
- update: data.update,
84
- };
85
- for (const { name, version } of data.artifacts) {
86
- config.artifacts[name] = {
87
- version,
88
- };
85
+ if ((0, is_it_type_1.isString)(data.$schema)) {
86
+ const match = constants_js_1.VERSION_INSTALL_REGEX.exec(data.$schema);
87
+ if (!match) {
88
+ return (0, xtry_1.err)(`Cannot validate the "$schema" in the project's "${configStats.name}".`);
89
+ }
90
+ const version = Number.parseInt(match[2], 10);
91
+ if (version > constants_js_1.MAX_VERSION) {
92
+ return (0, xtry_1.err)(`Don't support newer version (v${version}) in the project's "${configStats.name}".`);
89
93
  }
90
- return {
91
- config,
92
- configStats: {
93
- name: name,
94
- type,
95
- finalNewLine,
96
- },
97
- };
98
94
  }
99
- else {
100
- return {
101
- config: data,
102
- configStats: {
103
- name: name,
104
- type,
105
- finalNewLine,
106
- },
107
- };
95
+ if ((0, is_it_type_1.isArray)(data.artifacts)) {
96
+ for (const artifact of data.artifacts) {
97
+ if ((0, is_it_type_1.isRecord)(artifact) && (0, is_it_type_1.isString)(artifact.name) && (0, is_it_type_1.isString)(artifact.version)) {
98
+ const normalized = {
99
+ version: artifact.version,
100
+ };
101
+ if ((0, is_it_type_1.isString)(artifact.variant)) {
102
+ normalized.requires = [artifact.variant];
103
+ }
104
+ artifacts[artifact.name] = normalized;
105
+ }
106
+ }
108
107
  }
109
- }
110
- function isOldInstallConfig(config) {
111
- return Array.isArray(config.artifacts);
108
+ else if ((0, is_it_type_1.isRecord)(data.artifacts)) {
109
+ for (const [key, artifact] of Object.entries(data.artifacts)) {
110
+ if ((0, is_it_type_1.isRecord)(artifact) && (0, is_it_type_1.isString)(artifact.version)) {
111
+ const normalized = {
112
+ version: artifact.version,
113
+ };
114
+ if ((0, is_it_type_1.isArray)(artifact.requires, is_it_type_1.isString)) {
115
+ normalized.requires = artifact.requires;
116
+ }
117
+ else if ((0, is_it_type_1.isArray)(artifact.provides, is_it_type_1.isString)) {
118
+ normalized.requires = artifact.provides;
119
+ }
120
+ artifacts[key] = normalized;
121
+ }
122
+ }
123
+ }
124
+ if ((0, is_it_type_1.isRecord)(data.constants, (_key, value) => (0, is_it_type_1.isString)(value))) {
125
+ constants = data.constants;
126
+ }
127
+ if (data.update === false) {
128
+ update = false;
129
+ }
130
+ else if ((0, is_it_type_1.isRecord)(data.update)) {
131
+ for (const [key, value] of Object.entries(data.update)) {
132
+ const normalized = (0, normalize_file_upsert_js_1.normalizeFileUpsert)(value, 'update');
133
+ if (normalized.fails) {
134
+ return normalized;
135
+ }
136
+ if (update[key]) {
137
+ return (0, xtry_1.err)(`Conflict with the "${key}" key on "update"1.`);
138
+ }
139
+ update[key] = normalized.value;
140
+ }
141
+ }
142
+ if ((0, is_it_type_1.isRecord)(data.variables, (_key, value) => (0, is_it_type_1.isString)(value))) {
143
+ variables = data.variables;
144
+ }
145
+ return (0, xtry_1.ok)({
146
+ config: {
147
+ artifacts,
148
+ constants,
149
+ install,
150
+ update,
151
+ variables,
152
+ },
153
+ configStats,
154
+ });
112
155
  }
@@ -0,0 +1,2 @@
1
+ import { type ArtifactResult, type InstallConfig } from '../../types/config.js';
2
+ export declare function updateInstallConfig(config: InstallConfig, { name, version, provides, requires }: ArtifactResult): void;
@@ -0,0 +1,5 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type InstallConfig, type InstallConfigStats } from '../../types/config.js';
3
+ import { type Options } from '../../types/context.js';
4
+ import { type Format } from '../../types/format.js';
5
+ export declare function writeInstallConfig(config: InstallConfig, { name, finalNewLine, type }: InstallConfigStats, formats: Format[], targetPath: string, options: Options): AsyncDResult;
@@ -5,16 +5,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.writeInstallConfig = writeInstallConfig;
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 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 lodash_es_1 = require("lodash-es");
10
12
  const yaml_1 = __importDefault(require("yaml"));
11
- const apply_formatting_1 = require("../../steps/apply-formatting");
12
- const insert_final_new_line_1 = require("../../steps/insert-final-new-line");
13
+ const apply_formatting_js_1 = require("../../steps/apply-formatting.js");
14
+ const insert_final_new_line_js_1 = require("../../steps/insert-final-new-line.js");
15
+ const constants_js_1 = require("../utils/constants.js");
13
16
  async function writeInstallConfig(config, { name, finalNewLine, type }, formats, targetPath, options) {
14
17
  const exported = {
18
+ $schema: `https://raw.githubusercontent.com/zokugun/artifact/v${constants_js_1.VERSION_RELEASE}/schemas/v${constants_js_1.MAX_VERSION}/install.json`,
15
19
  artifacts: config.artifacts,
16
20
  };
17
- if (!(0, lodash_1.isPlainObject)(config.update) || !(0, lodash_1.isEmpty)(config.update)) {
21
+ if (!(0, lodash_es_1.isPlainObject)(config.update) || !(0, lodash_es_1.isEmpty)(config.update)) {
18
22
  exported.update = config.update;
19
23
  }
20
24
  const file = {
@@ -22,13 +26,17 @@ async function writeInstallConfig(config, { name, finalNewLine, type }, formats,
22
26
  data: type === 'yaml' ? yaml_1.default.stringify(exported) : JSON.stringify(exported, null, '\t'),
23
27
  finalNewLine,
24
28
  };
25
- await (0, insert_final_new_line_1.insertFinalNewLine)({ mergedTextFiles: [file] });
26
- await (0, apply_formatting_1.applyFormatting)({ mergedTextFiles: [file], formats });
29
+ await (0, insert_final_new_line_js_1.insertFinalNewLine)({ mergedTextFiles: [file] });
30
+ await (0, apply_formatting_js_1.applyFormatting)({ mergedTextFiles: [file], formats });
27
31
  if (!options.dryRun) {
28
32
  const filePath = path_1.default.join(targetPath, name);
29
- await fs_extra_1.default.outputFile(filePath, file.data, 'utf-8');
33
+ const result = await async_1.default.outputFile(filePath, file.data, 'utf8');
34
+ if (result.fails) {
35
+ return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
36
+ }
30
37
  }
31
38
  if (options.verbose) {
32
- console.log(`${name} has been written`);
39
+ cli_utils_1.logger.debug(`${name} has been written`);
33
40
  }
41
+ return xtry_1.OK;
34
42
  }
@@ -0,0 +1 @@
1
+ export { readPackageConfig } from './read-package-config.js';
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.readPackageConfig = void 0;
4
- var read_package_config_1 = require("./read-package-config");
5
- Object.defineProperty(exports, "readPackageConfig", { enumerable: true, get: function () { return read_package_config_1.readPackageConfig; } });
4
+ var read_package_config_js_1 = require("./read-package-config.js");
5
+ Object.defineProperty(exports, "readPackageConfig", { enumerable: true, get: function () { return read_package_config_js_1.readPackageConfig; } });
@@ -0,0 +1,3 @@
1
+ import { type AsyncDResult } from '@zokugun/xtry';
2
+ import { type PackageConfig } from '../../types/config.js';
3
+ export declare function readPackageConfig(targetPath: string): AsyncDResult<PackageConfig>;