@zokugun/artifact 0.8.0 → 0.9.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 (96) hide show
  1. package/lib/commands/add.js +67 -37
  2. package/lib/commands/list.js +2 -2
  3. package/lib/commands/outdated.js +2 -2
  4. package/lib/commands/remove.js +12 -18
  5. package/lib/commands/update.js +36 -21
  6. package/lib/compositors/codec.d.ts +3 -0
  7. package/lib/compositors/codec.js +46 -0
  8. package/lib/compositors/compose.d.ts +1 -0
  9. package/lib/compositors/compose.js +4 -0
  10. package/lib/compositors/index.d.ts +1 -0
  11. package/lib/compositors/index.js +3 -1
  12. package/lib/compositors/json.js +3 -66
  13. package/lib/compositors/rc.js +3 -56
  14. package/lib/compositors/yaml.js +24 -3
  15. package/lib/configs/install/read-install-config.d.ts +2 -5
  16. package/lib/configs/install/read-install-config.js +20 -18
  17. package/lib/configs/install/write-install-config.d.ts +2 -2
  18. package/lib/configs/install/write-install-config.js +2 -1
  19. package/lib/configs/package/read-package-config.d.ts +2 -1
  20. package/lib/configs/package/read-package-config.js +96 -10
  21. package/lib/configs/utils/constants.d.ts +2 -2
  22. package/lib/configs/utils/constants.js +2 -2
  23. package/lib/configs/utils/merge-upsert-property.js +0 -8
  24. package/lib/configs/utils/normalize-file-always.js +5 -0
  25. package/lib/configs/utils/normalize-file-upsert.d.ts +2 -1
  26. package/lib/configs/utils/normalize-file-upsert.js +12 -5
  27. package/lib/journeys/commitlint/index.d.ts +1 -1
  28. package/lib/journeys/config.ts/index.d.ts +1 -1
  29. package/lib/journeys/config.ts/index.js +2 -6
  30. package/lib/journeys/default/index.d.ts +1 -1
  31. package/lib/journeys/gitignore/index.d.ts +1 -1
  32. package/lib/journeys/ignore/index.d.ts +1 -1
  33. package/lib/journeys/index.d.ts +2 -2
  34. package/lib/journeys/index.js +9 -11
  35. package/lib/journeys/npmignore/index.d.ts +1 -1
  36. package/lib/journeys/package/index.d.ts +1 -1
  37. package/lib/journeys/rc/index.d.ts +1 -1
  38. package/lib/journeys/tsconfig/index.d.ts +1 -1
  39. package/lib/parsers/index.d.ts +4 -0
  40. package/lib/parsers/index.js +41 -0
  41. package/lib/parsers/json.d.ts +4 -2
  42. package/lib/parsers/json.js +7 -2
  43. package/lib/parsers/jsonc/parse.d.ts +2 -5
  44. package/lib/parsers/jsonc/parse.js +8 -6
  45. package/lib/parsers/to-format.d.ts +2 -0
  46. package/lib/parsers/to-format.js +50 -0
  47. package/lib/parsers/yaml.d.ts +4 -2
  48. package/lib/parsers/yaml.js +7 -2
  49. package/lib/routes/command.js +7 -0
  50. package/lib/routes/index.d.ts +4 -3
  51. package/lib/routes/index.js +9 -7
  52. package/lib/routes/{list-sort-concat.d.ts → list-concat-after.d.ts} +1 -1
  53. package/lib/routes/{list-sort-concat.js → list-concat-after.js} +2 -2
  54. package/lib/routes/merge-dot-js.d.ts +2 -0
  55. package/lib/routes/merge-dot-js.js +8 -0
  56. package/lib/steps/configure-install-file-actions.js +1 -20
  57. package/lib/steps/configure-update-file-actions.js +1 -20
  58. package/lib/steps/execute-first-block.js +1 -1
  59. package/lib/steps/index.d.ts +0 -2
  60. package/lib/steps/index.js +4 -3
  61. package/lib/steps/merge-text-files.d.ts +1 -1
  62. package/lib/steps/merge-text-files.js +6 -2
  63. package/lib/steps/read-files.d.ts +1 -1
  64. package/lib/steps/read-files.js +56 -42
  65. package/lib/steps/read-incoming-config.js +1 -1
  66. package/lib/steps/remove-files.d.ts +1 -1
  67. package/lib/steps/remove-files.js +3 -2
  68. package/lib/steps/rename-files.d.ts +1 -1
  69. package/lib/steps/rename-files.js +3 -2
  70. package/lib/steps/validate-newer-package.d.ts +1 -1
  71. package/lib/steps/validate-newer-package.js +13 -2
  72. package/lib/types/config.d.ts +11 -7
  73. package/lib/types/context.d.ts +23 -3
  74. package/lib/types/context.js +6 -0
  75. package/lib/types/travel.d.ts +1 -0
  76. package/lib/utils/build-journey-plan.d.ts +2 -2
  77. package/lib/utils/build-route.d.ts +1 -1
  78. package/lib/utils/build-route.js +50 -19
  79. package/lib/utils/build-travel-plan.js +1 -0
  80. package/lib/utils/command/merge-and-chains.js +1 -1
  81. package/lib/utils/command/merge-command-records.js +1 -1
  82. package/lib/utils/command/merge-parts-by-prefix.js +12 -1
  83. package/lib/utils/command/merge-semicolon-segments.js +161 -4
  84. package/lib/utils/fnmatch.d.ts +1 -0
  85. package/lib/utils/fnmatch.js +11 -0
  86. package/lib/utils/get-format.js +2 -9
  87. package/lib/utils/load-package.d.ts +6 -0
  88. package/lib/utils/load-package.js +26 -0
  89. package/lib/utils/template.js +1 -3
  90. package/package.json +128 -127
  91. package/lib/journeys/fixpack/index.d.ts +0 -2
  92. package/lib/journeys/fixpack/index.js +0 -16
  93. package/lib/steps/validate-not-present-package.d.ts +0 -3
  94. package/lib/steps/validate-not-present-package.js +0 -24
  95. package/lib/utils/try-json.d.ts +0 -1
  96. package/lib/utils/try-json.js +0 -11
