@zokugun/artifact 0.3.1 → 0.4.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 (66) hide show
  1. package/README.md +122 -37
  2. package/lib/cli.js +8 -2
  3. package/lib/commands/add.js +37 -44
  4. package/lib/commands/index.js +3 -1
  5. package/lib/commands/list.js +46 -0
  6. package/lib/commands/update.js +34 -20
  7. package/lib/compositors/compose.js +7 -12
  8. package/lib/compositors/fork.js +1 -2
  9. package/lib/compositors/json.js +18 -9
  10. package/lib/compositors/map-sort.js +1 -2
  11. package/lib/compositors/rc.js +18 -9
  12. package/lib/compositors/yaml.js +18 -9
  13. package/lib/configs/index.js +18 -0
  14. package/lib/configs/install/index.js +9 -0
  15. package/lib/configs/install/read-install-config.js +120 -0
  16. package/lib/configs/install/update-install-config.js +15 -0
  17. package/lib/{config/write-config.js → configs/install/write-install-config.js} +8 -9
  18. package/lib/configs/package/index.js +5 -0
  19. package/lib/{config/read-config.js → configs/package/read-package-config.js} +14 -32
  20. package/lib/journeys/config.ts/index.js +11 -0
  21. package/lib/journeys/index.js +3 -2
  22. package/lib/journeys/package/index.js +0 -1
  23. package/lib/parsers/json.js +2 -3
  24. package/lib/parsers/jsonc/parse.js +2 -3
  25. package/lib/parsers/jsonc/stringify.js +1 -2
  26. package/lib/parsers/yaml.js +2 -3
  27. package/lib/routes/command.js +1 -2
  28. package/lib/routes/lines-concat.js +1 -2
  29. package/lib/routes/list-concat.js +1 -2
  30. package/lib/routes/list-sort-concat.js +1 -2
  31. package/lib/routes/map-concat.js +1 -2
  32. package/lib/routes/overwrite.js +1 -2
  33. package/lib/routes/primitive.js +1 -2
  34. package/lib/steps/apply-formatting.js +5 -6
  35. package/lib/steps/configure-branches.js +69 -0
  36. package/lib/steps/configure-install-file-actions.js +151 -0
  37. package/lib/steps/{validate-updatability.js → configure-update-file-actions.js} +9 -10
  38. package/lib/steps/copy-binary-files.js +21 -13
  39. package/lib/steps/execute-first-block.js +112 -0
  40. package/lib/steps/execute-next-block.js +22 -0
  41. package/lib/steps/index.js +47 -9
  42. package/lib/steps/insert-final-new-line.js +3 -4
  43. package/lib/steps/merge-text-files.js +65 -36
  44. package/lib/steps/read-editor-config.js +22 -13
  45. package/lib/steps/read-files.js +3 -4
  46. package/lib/steps/read-incoming-config.js +9 -5
  47. package/lib/steps/read-incoming-package.js +12 -4
  48. package/lib/steps/remove-files.js +40 -0
  49. package/lib/steps/replace-templates.js +3 -4
  50. package/lib/steps/validate-newer-package.js +4 -5
  51. package/lib/steps/validate-not-present-package.js +4 -5
  52. package/lib/steps/write-text-files.js +3 -4
  53. package/lib/types/format.js +1 -1
  54. package/lib/utils/build-journey-plan.js +1 -2
  55. package/lib/utils/build-travel-plan.js +1 -2
  56. package/lib/utils/command/join-command.js +1 -2
  57. package/lib/utils/command/split-command.js +1 -2
  58. package/lib/utils/dev-null.js +1 -2
  59. package/lib/utils/read-buffer.js +5 -8
  60. package/lib/utils/resolve-request.js +42 -0
  61. package/lib/utils/template.js +21 -10
  62. package/lib/utils/to-lines.js +1 -2
  63. package/lib/utils/trim-final-newline.js +1 -2
  64. package/lib/utils/try-json.js +1 -2
  65. package/package.json +6 -4
  66. package/lib/config/index.js +0 -7
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.configureInstallFileActions = configureInstallFileActions;
13
+ const lodash_1 = require("lodash");
14
+ const micromatch_1 = require("micromatch");
15
+ const compositors_1 = require("../compositors");
16
+ const routes_1 = require("../routes");
17
+ function buildRoute(route) {
18
+ if (Array.isArray(route) && route.length > 0) {
19
+ let result = buildRoute(route[0]);
20
+ for (let i = 1; i < route.length; i++) {
21
+ if (route[i] === 'mapSort') {
22
+ result = (0, compositors_1.mapSort)(result);
23
+ }
24
+ else {
25
+ throw new Error('Can\'t build route');
26
+ }
27
+ }
28
+ return result;
29
+ }
30
+ else if ((0, lodash_1.isPlainObject)(route)) {
31
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
32
+ const { compose: rtCompose, fork: rtFork, mapSort: rtMapSort } = route;
33
+ if (rtCompose) {
34
+ const map = {};
35
+ for (const [name, route] of Object.entries(rtCompose)) {
36
+ map[name] = buildRoute(route);
37
+ }
38
+ return (0, compositors_1.compose)(map);
39
+ }
40
+ else if (rtFork) {
41
+ const map = [];
42
+ if (rtFork.array) {
43
+ map.push([Array.isArray, buildRoute(rtFork.array)]);
44
+ }
45
+ if (rtFork.object) {
46
+ map.push([lodash_1.isPlainObject, buildRoute(rtFork.object)]);
47
+ }
48
+ if (rtFork.default) {
49
+ map.push(buildRoute(rtFork.default));
50
+ }
51
+ return (0, compositors_1.fork)(...map);
52
+ }
53
+ else if (rtMapSort) {
54
+ return (0, compositors_1.mapSort)(buildRoute(rtMapSort));
55
+ }
56
+ }
57
+ else if (route === 'command') {
58
+ return routes_1.command;
59
+ }
60
+ else if (route === 'linesConcat') {
61
+ return routes_1.linesConcat;
62
+ }
63
+ else if (route === 'listConcat') {
64
+ return routes_1.listConcat;
65
+ }
66
+ else if (route === 'mapConcat') {
67
+ return routes_1.mapConcat;
68
+ }
69
+ else if (route === 'overwrite') {
70
+ return routes_1.overwrite;
71
+ }
72
+ else if (route === 'primitive') {
73
+ return routes_1.primitive;
74
+ }
75
+ throw new Error('Can\'t build route');
76
+ } // }}}
77
+ function buildTravel(route) {
78
+ if (route.json) {
79
+ return (0, compositors_1.json)(buildRoute(route.json));
80
+ }
81
+ else if (route.rc) {
82
+ return (0, compositors_1.rc)(buildRoute(route.json));
83
+ }
84
+ else if (route.yaml) {
85
+ return (0, compositors_1.yaml)(buildRoute(route.json));
86
+ }
87
+ else {
88
+ throw new Error('Can\'t build route');
89
+ }
90
+ } // }}}
91
+ function configureInstallFileActions(context) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ const { install } = context.incomingConfig;
94
+ if (!install) {
95
+ return;
96
+ }
97
+ const overwritings = [];
98
+ const filters = {};
99
+ const routes = {};
100
+ for (const [file, fileUpdate] of Object.entries(install)) {
101
+ const { overwrite, remove, filter, route } = fileUpdate;
102
+ if (remove) {
103
+ context.removedPatterns.push(file);
104
+ continue;
105
+ }
106
+ if (overwrite) {
107
+ overwritings.push(file);
108
+ }
109
+ if (filter) {
110
+ filters[file] = filter;
111
+ }
112
+ if (route) {
113
+ const { alias } = route;
114
+ if (alias) {
115
+ routes[file] = {
116
+ alias,
117
+ travel: buildTravel(route),
118
+ };
119
+ }
120
+ else {
121
+ routes[file] = {
122
+ travel: buildTravel(route),
123
+ };
124
+ }
125
+ }
126
+ }
127
+ if (overwritings.length > 0) {
128
+ context.onExisting = (file) => (0, micromatch_1.isMatch)(file, overwritings) ? 'overwrite' : 'merge';
129
+ }
130
+ if (!(0, lodash_1.isEmpty)(filters)) {
131
+ context.filters = (file) => {
132
+ for (const [pattern, value] of Object.entries(filters)) {
133
+ if ((0, micromatch_1.isMatch)(file, pattern)) {
134
+ return value;
135
+ }
136
+ }
137
+ return undefined;
138
+ };
139
+ }
140
+ if (!(0, lodash_1.isEmpty)(routes)) {
141
+ context.routes = (file) => {
142
+ for (const [pattern, route] of Object.entries(routes)) {
143
+ if ((0, micromatch_1.isMatch)(file, pattern)) {
144
+ return route;
145
+ }
146
+ }
147
+ return undefined;
148
+ };
149
+ }
150
+ });
151
+ }
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.validateUpdatability = void 0;
12
+ exports.configureUpdateFileActions = configureUpdateFileActions;
13
13
  const lodash_1 = require("lodash");