@@ -0,0 +1,50 @@
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.toFormat = toFormat;
37
+ const JSON = __importStar(require("./json.js"));
38
+ const JSONC = __importStar(require("./jsonc/index.js"));
39
+ const YAML = __importStar(require("./yaml.js"));
40
+ function toFormat(value) {
41
+ if (value === 'json') {
42
+ return JSON;
43
+ }
44
+ else if (value === 'yaml') {
45
+ return YAML;
46
+ }
47
+ else {
48
+ return JSONC;
49
+ }
50
+ }
@@ -1,2 +1,4 @@
1
- export declare function parse(data: string): Record<string, unknown>;
2
- export declare function stringify(data: Record<string, unknown>): string;
1
+ import { type ParseResult } from '../types/context.js';
2
+ import { type Transform } from './jsonc/transform.js';
3
+ export declare function parse(data: string): ParseResult;
4
+ export declare function stringify(data: Record<string, unknown>, _transform?: Transform): string;
@@ -5,10 +5,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.parse = parse;
7
7
  exports.stringify = stringify;
8
+ const sync_1 = require("@zokugun/xtry/sync");
8
9
  const yaml_1 = __importDefault(require("yaml"));
9
10
  function parse(data) {
10
- return yaml_1.default.parse(data);
11
+ const result = (0, sync_1.xtry)(() => yaml_1.default.parse(data));
12
+ if (result.fails) {
13
+ return (0, sync_1.err)((0, sync_1.stringifyError)(result.error));
14
+ }
15
+ return (0, sync_1.ok)({ data: result.value });
11
16
  }
12
- function stringify(data) {
17
+ function stringify(data, _transform) {
13
18
  return yaml_1.default.stringify(data);
14
19
  }
@@ -18,6 +18,13 @@ async function command({ current, incoming }) {
18
18
  const incomingCommand = trueAndMatch[1].trim();
19
19
  return currentSegments.has(incomingCommand) ? current : `${current} && ${incomingCommand}`;
20
20
  }
21
+ const incomingAndMatch = /^(.+?)\s*&&\s*(.+)$/.exec(incoming);
22
+ if (incomingAndMatch && !current.includes('&&')) {
23
+ const left = incomingAndMatch[1].trim();
24
+ if (current.trim() === left || currentSegments.has(left)) {
25
+ return incoming;
26
+ }
27
+ }
21
28
  const mixed = (0, index_js_1.mergeWithSemicolonMix)(current, incoming);
22
29
  if (mixed) {
23
30
  return mixed;
@@ -1,8 +1,9 @@
1
1
  export { command } from './command.js';
2
- export { mapConcat } from './map-concat.js';
3
- export { mapDelete } from './map-delete.js';
4
2
  export { linesConcat } from './lines-concat.js';
5
3
  export { listConcat } from './list-concat.js';
6
- export { listSortConcat } from './list-sort-concat.js';
4
+ export { listConcatAfter } from './list-concat-after.js';
5
+ export { mapConcat } from './map-concat.js';
6
+ export { mapDelete } from './map-delete.js';
7
+ export { mergeDotJs } from './merge-dot-js.js';
7
8
  export { overwrite } from './overwrite.js';
8
9
  export { primitive } from './primitive.js';
@@ -1,18 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.primitive = exports.overwrite = exports.listSortConcat = exports.listConcat = exports.linesConcat = exports.mapDelete = exports.mapConcat = exports.command = void 0;
3
+ exports.primitive = exports.overwrite = exports.mergeDotJs = exports.mapDelete = exports.mapConcat = exports.listConcatAfter = exports.listConcat = exports.linesConcat = exports.command = void 0;
4
4
  var command_js_1 = require("./command.js");
5
5
  Object.defineProperty(exports, "command", { enumerable: true, get: function () { return command_js_1.command; } });
6
- var map_concat_js_1 = require("./map-concat.js");
7
- Object.defineProperty(exports, "mapConcat", { enumerable: true, get: function () { return map_concat_js_1.mapConcat; } });
8
- var map_delete_js_1 = require("./map-delete.js");
9
- Object.defineProperty(exports, "mapDelete", { enumerable: true, get: function () { return map_delete_js_1.mapDelete; } });
10
6
  var lines_concat_js_1 = require("./lines-concat.js");
11
7
  Object.defineProperty(exports, "linesConcat", { enumerable: true, get: function () { return lines_concat_js_1.linesConcat; } });
12
8
  var list_concat_js_1 = require("./list-concat.js");
13
9
  Object.defineProperty(exports, "listConcat", { enumerable: true, get: function () { return list_concat_js_1.listConcat; } });
14
- var list_sort_concat_js_1 = require("./list-sort-concat.js");
15
- Object.defineProperty(exports, "listSortConcat", { enumerable: true, get: function () { return list_sort_concat_js_1.listSortConcat; } });
10
+ var list_concat_after_js_1 = require("./list-concat-after.js");
11
+ Object.defineProperty(exports, "listConcatAfter", { enumerable: true, get: function () { return list_concat_after_js_1.listConcatAfter; } });
12
+ var map_concat_js_1 = require("./map-concat.js");
13
+ Object.defineProperty(exports, "mapConcat", { enumerable: true, get: function () { return map_concat_js_1.mapConcat; } });
14
+ var map_delete_js_1 = require("./map-delete.js");
15
+ Object.defineProperty(exports, "mapDelete", { enumerable: true, get: function () { return map_delete_js_1.mapDelete; } });
16
+ var merge_dot_js_js_1 = require("./merge-dot-js.js");
17
+ Object.defineProperty(exports, "mergeDotJs", { enumerable: true, get: function () { return merge_dot_js_js_1.mergeDotJs; } });
16
18
  var overwrite_js_1 = require("./overwrite.js");
17
19
  Object.defineProperty(exports, "overwrite", { enumerable: true, get: function () { return overwrite_js_1.overwrite; } });
18
20
  var primitive_js_1 = require("./primitive.js");
@@ -1,4 +1,4 @@
1
- export declare function listSortConcat({ current, incoming }: {
1
+ export declare function listConcatAfter({ current, incoming }: {
2
2
  current: unknown[] | undefined;
3
3
  incoming: unknown[] | undefined;
4
4
  }): Promise<any[]>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.listSortConcat = listSortConcat;
4
- async function listSortConcat({ current, incoming }) {
3
+ exports.listConcatAfter = listConcatAfter;
4
+ async function listConcatAfter({ current, incoming }) {
5
5
  if (!incoming) {
6
6
  return current ?? [];
7
7
  }
@@ -0,0 +1,2 @@
1
+ import { type Args } from '../types/travel.js';
2
+ export declare function mergeDotJs({ current, incoming }: Args<string>): Promise<string>;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mergeDotJs = mergeDotJs;
4
+ const configdotts_merge_1 = require("@zokugun/configdotts-merge");
5
+ async function mergeDotJs({ current, incoming }) {
6
+ const data = (0, configdotts_merge_1.merge)(current, incoming);
7
+ return data;
8
+ }
@@ -4,7 +4,6 @@ exports.configureInstallFileActions = configureInstallFileActions;
4
4
  const is_it_type_1 = require("@zokugun/is-it-type");
5
5
  const xtry_1 = require("@zokugun/xtry");
6
6
  const micromatch_1 = require("micromatch");
7
- const build_travel_js_1 = require("../utils/build-travel.js");
8
7
  async function configureInstallFileActions(context) {
9
8
  const { install } = context.incomingConfig;
10
9
  if (!install) {
@@ -15,7 +14,7 @@ async function configureInstallFileActions(context) {
15
14
  const routes = {};
16
15
  const transformations = {};
17
16
  for (const file of install) {
18
- const { filter, ifExists, pattern, rename, route, transforms } = file;
17
+ const { filter, ifExists, pattern, rename, transforms } = file;
19
18
  if (rename) {
20
19
  context.renamedPatterns.push({
21
20
  from: pattern,
@@ -39,24 +38,6 @@ async function configureInstallFileActions(context) {
39
38
  if (filter) {
40
39
  filters[pattern] = filter;
41
40
  }
42
- if (route) {
43
- const { alias } = route;
44
- const travel = (0, build_travel_js_1.buildTravel)(route);
45
- if (travel.fails) {
46
- return travel;
47
- }
48
- if (alias) {
49
- routes[pattern] = {
50
- alias,
51
- travel: travel.value,
52
- };
53
- }
54
- else {
55
- routes[pattern] = {
56
- travel: travel.value,
57
- };
58
- }
59
- }
60
41
  if (transforms) {
61
42
  transformations[pattern] = transforms;
62
43
  }
@@ -4,7 +4,6 @@ exports.configureUpdateFileActions = configureUpdateFileActions;
4
4
  const is_it_type_1 = require("@zokugun/is-it-type");
5
5
  const xtry_1 = require("@zokugun/xtry");
6
6
  const micromatch_1 = require("micromatch");
7
- const build_travel_js_1 = require("../utils/build-travel.js");
8
7
  async function configureUpdateFileActions(context) {
9
8
  const { update } = context.incomingConfig;
10
9
  if (update === false) {
@@ -18,7 +17,7 @@ async function configureUpdateFileActions(context) {
18
17
  const routes = {};
19
18
  const transformations = {};
20
19
  for (const file of update) {
21
- const { filter, ifExists, ifMissing, pattern, rename, route, transforms } = file;
20
+ const { filter, ifExists, ifMissing, pattern, rename, transforms } = file;
22
21
  if (rename) {
23
22
  context.renamedPatterns.push({
24
23
  from: pattern,
@@ -45,24 +44,6 @@ async function configureUpdateFileActions(context) {
45
44
  if (filter) {
46
45
  filters[pattern] = filter;
47
46
  }
48
- if (route) {
49
- const { alias } = route;
50
- const travel = (0, build_travel_js_1.buildTravel)(route);
51
- if (travel.fails) {
52
- return travel;
53
- }
54
- if (alias) {
55
- routes[pattern] = {
56
- alias,
57
- travel: travel.value,
58
- };
59
- }
60
- else {
61
- routes[pattern] = {
62
- travel: travel.value,
63
- };
64
- }
65
- }
66
47
  if (transforms) {
67
48
  transformations[pattern] = transforms;
68
49
  }
@@ -23,7 +23,7 @@ async function executeFirstBlock(context) {
23
23
  alias = true;
24
24
  }
25
25
  const variantPath = node_path_1.default.join(context.packagePath, 'variants', variant);
26
- const configResult = await (0, index_js_1.readPackageConfig)(variantPath);
26
+ const configResult = await (0, index_js_1.readPackageConfig)(variantPath, context.global.routes);
27
27
  if (configResult.fails) {
28
28
  return configResult;
29
29
  }
@@ -20,7 +20,6 @@ import { replaceTemplates } from './replace-templates.js';
20
20
  import { transformUntouchedFiles } from './transform-untouched-files.js';
21
21
  import { unmergeTextFiles } from './unmerge-text-files.js';
22
22
  import { validateNewerPackage } from './validate-newer-package.js';
23
- import { validateNotPresentPackage } from './validate-not-present-package.js';
24
23
  import { validatePresentPackage } from './validate-present-package.js';
25
24
  import { writeTextFiles } from './write-text-files.js';
26
25
  export declare const steps: {
@@ -44,7 +43,6 @@ export declare const steps: {
44
43
  transformUntouchedFiles: typeof transformUntouchedFiles;
45
44
  unmergeTextFiles: typeof unmergeTextFiles;
46
45
  validateNewerPackage: typeof validateNewerPackage;
47
- validateNotPresentPackage: typeof validateNotPresentPackage;
48
46
  validatePresentPackage: typeof validatePresentPackage;
49
47
  writeTextFiles: typeof writeTextFiles;
50
48
  };
@@ -4,6 +4,7 @@ exports.steps = void 0;
4
4
  exports.composeSteps = composeSteps;
5
5
  const cli_utils_1 = require("@zokugun/cli-utils");
6
6
  const xtry_1 = require("@zokugun/xtry");
7
+ const context_js_1 = require("../types/context.js");
7
8
  const apply_formatting_js_1 = require("./apply-formatting.js");
8
9
  const configure_branches_js_1 = require("./configure-branches.js");
9
10
  const configure_install_file_actions_js_1 = require("./configure-install-file-actions.js");
@@ -24,7 +25,6 @@ const replace_templates_js_1 = require("./replace-templates.js");
24
25
  const transform_untouched_files_js_1 = require("./transform-untouched-files.js");
25
26
  const unmerge_text_files_js_1 = require("./unmerge-text-files.js");
26
27
  const validate_newer_package_js_1 = require("./validate-newer-package.js");
27
- const validate_not_present_package_js_1 = require("./validate-not-present-package.js");
28
28
  const validate_present_package_js_1 = require("./validate-present-package.js");
29
29
  const write_text_files_js_1 = require("./write-text-files.js");
30
30
  exports.steps = {
@@ -48,12 +48,11 @@ exports.steps = {
48
48
  transformUntouchedFiles: transform_untouched_files_js_1.transformUntouchedFiles,
49
49
  unmergeTextFiles: unmerge_text_files_js_1.unmergeTextFiles,
50
50
  validateNewerPackage: validate_newer_package_js_1.validateNewerPackage,
51
- validateNotPresentPackage: validate_not_present_package_js_1.validateNotPresentPackage,
52
51
  validatePresentPackage: validate_present_package_js_1.validatePresentPackage,
53
52
  writeTextFiles: write_text_files_js_1.writeTextFiles,
54
53
  };
55
54
  function composeSteps(validations, processes) {
56
- const mainFlow = async (targetPath, incomingPath, request, config, options) => {
55
+ const mainFlow = async (targetPath, incomingPath, request, config, global, options) => {
57
56
  const context = {
58
57
  binaryFiles: [],
59
58
  blocks: [],
@@ -61,9 +60,11 @@ function composeSteps(validations, processes) {
61
60
  config,
62
61
  filters: () => undefined,
63
62
  formats: [],
63
+ global,
64
64
  incomingPath,
65
65
  incomingVariant: request.variant,
66
66
  mergedTextFiles: [],
67
+ mode: context_js_1.Mode.Default,
67
68
  onExisting: () => 'merge',
68
69
  onMissing: () => 'continue',
69
70
  options,
@@ -1,3 +1,3 @@
1
1
  import { type AsyncDResult } from '@zokugun/xtry';
2
2
  import { type Context } from '../types/context.js';
3
- export declare function mergeTextFiles({ targetPath, textFiles, mergedTextFiles, onExisting, onMissing, filters, routes, transforms, options }: Context): AsyncDResult;
3
+ export declare function mergeTextFiles({ targetPath, textFiles, mergedTextFiles, onExisting, onMissing, filters, routes, transforms, incomingConfig, global, options }: Context): AsyncDResult;
@@ -11,12 +11,15 @@ const xtry_1 = require("@zokugun/xtry");
11
11
  const index_js_1 = require("../journeys/index.js");
12
12
  const detect_indent_js_1 = require("../utils/detect-indent.js");
13
13
  const has_final_new_line_js_1 = require("../utils/has-final-new-line.js");
14
- async function mergeTextFiles({ targetPath, textFiles, mergedTextFiles, onExisting, onMissing, filters, routes, transforms, options }) {
14
+ async function mergeTextFiles({ targetPath, textFiles, mergedTextFiles, onExisting, onMissing, filters, routes, transforms, incomingConfig, global, options }) {
15
15
  for (const file of textFiles) {
16
16
  if (options.verbose) {
17
17
  cli_utils_1.logger.debug(`${file.name} is going to be merged`);
18
18
  }
19
- const journey = routes(file.name) ?? (0, index_js_1.getJourney)(file.name);
19
+ const journey = routes(file.name)
20
+ ?? (0, index_js_1.getJourney)(file.name, Object.values(incomingConfig.journeys))
21
+ ?? (0, index_js_1.getJourney)(file.name, Object.values(global.journeys))
22
+ ?? (0, index_js_1.getJourney)(file.name);
20
23
  if (!journey) {
21
24
  if (options.verbose) {
22
25
  cli_utils_1.logger.debug(`${file.name}, no merger has been found`);
@@ -85,6 +88,7 @@ async function mergeTextFiles({ targetPath, textFiles, mergedTextFiles, onExisti
85
88
  }
86
89
  case 'overwrite': {
87
90
  mergedTextFiles.push(file);
91
+ global.overwrittenTextFiles.push(fileName);
88
92
  if (options.verbose) {
89
93
  cli_utils_1.logger.debug(`${file.name} has been overwritten`);
90
94
  }
@@ -1,3 +1,3 @@
1
1
  import { type AsyncDResult } from '@zokugun/xtry';
2
2
  import { type Context } from '../types/context.js';
3
- export declare function readFiles({ incomingPath, textFiles, binaryFiles, options }: Context): AsyncDResult;
3
+ export declare function readFiles({ incomingPath, textFiles, binaryFiles, mode, global, options }: Context): AsyncDResult;
@@ -9,63 +9,77 @@ const cli_utils_1 = require("@zokugun/cli-utils");
9
9
  const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
10
10
  const xtry_1 = require("@zokugun/xtry");
11
11
  const istextorbinary_1 = require("istextorbinary");
12
+ const context_js_1 = require("../types/context.js");
12
13
  const detect_indent_js_1 = require("../utils/detect-indent.js");
13
14
  const has_final_new_line_js_1 = require("../utils/has-final-new-line.js");
14
15
  const list_working_files_js_1 = require("../utils/list-working-files.js");
15
16
  const read_buffer_js_1 = require("../utils/read-buffer.js");
16
- async function readFiles({ incomingPath, textFiles, binaryFiles, options }) {
17
+ async function readFiles({ incomingPath, textFiles, binaryFiles, mode, global, options }) {
17
18
  const cwd = path_1.default.join(incomingPath, 'configs');
18
19
  const files = await (0, list_working_files_js_1.listWorkingFiles)(cwd);
19
- for (const file of files) {
20
- const filePath = path_1.default.join(cwd, file);
21
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call
22
- if ((0, istextorbinary_1.isText)(file) || (0, istextorbinary_1.getEncoding)(await (0, read_buffer_js_1.readBuffer)(filePath, 24)) === 'utf8') {
23
- const result = await async_1.default.readFile(filePath, 'utf8');
24
- if (result.fails) {
25
- return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
26
- }
27
- const data = result.value;
28
- const finalNewLine = (0, has_final_new_line_js_1.hasFinalNewLine)(data);
29
- const indent = (0, detect_indent_js_1.detectIndent)(data);
30
- if (data.startsWith('#!')) {
31
- // the text file might be executable
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;
37
- textFiles.push({
38
- name: file,
39
- data,
40
- finalNewLine,
41
- indent,
42
- mode,
43
- });
44
- if (options.verbose) {
45
- cli_utils_1.logger.debug(`${file} is a shebang file`);
46
- }
20
+ if (mode === context_js_1.Mode.Default) {
21
+ for (const file of files) {
22
+ const filePath = path_1.default.join(cwd, file);
23
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
24
+ if ((0, istextorbinary_1.isText)(file) || (0, istextorbinary_1.getEncoding)(await (0, read_buffer_js_1.readBuffer)(filePath, 24)) === 'utf8') {
25
+ await readTextFile(file, filePath, textFiles, options);
47
26
  }
48
27
  else {
49
- textFiles.push({
50
- name: file,
51
- data,
52
- finalNewLine,
53
- indent,
28
+ binaryFiles.push({
29
+ source: file,
30
+ target: file,
54
31
  });
55
32
  if (options.verbose) {
56
- cli_utils_1.logger.debug(`${file} is a text file`);
33
+ cli_utils_1.logger.debug(`${file} is a binary file`);
57
34
  }
58
35
  }
59
36
  }
60
- else {
61
- binaryFiles.push({
62
- source: file,
63
- target: file,
64
- });
65
- if (options.verbose) {
66
- cli_utils_1.logger.debug(`${file} is a binary file`);
37
+ }
38
+ else {
39
+ for (const file of files) {
40
+ if (global.overwrittenTextFiles.includes(file)) {
41
+ const filePath = path_1.default.join(cwd, file);
42
+ await readTextFile(file, filePath, textFiles, options);
67
43
  }
68
44
  }
69
45
  }
70
46
  return xtry_1.OK;
71
47
  }
48
+ async function readTextFile(file, filePath, textFiles, options) {
49
+ const result = await async_1.default.readFile(filePath, 'utf8');
50
+ if (result.fails) {
51
+ return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
52
+ }
53
+ const data = result.value;
54
+ const finalNewLine = (0, has_final_new_line_js_1.hasFinalNewLine)(data);
55
+ const indent = (0, detect_indent_js_1.detectIndent)(data);
56
+ if (data.startsWith('#!')) {
57
+ // the text file might be executable
58
+ const result = await async_1.default.stat(filePath);
59
+ if (result.fails) {
60
+ return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
61
+ }
62
+ const { mode } = result.value;
63
+ textFiles.push({
64
+ name: file,
65
+ data,
66
+ finalNewLine,
67
+ indent,
68
+ mode,
69
+ });
70
+ if (options.verbose) {
71
+ cli_utils_1.logger.debug(`${file} is a shebang file`);
72
+ }
73
+ }
74
+ else {
75
+ textFiles.push({
76
+ name: file,
77
+ data,
78
+ finalNewLine,
79
+ indent,
80
+ });
81
+ if (options.verbose) {
82
+ cli_utils_1.logger.debug(`${file} is a text file`);
83
+ }
84
+ }
85
+ } // }}}
@@ -5,7 +5,7 @@ const xtry_1 = require("@zokugun/xtry");
5
5
  const index_js_1 = require("../configs/index.js");
6
6
  async function readIncomingConfig(context) {
7
7
  if (!context.incomingConfig) {
8
- const config = await (0, index_js_1.readPackageConfig)(context.incomingPath);
8
+ const config = await (0, index_js_1.readPackageConfig)(context.incomingPath, context.global.routes);
9
9
  if (config.fails) {
10
10
  return config;
11
11
  }
@@ -1,3 +1,3 @@
1
1
  import { type AsyncDResult } from '@zokugun/xtry';
2
2
  import { type Context } from '../types/context.js';
3
- export declare function removeFiles({ removedPatterns, targetPath, options }: Context): AsyncDResult;
3
+ export declare function removeFiles({ removedPatterns, targetPath, mode, options }: Context): AsyncDResult;
@@ -9,9 +9,10 @@ const cli_utils_1 = require("@zokugun/cli-utils");
9
9
  const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
10
10
  const xtry_1 = require("@zokugun/xtry");
11
11
  const micromatch_1 = require("micromatch");
12
+ const context_js_1 = require("../types/context.js");
12
13
  const list_working_files_js_1 = require("../utils/list-working-files.js");
13
- async function removeFiles({ removedPatterns, targetPath, options }) {
14
- if (removedPatterns.length === 0) {
14
+ async function removeFiles({ removedPatterns, targetPath, mode, options }) {
15
+ if (removedPatterns.length === 0 || mode !== context_js_1.Mode.Default) {
15
16
  return xtry_1.OK;
16
17
  }
17
18
  const cwd = path_1.default.join(targetPath);
@@ -1,3 +1,3 @@
1
1
  import { type AsyncDResult } from '@zokugun/xtry';
2
2
  import { type Context } from '../types/context.js';
3
- export declare function renameFiles({ renamedPatterns, targetPath }: Context): AsyncDResult;
3
+ export declare function renameFiles({ renamedPatterns, targetPath, mode }: Context): AsyncDResult;
@@ -7,8 +7,9 @@ exports.renameFiles = renameFiles;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
9
9
  const xtry_1 = require("@zokugun/xtry");
10
- async function renameFiles({ renamedPatterns, targetPath }) {
11
- if (renamedPatterns.length === 0) {
10
+ const context_js_1 = require("../types/context.js");
11
+ async function renameFiles({ renamedPatterns, targetPath, mode }) {
12
+ if (renamedPatterns.length === 0 || mode !== context_js_1.Mode.Default) {
12
13
  return xtry_1.OK;
13
14
  }
14
15
  const cwd = path_1.default.join(targetPath);
@@ -1,3 +1,3 @@
1
1
  import { type AsyncDResult } from '@zokugun/xtry';
2
2
  import { type Context } from '../types/context.js';
3
- export declare function validateNewerPackage({ incomingPackage, config, options }: Context): AsyncDResult<boolean | void>;
3
+ export declare function validateNewerPackage(context: Context): AsyncDResult<boolean | void>;
@@ -3,13 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateNewerPackage = validateNewerPackage;
4
4
  const xtry_1 = require("@zokugun/xtry");
5
5
  const semver_1 = require("semver");
6
- async function validateNewerPackage({ incomingPackage, config, options }) {
6
+ const context_js_1 = require("../types/context.js");
7
+ async function validateNewerPackage(context) {
8
+ const { incomingPackage, config, global, options } = context;
7
9
  if (options.force) {
8
10
  return xtry_1.OK;
9
11
  }
10
12
  const artifact = config.artifacts[incomingPackage.name];
11
13
  if (artifact) {
12
- return (0, xtry_1.ok)(!(0, semver_1.gt)(incomingPackage.version, artifact.version));
14
+ const newer = (0, semver_1.gt)(incomingPackage.version, artifact.version);
15
+ if (newer) {
16
+ return xtry_1.OK_FALSE;
17
+ }
18
+ else if (global.overwrittenTextFiles.length > 0) {
19
+ context.mode = context_js_1.Mode.Overwritten;
20
+ }
21
+ else {
22
+ return xtry_1.OK_TRUE;
23
+ }
13
24
  }
14
25
  return xtry_1.OK;
15
26
  }
@@ -1,5 +1,6 @@
1
1
  import { type Primitive } from '@zokugun/is-it-type';
2
2
  import { type Indent } from './format.js';
3
+ import { type JourneyPlan, type Route } from './travel.js';
3
4
  export type Request = {
4
5
  name: string;
5
6
  variant?: string;
@@ -11,7 +12,9 @@ export type PackageManifest = {
11
12
  export type PackageConfig = {
12
13
  extends?: string;
13
14
  install: InstallFileConfig[];
15
+ journeys: Record<string, JourneyPlan>;
14
16
  orphan: boolean;
17
+ routes: Record<string, Route<any>>;
15
18
  uninstall: UninstallFileConfig[];
16
19
  update: false | UpdateFileConfig[];
17
20
  variables: Record<string, Primitive>;
@@ -26,8 +29,16 @@ export type ArtifactResult = Artifact & {
26
29
  name: string;
27
30
  };
28
31
  export type InstallConfig = {
32
+ file: {
33
+ name: string;
34
+ finalNewLine: boolean;
35
+ indent?: Indent;
36
+ type: string;
37
+ };
29
38
  artifacts: Record<string, Artifact>;
30
39
  install: Record<string, InstallFileConfig>;
40
+ journeys: Record<string, JourneyPlan>;
41
+ routes: Record<string, Route<any>>;
31
42
  update: false | Record<string, UpdateFileConfig>;
32
43
  variables: Record<string, Primitive>;
33
44
  };
@@ -44,15 +55,8 @@ export type UpsertFileConfig = AlwaysFileConfig & {
44
55
  filter?: string[];
45
56
  ifMissing: 'merge' | 'skip';
46
57
  rename?: string;
47
- route?: Record<string, any>;
48
58
  };
49
59
  export type FileTransform = {
50
60
  description?: string;
51
61
  jq: string;
52
62
  };
53
- export type InstallConfigStats = {
54
- name: string;
55
- type: string;
56
- finalNewLine: boolean;
57
- indent?: Indent;
58
- };