14
14
  const micromatch_1 = require("micromatch");
15
15
  const compositors_1 = require("../compositors");
@@ -88,18 +88,18 @@ function buildTravel(route) {
88
88
  throw new Error('Can\'t build route');
89
89
  }
90
90
  } // }}}
91
- function validateUpdatability(context) {
91
+ function configureUpdateFileActions(context) {
92
92
  return __awaiter(this, void 0, void 0, function* () {
93
93
  const { update } = context.incomingConfig;
94
94
  if (typeof update === 'boolean') {
95
95
  if (!update) {
96
- context.onMissing = () => true;
97
- context.onUpdate = () => true;
96
+ context.onExisting = () => 'skip';
97
+ context.onMissing = () => 'skip';
98
98
  }
99
99
  }
100
100
  else if ((0, lodash_1.isPlainObject)(update)) {
101
+ const existings = [];
101
102
  const missings = [];
102
- const updates = [];
103
103
  const filters = {};
104
104
  const routes = {};
105
105
  for (const [file, fileUpdate] of Object.entries(update)) {
@@ -108,7 +108,7 @@ function validateUpdatability(context) {
108
108
  missings.push(file);
109
109
  }
110
110
  if (update === false) {
111
- updates.push(file);
111
+ existings.push(file);
112
112
  }
113
113
  if (filter) {
114
114
  filters[file] = filter;
@@ -129,10 +129,10 @@ function validateUpdatability(context) {
129
129
  }
130
130
  }
131
131
  if (missings.length > 0) {
132
- context.onMissing = (file) => (0, micromatch_1.isMatch)(file, missings);
132
+ context.onMissing = (file) => (0, micromatch_1.isMatch)(file, missings) ? 'skip' : 'continue';
133
133
  }
134
- if (updates.length > 0) {
135
- context.onUpdate = (file) => (0, micromatch_1.isMatch)(file, updates);
134
+ if (existings.length > 0) {
135
+ context.onExisting = (file) => (0, micromatch_1.isMatch)(file, existings) ? 'skip' : 'merge';
136
136
  }
137
137
  if (!(0, lodash_1.isEmpty)(filters)) {
138
138
  context.filters = (file) => {
@@ -157,4 +157,3 @@ function validateUpdatability(context) {
157
157
  }
158
158
  });
159
159
  }
160
- exports.validateUpdatability = validateUpdatability;
@@ -12,26 +12,35 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.copyBinaryFiles = void 0;
15
+ exports.copyBinaryFiles = copyBinaryFiles;
16
16
  const path_1 = __importDefault(require("path"));
17
17
  const fs_extra_1 = __importDefault(require("fs-extra"));
18
- function copyBinaryFiles({ binaryFiles, incomingPath, targetPath, onMissing, onUpdate, options }) {
19
- return __awaiter(this, void 0, void 0, function* () {
18
+ function copyBinaryFiles(_a) {
19
+ return __awaiter(this, arguments, void 0, function* ({ binaryFiles, incomingPath, targetPath, onExisting, onMissing, options }) {
20
20
  const cwd = path_1.default.join(incomingPath, 'configs');
21
21
  for (const file of binaryFiles) {
22
- try {
23
- yield fs_extra_1.default.access(path_1.default.join(targetPath, file.source));
24
- if (onUpdate(file.source)) {
25
- continue;
22
+ const source = path_1.default.join(cwd, file.source);
23
+ const target = path_1.default.join(targetPath, file.target);
24
+ const exists = yield fs_extra_1.default.pathExists(target);
25
+ if (exists) {
26
+ switch (onExisting(file.source)) {
27
+ case 'merge':
28
+ break;
29
+ case 'overwrite':
30
+ break;
31
+ case 'skip':
32
+ continue;
26
33
  }
27
34
  }
28
- catch (_a) {
29
- if (onMissing(file.source)) {
30
- continue;
35
+ else {
36
+ switch (onMissing(file.source)) {
37
+ case 'continue':
38
+ break;
39
+ case 'skip':
40
+ continue;
31
41
  }
32
42
  }
33
- const source = path_1.default.join(cwd, file.source);
34
- const target = path_1.default.join(targetPath, file.target);
43
+ yield fs_extra_1.default.ensureFile(target);
35
44
  yield fs_extra_1.default.copyFile(source, target);
36
45
  if (options.verbose) {
37
46
  console.log(`${file.target} has been written as a binary file`);
@@ -39,4 +48,3 @@ function copyBinaryFiles({ binaryFiles, incomingPath, targetPath, onMissing, onU
39
48
  }
40
49
  });
41
50
  }
42
- exports.copyBinaryFiles = copyBinaryFiles;
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.executeFirstBlock = executeFirstBlock;
16
+ const node_path_1 = __importDefault(require("node:path"));
17
+ const lodash_1 = require("lodash");
18
+ const configs_1 = require("../configs");
19
+ function executeFirstBlock(context) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ var _a, _b, _c, _d;
22
+ const { name, version } = context.incomingPackage;
23
+ const root = String((_b = (_a = context.incomingConfig.variants) === null || _a === void 0 ? void 0 : _a.root) !== null && _b !== void 0 ? _b : '');
24
+ if (context.incomingVariant) {
25
+ let variant;
26
+ let alias;
27
+ if ((0, lodash_1.isNil)(context.incomingConfig.variants[context.incomingVariant])) {
28
+ variant = context.incomingVariant;
29
+ alias = false;
30
+ }
31
+ else {
32
+ variant = String(context.incomingConfig.variants[context.incomingVariant]);
33
+ alias = true;
34
+ }
35
+ const variantPath = node_path_1.default.join(context.packagePath, 'variants', variant);
36
+ const variantConfig = yield (0, configs_1.readPackageConfig)(variantPath);
37
+ if (variantConfig.orphan) {
38
+ pushToResult(name, version, variant, alias, context);
39
+ context.incomingConfig = variantConfig;
40
+ yield context.commonFlow(name, version, variant, undefined, variantPath, context);
41
+ }
42
+ else if (variantConfig.extends) {
43
+ context.blocks.unshift({
44
+ name,
45
+ version,
46
+ variant,
47
+ incomingPath: node_path_1.default.join(context.packagePath, 'variants', variant),
48
+ });
49
+ pushToResult(name, version, variant, alias, context);
50
+ const extend = String((_c = context.incomingConfig.variants[variantConfig.extends]) !== null && _c !== void 0 ? _c : variantConfig.extends);
51
+ context.incomingVariant = extend;
52
+ return executeFirstBlock(context);
53
+ }
54
+ else {
55
+ if (root.length === 0) {
56
+ throw new Error('No root variant has been defined');
57
+ }
58
+ if (root === variant) {
59
+ pushToResult(name, version, variant, alias, context);
60
+ context.incomingConfig = variantConfig;
61
+ yield context.commonFlow(name, version, variant, undefined, variantPath, context);
62
+ }
63
+ else {
64
+ const variant = String((_d = context.incomingConfig.variants[context.request.variant]) !== null && _d !== void 0 ? _d : context.request.variant);
65
+ context.blocks.unshift({
66
+ name,
67
+ version,
68
+ variant,
69
+ incomingPath: node_path_1.default.join(context.packagePath, 'variants', variant),
70
+ });
71
+ pushToResult(name, version, variant, alias, context);
72
+ const incomingPath = node_path_1.default.join(context.packagePath, 'variants', root);
73
+ context.incomingConfig = undefined;
74
+ yield context.commonFlow(name, version, root, undefined, incomingPath, context);
75
+ }
76
+ }
77
+ }
78
+ else if (root.length > 0) {
79
+ context.result = {
80
+ name,
81
+ version,
82
+ provides: [root],
83
+ };
84
+ const incomingPath = node_path_1.default.join(context.packagePath, 'variants', root);
85
+ context.incomingConfig = undefined;
86
+ yield context.commonFlow(name, version, root, undefined, incomingPath, context);
87
+ }
88
+ else {
89
+ context.result = { name, version };
90
+ yield context.commonFlow(name, version, undefined, undefined, context.incomingPath, context);
91
+ }
92
+ });
93
+ }
94
+ function pushToResult(name, version, variant, alias, context) {
95
+ var _a, _b;
96
+ var _c;
97
+ (_a = context.result) !== null && _a !== void 0 ? _a : (context.result = {
98
+ name,
99
+ version,
100
+ requires: [context.request.variant],
101
+ });
102
+ const provider = context.incomingVariant !== context.request.variant;
103
+ if (provider || alias) {
104
+ (_b = (_c = context.result).provides) !== null && _b !== void 0 ? _b : (_c.provides = []);
105
+ if (provider) {
106
+ context.result.provides.unshift(context.incomingVariant);
107
+ }
108
+ if (alias) {
109
+ context.result.provides.unshift(variant);
110
+ }
111
+ }
112
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.executeNextBlock = executeNextBlock;
13
+ const lodash_1 = require("lodash");
14
+ function executeNextBlock(context) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const block = context.blocks.shift();
17
+ if (!(0, lodash_1.isNil)(block)) {
18
+ const { name, version, variant, branch, incomingPath } = block;
19
+ yield context.commonFlow(name, version, variant, branch, incomingPath, context);
20
+ }
21
+ });
22
+ }
@@ -9,53 +9,70 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.composeSteps = exports.steps = void 0;
12
+ exports.steps = void 0;
13
+ exports.composeSteps = composeSteps;
13
14
  const apply_formatting_1 = require("./apply-formatting");
15
+ const configure_branches_1 = require("./configure-branches");
16
+ const configure_install_file_actions_1 = require("./configure-install-file-actions");
17
+ const configure_update_file_actions_1 = require("./configure-update-file-actions");
14
18
  const copy_binary_files_1 = require("./copy-binary-files");
19
+ const execute_first_block_1 = require("./execute-first-block");
20
+ const execute_next_block_1 = require("./execute-next-block");
15
21
  const insert_final_new_line_1 = require("./insert-final-new-line");
16
22
  const merge_text_files_1 = require("./merge-text-files");
17
23
  const read_editor_config_1 = require("./read-editor-config");
18
24
  const read_files_1 = require("./read-files");
19
25
  const read_incoming_config_1 = require("./read-incoming-config");
20
26
  const read_incoming_package_1 = require("./read-incoming-package");
27
+ const remove_files_1 = require("./remove-files");
21
28
  const replace_templates_1 = require("./replace-templates");
22
29
  const validate_newer_package_1 = require("./validate-newer-package");
23
30
  const validate_not_present_package_1 = require("./validate-not-present-package");
24
- const validate_updatability_1 = require("./validate-updatability");
25
31
  const write_text_files_1 = require("./write-text-files");
26
32
  exports.steps = {
27
33
  applyFormatting: apply_formatting_1.applyFormatting,
34
+ configureBranches: configure_branches_1.configureBranches,
35
+ configureInstallFileActions: configure_install_file_actions_1.configureInstallFileActions,
36
+ configureUpdateFileActions: configure_update_file_actions_1.configureUpdateFileActions,
28
37
  copyBinaryFiles: copy_binary_files_1.copyBinaryFiles,
38
+ executeFirstBlock: execute_first_block_1.executeFirstBlock,
39
+ executeNextBlock: execute_next_block_1.executeNextBlock,
29
40
  insertFinalNewLine: insert_final_new_line_1.insertFinalNewLine,
30
41
  mergeTextFiles: merge_text_files_1.mergeTextFiles,
31
42
  readEditorConfig: read_editor_config_1.readEditorConfig,
32
43
  readFiles: read_files_1.readFiles,
33
44
  readIncomingConfig: read_incoming_config_1.readIncomingConfig,
34
45
  readIncomingPackage: read_incoming_package_1.readIncomingPackage,
46
+ removeFiles: remove_files_1.removeFiles,
35
47
  replaceTemplates: replace_templates_1.replaceTemplates,
36
48
  validateNewerPackage: validate_newer_package_1.validateNewerPackage,
37
49
  validateNotPresentPackage: validate_not_present_package_1.validateNotPresentPackage,
38
- validateUpdatability: validate_updatability_1.validateUpdatability,
39
50
  writeTextFiles: write_text_files_1.writeTextFiles,
40
51
  };
41
- function composeSteps(...steps) {
42
- return (targetPath, incomingPath, config, options) => __awaiter(this, void 0, void 0, function* () {
52
+ function composeSteps(validations, processes) {
53
+ const mainFlow = (targetPath, incomingPath, request, config, options) => __awaiter(this, void 0, void 0, function* () {
43
54
  const context = {
55
+ packagePath: incomingPath,
56
+ request,
44
57
  targetPath,
45
58
  incomingPath,
46
- onMissing: () => false,
47
- onUpdate: () => false,
59
+ incomingVariant: request.variant,
60
+ onExisting: () => 'merge',
61
+ onMissing: () => 'continue',
48
62
  filters: () => undefined,
49
63
  routes: () => undefined,
50
64
  binaryFiles: [],
51
65
  textFiles: [],
52
66
  mergedTextFiles: [],
67
+ removedPatterns: [],
53
68
  formats: [],
54
69
  config,
55
70
  options,
71
+ commonFlow,
72
+ blocks: [],
56
73
  };
57
74
  let skipped = false;
58
- for (const step of steps) {
75
+ for (const step of validations) {
59
76
  if (yield step(context)) {
60
77
  skipped = true;
61
78
  break;
@@ -63,5 +80,26 @@ function composeSteps(...steps) {
63
80
  }
64
81
  return skipped ? undefined : context;
65
82
  });
83
+ const commonFlow = (name, version, variant, branch, incomingPath, mainContext) => __awaiter(this, void 0, void 0, function* () {
84
+ if (mainContext.options.verbose) {
85
+ let message = `\n---> ${name} version=${version}`;
86
+ if (variant) {
87
+ message += ` variant=${variant}`;
88
+ }
89
+ if (branch) {
90
+ message += ` branch=${branch}`;
91
+ }
92
+ console.log(message);
93
+ }
94
+ const context = Object.assign(Object.assign({}, mainContext), { incomingPath, incomingName: name, incomingVersion: version, incomingVariant: variant, incomingBranch: branch, incomingConfig: undefined, onExisting: () => 'merge', onMissing: () => 'continue', filters: () => undefined, routes: () => undefined, binaryFiles: [], textFiles: [], mergedTextFiles: [], formats: [] });
95
+ let skipped = false;
96
+ for (const step of processes) {
97
+ if (yield step(context)) {
98
+ skipped = true;
99
+ break;
100
+ }
101
+ }
102
+ return skipped ? undefined : context;
103
+ });
104
+ return { mainFlow, commonFlow };
66
105
  }
67
- exports.composeSteps = composeSteps;
@@ -9,9 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.insertFinalNewLine = void 0;
13
- function insertFinalNewLine({ mergedTextFiles }) {
14
- return __awaiter(this, void 0, void 0, function* () {
12
+ exports.insertFinalNewLine = insertFinalNewLine;
13
+ function insertFinalNewLine(_a) {
14
+ return __awaiter(this, arguments, void 0, function* ({ mergedTextFiles }) {
15
15
  for (const file of mergedTextFiles) {
16
16
  if (file.finalNewLine) {
17
17
  const withFinalNewLine = file.data.endsWith('\n');
@@ -22,4 +22,3 @@ function insertFinalNewLine({ mergedTextFiles }) {
22
22
  }
23
23
  });
24
24
  }
25
- exports.insertFinalNewLine = insertFinalNewLine;
@@ -12,67 +12,96 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.mergeTextFiles = void 0;
15
+ exports.mergeTextFiles = mergeTextFiles;
16
16
  const path_1 = __importDefault(require("path"));
17
17
  const fs_extra_1 = __importDefault(require("fs-extra"));
18
18
  const journeys_1 = require("../journeys");
19
- function mergeTextFiles({ targetPath, textFiles, mergedTextFiles, onMissing, onUpdate, filters, routes, options }) {
20
- var _a;
21
- return __awaiter(this, void 0, void 0, function* () {
19
+ function mergeTextFiles(_a) {
20
+ return __awaiter(this, arguments, void 0, function* ({ targetPath, textFiles, mergedTextFiles, onExisting, onMissing, filters, routes, options }) {
21
+ var _b;
22
22
  for (const file of textFiles) {
23
23
  if (options.verbose) {
24
24
  console.log(`${file.name} is going to be merged`);
25
25
  }
26
- const journey = (_a = routes(file.name)) !== null && _a !== void 0 ? _a : (0, journeys_1.getJourney)(file.name);
26
+ const journey = (_b = routes(file.name)) !== null && _b !== void 0 ? _b : (0, journeys_1.getJourney)(file.name);
27
27
  if (!journey) {
28
28
  if (options.verbose) {
29
29
  console.log(`${file.name}, no merger has been found`);
30
30
  }
31
- try {
32
- yield fs_extra_1.default.access(path_1.default.join(targetPath, file.name));
33
- if (onUpdate(file.name)) {
34
- continue;
31
+ const filePath = path_1.default.join(targetPath, file.name);
32
+ const exists = yield fs_extra_1.default.pathExists(filePath);
33
+ if (exists) {
34
+ switch (onExisting(file.name)) {
35
+ case 'merge':
36
+ break;
37
+ case 'overwrite':
38
+ break;
39
+ case 'skip':
40
+ continue;
35
41
  }
36
42
  }
37
- catch (_b) {
38
- if (onMissing(file.name)) {
39
- continue;
43
+ else {
44
+ switch (onMissing(file.name)) {
45
+ case 'continue':
46
+ break;
47
+ case 'skip':
48
+ continue;
40
49
  }
41
50
  }
42
51
  mergedTextFiles.push(file);
52
+ if (options.verbose) {
53
+ console.log(`${file.name} has been copied`);
54
+ }
43
55
  continue;
44
56
  }
45
57
  if (options.verbose) {
46
58
  console.log(`${file.name}, a merger has been found`);
47
59
  }
48
- const name = journey.alias ? path_1.default.join(path_1.default.dirname(file.name), journey.alias) : file.name;
49
- let currentData;
50
- try {
51
- currentData = yield fs_extra_1.default.readFile(path_1.default.join(targetPath, name), 'utf-8');
52
- if (onUpdate(name)) {
53
- continue;
60
+ const fileName = journey.alias ? path_1.default.join(path_1.default.dirname(file.name), journey.alias) : file.name;
61
+ const filePath = path_1.default.join(targetPath, fileName);
62
+ const exists = yield fs_extra_1.default.pathExists(filePath);
63
+ if (exists) {
64
+ switch (onExisting(file.name)) {
65
+ case 'merge': {
66
+ const currentData = yield fs_extra_1.default.readFile(filePath, 'utf-8');
67
+ const data = journey.travel({
68
+ current: currentData,
69
+ incoming: file.data,
70
+ filters: filters(file.name),
71
+ });
72
+ mergedTextFiles.push({
73
+ name: fileName,
74
+ data,
75
+ finalNewLine: file.finalNewLine,
76
+ mode: file.mode,
77
+ });
78
+ if (options.verbose) {
79
+ console.log(`${file.name} has been merged`);
80
+ }
81
+ break;
82
+ }
83
+ case 'overwrite':
84
+ mergedTextFiles.push(file);
85
+ if (options.verbose) {
86
+ console.log(`${file.name} has been overwritten`);
87
+ }
88
+ continue;
89
+ case 'skip':
90
+ continue;
54
91
  }
55
92
  }
56
- catch (_c) {
57
- if (onMissing(name)) {
58
- continue;
93
+ else {
94
+ switch (onMissing(file.name)) {
95
+ case 'continue':
96
+ mergedTextFiles.push(Object.assign(Object.assign({}, file), { name: fileName }));
97
+ if (options.verbose) {
98
+ console.log(`${file.name} has been copied`);
99
+ }
100
+ continue;
101
+ case 'skip':
102
+ continue;
59
103
  }
60
104
  }
61
- const data = journey.travel({
62
- current: currentData,
63
- incoming: file.data,
64
- filters: filters(file.name),
65
- });
66
- mergedTextFiles.push({
67
- name,
68
- data,
69
- finalNewLine: file.finalNewLine,
70
- mode: file.mode,
71
- });
72
- if (options.verbose) {
73
- console.log(`${file.name} has been merged`);
74
- }
75
105
  }
76
106
  });
77
107
  }
78
- exports.mergeTextFiles = mergeTextFiles;