@zokugun/artifact 0.1.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 (60) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +102 -0
  3. package/bin/artifact +3 -0
  4. package/lib/cli.js +17 -0
  5. package/lib/commands/add.js +57 -0
  6. package/lib/compositors/compose.js +49 -0
  7. package/lib/compositors/fork.js +21 -0
  8. package/lib/compositors/index.js +13 -0
  9. package/lib/compositors/json.js +56 -0
  10. package/lib/compositors/rc.js +47 -0
  11. package/lib/compositors/yaml.js +34 -0
  12. package/lib/install.js +32 -0
  13. package/lib/journeys/commitlint/index.js +19 -0
  14. package/lib/journeys/default/index.js +17 -0
  15. package/lib/journeys/gitignore/index.js +7 -0
  16. package/lib/journeys/ignore/index.js +7 -0
  17. package/lib/journeys/index.js +34 -0
  18. package/lib/journeys/npmignore/index.js +7 -0
  19. package/lib/journeys/package/index.js +48 -0
  20. package/lib/journeys/rc/index.js +15 -0
  21. package/lib/parsers/json.js +11 -0
  22. package/lib/parsers/jsonc/index.js +7 -0
  23. package/lib/parsers/jsonc/parse.js +194 -0
  24. package/lib/parsers/jsonc/stringify.js +100 -0
  25. package/lib/parsers/jsonc/transform.js +2 -0
  26. package/lib/parsers/yaml.js +15 -0
  27. package/lib/routes/command.js +21 -0
  28. package/lib/routes/hash.js +13 -0
  29. package/lib/routes/index.js +15 -0
  30. package/lib/routes/lines-concat.js +22 -0
  31. package/lib/routes/list-concat.js +18 -0
  32. package/lib/routes/overwrite.js +12 -0
  33. package/lib/routes/primitive.js +18 -0
  34. package/lib/steps/apply-formatting.js +78 -0
  35. package/lib/steps/copy-binary-files.js +31 -0
  36. package/lib/steps/index.js +42 -0
  37. package/lib/steps/insert-final-new-line.js +25 -0
  38. package/lib/steps/merge-text-files.js +57 -0
  39. package/lib/steps/read-editor-config.js +97 -0
  40. package/lib/steps/read-files.js +66 -0
  41. package/lib/steps/read-incoming-package.js +24 -0
  42. package/lib/steps/read-target-config.js +78 -0
  43. package/lib/steps/update-target-config.js +50 -0
  44. package/lib/steps/write-text-files.js +32 -0
  45. package/lib/types/config.js +2 -0
  46. package/lib/types/context.js +2 -0
  47. package/lib/types/format.js +8 -0
  48. package/lib/types/step.js +2 -0
  49. package/lib/types/text-file.js +2 -0
  50. package/lib/types/travel.js +2 -0
  51. package/lib/utils/build-journey-plan.js +18 -0
  52. package/lib/utils/build-travel-plan.js +20 -0
  53. package/lib/utils/command/command.js +2 -0
  54. package/lib/utils/command/index.js +7 -0
  55. package/lib/utils/command/join-command.js +27 -0
  56. package/lib/utils/command/split-command.js +30 -0
  57. package/lib/utils/read-buffer.js +38 -0
  58. package/lib/utils/to-lines.js +7 -0
  59. package/lib/utils/trim-final-newline.js +8 -0
  60. package/package.json +93 -0
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parse = void 0;
4
+ const jsonc_parser_1 = require("jsonc-parser");
5
+ function parse(text) {
6
+ if (!text) {
7
+ return {
8
+ data: undefined,
9
+ transform: {},
10
+ };
11
+ }
12
+ const stack = [];
13
+ let current;
14
+ let property = '';
15
+ const transformStack = [];
16
+ let comment;
17
+ let transform;
18
+ let lastLine = 0;
19
+ let lastOffset = 0;
20
+ let lastKid;
21
+ (0, jsonc_parser_1.visit)(text, {
22
+ onObjectBegin(offset, length, startLine, _startCharacter) {
23
+ // console.log('onObjectBegin', startLine)
24
+ if (current) {
25
+ stack.unshift(current);
26
+ }
27
+ if (transform) {
28
+ transformStack.unshift(transform);
29
+ }
30
+ current = {};
31
+ transform = {
32
+ children: {},
33
+ };
34
+ if (stack.length > 0) {
35
+ if (Array.isArray(stack[0])) {
36
+ stack[0].push(current);
37
+ }
38
+ else {
39
+ stack[0][property] = current;
40
+ transformStack[0].children[property] = transform;
41
+ property = '';
42
+ }
43
+ }
44
+ lastKid = transform;
45
+ lastLine = startLine;
46
+ lastOffset = offset + length;
47
+ },
48
+ onObjectProperty(name, _offset, _length, _startLine, _startCharacter) {
49
+ // console.log('onObjectProperty', name, _startLine, _startCharacter)
50
+ property = name;
51
+ },
52
+ onObjectEnd(offset, length, startLine, _startCharacter) {
53
+ // console.log('onObjectEnd', startLine, startCharacter)
54
+ if (stack.length > 0) {
55
+ lastKid = transform;
56
+ current = stack.shift();
57
+ transform = transformStack.shift();
58
+ }
59
+ lastLine = startLine;
60
+ lastOffset = offset + length;
61
+ },
62
+ onArrayBegin(offset, length, startLine, _startCharacter) {
63
+ // console.log('onArrayBegin', startLine, _startCharacter)
64
+ if (current) {
65
+ stack.unshift(current);
66
+ }
67
+ if (transform) {
68
+ transformStack.unshift(transform);
69
+ }
70
+ current = [];
71
+ transform = {
72
+ children: {},
73
+ };
74
+ if (stack.length > 0) {
75
+ if (Array.isArray(stack[0])) {
76
+ stack[0].push(current);
77
+ }
78
+ else {
79
+ stack[0][property] = current;
80
+ transformStack[0].children[property] = transform;
81
+ property = '';
82
+ }
83
+ }
84
+ lastKid = transform;
85
+ lastLine = startLine;
86
+ lastOffset = offset + length;
87
+ },
88
+ onArrayEnd(offset, length, startLine, _startCharacter) {
89
+ // console.log('onArrayEnd', startLine, _startCharacter)
90
+ if (stack.length > 0) {
91
+ lastKid = transform;
92
+ current = stack.shift();
93
+ transform = transformStack.shift();
94
+ }
95
+ lastLine = startLine;
96
+ lastOffset = offset + length;
97
+ },
98
+ onLiteralValue(value, offset, length, startLine, _startCharacter) {
99
+ // console.log('onLiteralValue', startLine, _startCharacter)
100
+ if (current) {
101
+ if (Array.isArray(current)) {
102
+ lastKid = {};
103
+ transform.children[current.length] = lastKid;
104
+ current.push(value);
105
+ }
106
+ else {
107
+ current[property] = value;
108
+ if (comment) {
109
+ transform.children[property] = {
110
+ comments: {
111
+ top: comment.text,
112
+ },
113
+ };
114
+ if (comment.line - lastLine > 1) {
115
+ transform.children[property].emptyLines = comment.line - lastLine - 1;
116
+ }
117
+ comment = undefined;
118
+ }
119
+ else if (startLine - lastLine > 1) {
120
+ transform.children[property] = {
121
+ emptyLines: startLine - lastLine - 1,
122
+ };
123
+ }
124
+ else {
125
+ transform.children[property] = {};
126
+ }
127
+ lastKid = transform.children[property];
128
+ property = '';
129
+ }
130
+ }
131
+ lastLine = startLine;
132
+ lastOffset = offset + length;
133
+ },
134
+ onSeparator(_character, offset, length, _startLine, _startCharacter) {
135
+ // console.log('onSeparator', _character, _startLine, _startCharacter)
136
+ if (lastOffset) {
137
+ lastOffset = offset + length;
138
+ }
139
+ },
140
+ onComment(offset, length, startLine, _startCharacter) {
141
+ // console.log('onComment', startLine, _startCharacter)
142
+ let line = text.slice(offset, offset + length);
143
+ if (startLine === lastLine && lastKid) {
144
+ line = text.slice(lastOffset, lastOffset + offset - lastOffset) + line;
145
+ if (lastKid.comments) {
146
+ lastKid.comments.right = [line];
147
+ }
148
+ else {
149
+ lastKid.comments = {
150
+ right: [line],
151
+ };
152
+ }
153
+ }
154
+ else if (comment) {
155
+ if (comment.line + comment.text.length === startLine) {
156
+ comment.text.push(line);
157
+ }
158
+ else {
159
+ if (lastKid.comments) {
160
+ lastKid.comments.bottom = comment.text;
161
+ }
162
+ else {
163
+ lastKid.comments = {
164
+ bottom: comment.text,
165
+ };
166
+ }
167
+ lastLine += comment.text.length;
168
+ comment = {
169
+ text: [line],
170
+ line: startLine,
171
+ };
172
+ }
173
+ }
174
+ else {
175
+ comment = {
176
+ text: [line],
177
+ line: startLine,
178
+ };
179
+ }
180
+ },
181
+ onError(error, _offset, _length, _startLine, _startCharacter) {
182
+ // console.log('onError', error, _startLine, _startCharacter)
183
+ if ((error === 3 /* PropertyNameExpected */ || error === 4 /* ValueExpected */) && lastKid) {
184
+ lastKid.separator = true;
185
+ }
186
+ },
187
+ });
188
+ // console.log(JSON.stringify(transform, null, 2))
189
+ return {
190
+ data: current,
191
+ transform,
192
+ };
193
+ }
194
+ exports.parse = parse;
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stringify = void 0;
4
+ const lodash_1 = require("lodash");
5
+ function stringify(data, transform = {}) {
6
+ const result = format(data, '', transform);
7
+ return result;
8
+ }
9
+ exports.stringify = stringify;
10
+ function format(data, indentValue, transform, separator = false) {
11
+ var _a;
12
+ let result;
13
+ if (Array.isArray(data)) {
14
+ result = formatArray(data, indentValue, transform);
15
+ if (separator) {
16
+ result += ',';
17
+ }
18
+ }
19
+ else if ((0, lodash_1.isPlainObject)(data)) {
20
+ result = formatObject(data, indentValue, transform);
21
+ if (separator) {
22
+ result += ',';
23
+ }
24
+ }
25
+ else {
26
+ result = JSON.stringify(data);
27
+ if (separator) {
28
+ result += ',';
29
+ }
30
+ if ((_a = transform.comments) === null || _a === void 0 ? void 0 : _a.right) {
31
+ result += transform.comments.right[0];
32
+ }
33
+ }
34
+ return result;
35
+ }
36
+ function formatArray(data, indentValue, transform) {
37
+ var _a, _b, _c, _d, _e;
38
+ let result = '[';
39
+ if ((_a = transform.comments) === null || _a === void 0 ? void 0 : _a.right) {
40
+ result += transform.comments.right[0];
41
+ }
42
+ result += '\n';
43
+ const indent = indentValue + '\t';
44
+ const lastIndex = data.length - 1;
45
+ const children = (_b = transform.children) !== null && _b !== void 0 ? _b : {};
46
+ for (const [index, value] of data.entries()) {
47
+ const transform = (_c = children[index]) !== null && _c !== void 0 ? _c : {};
48
+ if (transform.emptyLines) {
49
+ result += '\n'.repeat(transform.emptyLines);
50
+ }
51
+ if ((_d = transform.comments) === null || _d === void 0 ? void 0 : _d.top) {
52
+ for (const line of transform.comments.top) {
53
+ result += `${indent}${line}\n`;
54
+ }
55
+ }
56
+ result += `${indent}`;
57
+ result += format(value, indent, transform, index !== lastIndex || transform.separator);
58
+ result += '\n';
59
+ if ((_e = transform.comments) === null || _e === void 0 ? void 0 : _e.bottom) {
60
+ for (const line of transform.comments.bottom) {
61
+ result += `${indent}${line}\n`;
62
+ }
63
+ }
64
+ }
65
+ result += `${indentValue}]`;
66
+ return result;
67
+ }
68
+ function formatObject(data, indentValue, transform) {
69
+ var _a, _b, _c, _d, _e;
70
+ let result = '{';
71
+ if ((_a = transform.comments) === null || _a === void 0 ? void 0 : _a.right) {
72
+ result += transform.comments.right[0];
73
+ }
74
+ result += '\n';
75
+ const indent = indentValue + '\t';
76
+ const values = Object.entries(data);
77
+ const lastIndex = values.length - 1;
78
+ const children = (_b = transform.children) !== null && _b !== void 0 ? _b : {};
79
+ for (const [index, [key, value]] of values.entries()) {
80
+ const transform = (_c = children[key]) !== null && _c !== void 0 ? _c : {};
81
+ if (transform.emptyLines) {
82
+ result += '\n'.repeat(transform.emptyLines);
83
+ }
84
+ if ((_d = transform.comments) === null || _d === void 0 ? void 0 : _d.top) {
85
+ for (const line of transform.comments.top) {
86
+ result += `${indent}${line}\n`;
87
+ }
88
+ }
89
+ result += `${indent}"${key}": `;
90
+ result += format(value, indent, transform, index !== lastIndex || transform.separator);
91
+ result += '\n';
92
+ if ((_e = transform.comments) === null || _e === void 0 ? void 0 : _e.bottom) {
93
+ for (const line of transform.comments.bottom) {
94
+ result += `${indent}${line}\n`;
95
+ }
96
+ }
97
+ }
98
+ result += `${indentValue}}`;
99
+ return result;
100
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.stringify = exports.parse = void 0;
7
+ const yaml_1 = __importDefault(require("yaml"));
8
+ function parse(data) {
9
+ return yaml_1.default.parse(data);
10
+ }
11
+ exports.parse = parse;
12
+ function stringify(data) {
13
+ return yaml_1.default.stringify(data);
14
+ }
15
+ exports.stringify = stringify;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const command_1 = require("../utils/command");
5
+ const hash_1 = require("./hash");
6
+ function command({ current, incoming }) {
7
+ if (!incoming) {
8
+ return current !== null && current !== void 0 ? current : '';
9
+ }
10
+ if (!current) {
11
+ return incoming;
12
+ }
13
+ const currentCommand = (0, command_1.splitCommand)(current);
14
+ const incomingCommand = (0, command_1.splitCommand)(incoming);
15
+ const result = (0, hash_1.hash)({
16
+ current: currentCommand,
17
+ incoming: incomingCommand,
18
+ });
19
+ return (0, command_1.joinCommand)(result);
20
+ }
21
+ exports.command = command;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hash = void 0;
4
+ function hash({ current, incoming }) {
5
+ if (!incoming) {
6
+ return current !== null && current !== void 0 ? current : {};
7
+ }
8
+ if (!current) {
9
+ return incoming;
10
+ }
11
+ return Object.assign(Object.assign({}, current), incoming);
12
+ }
13
+ exports.hash = hash;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.primitive = exports.overwrite = exports.listConcat = exports.linesConcat = exports.hash = exports.command = void 0;
4
+ var command_1 = require("./command");
5
+ Object.defineProperty(exports, "command", { enumerable: true, get: function () { return command_1.command; } });
6
+ var hash_1 = require("./hash");
7
+ Object.defineProperty(exports, "hash", { enumerable: true, get: function () { return hash_1.hash; } });
8
+ var lines_concat_1 = require("./lines-concat");
9
+ Object.defineProperty(exports, "linesConcat", { enumerable: true, get: function () { return lines_concat_1.linesConcat; } });
10
+ var list_concat_1 = require("./list-concat");
11
+ Object.defineProperty(exports, "listConcat", { enumerable: true, get: function () { return list_concat_1.listConcat; } });
12
+ var overwrite_1 = require("./overwrite");
13
+ Object.defineProperty(exports, "overwrite", { enumerable: true, get: function () { return overwrite_1.overwrite; } });
14
+ var primitive_1 = require("./primitive");
15
+ Object.defineProperty(exports, "primitive", { enumerable: true, get: function () { return primitive_1.primitive; } });
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.linesConcat = void 0;
4
+ const trim_final_newline_1 = require("../utils/trim-final-newline");
5
+ const to_lines_1 = require("../utils/to-lines");
6
+ const list_concat_1 = require("./list-concat");
7
+ function linesConcat({ current, incoming }) {
8
+ if (!incoming) {
9
+ return current !== null && current !== void 0 ? current : '';
10
+ }
11
+ if (!current) {
12
+ return incoming;
13
+ }
14
+ const currentLines = (0, to_lines_1.toLines)((0, trim_final_newline_1.trimFinalNewLine)(current));
15
+ const incomingLines = (0, to_lines_1.toLines)((0, trim_final_newline_1.trimFinalNewLine)(incoming));
16
+ const result = (0, list_concat_1.listConcat)({
17
+ current: currentLines,
18
+ incoming: incomingLines,
19
+ });
20
+ return result.join('\n');
21
+ }
22
+ exports.linesConcat = linesConcat;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.listConcat = void 0;
7
+ const isEqual_1 = __importDefault(require("lodash/isEqual"));
8
+ const uniqWith_1 = __importDefault(require("lodash/uniqWith"));
9
+ function listConcat({ current, incoming }) {
10
+ if (!incoming) {
11
+ return current !== null && current !== void 0 ? current : [];
12
+ }
13
+ if (!current) {
14
+ return incoming;
15
+ }
16
+ return (0, uniqWith_1.default)([...current, ...incoming], isEqual_1.default);
17
+ }
18
+ exports.listConcat = listConcat;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.overwrite = void 0;
4
+ function overwrite({ current, incoming }) {
5
+ if (!incoming) {
6
+ return current !== null && current !== void 0 ? current : [];
7
+ }
8
+ else {
9
+ return incoming;
10
+ }
11
+ }
12
+ exports.overwrite = overwrite;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.primitive = void 0;
4
+ function primitive({ current, incoming }) {
5
+ if (!incoming) {
6
+ return current !== null && current !== void 0 ? current : [];
7
+ }
8
+ if (!current) {
9
+ return incoming;
10
+ }
11
+ if (current === incoming) {
12
+ return current;
13
+ }
14
+ else {
15
+ return incoming;
16
+ }
17
+ }
18
+ exports.primitive = primitive;
@@ -0,0 +1,78 @@
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.applyFormatting = void 0;
16
+ const fnmatch_1 = __importDefault(require("editorconfig/src/lib/fnmatch"));
17
+ const detect_indent_1 = __importDefault(require("detect-indent"));
18
+ const format_1 = require("../types/format");
19
+ function applyFormat(file, format) {
20
+ if (format.indentStyle === format_1.IndentStyle.SPACE) {
21
+ file.data = indentWithSpace(file.data, format.indentSize);
22
+ }
23
+ else {
24
+ file.data = indentWithTab(file.data);
25
+ }
26
+ if (format.insertFinalNewline) {
27
+ const withFinalNewLine = file.data.endsWith('\n');
28
+ if (!withFinalNewLine) {
29
+ file.data = `${file.data}\n`;
30
+ }
31
+ }
32
+ } // }}}
33
+ function fnmatch(filepath, glob) {
34
+ const matchOptions = { matchBase: true, dot: true, noext: true };
35
+ return (0, fnmatch_1.default)(filepath, glob, matchOptions);
36
+ } // }}}
37
+ function indentWithSpace(data, size) {
38
+ const { type, indent } = (0, detect_indent_1.default)(data);
39
+ if (type === 'space') {
40
+ if (indent.length === size) {
41
+ return data;
42
+ }
43
+ else {
44
+ data = data.replace(new RegExp(indent, 'gm'), '\t');
45
+ const newIndent = ' '.repeat(size);
46
+ return data.replace(/\t/gm, newIndent);
47
+ }
48
+ }
49
+ else if (type === 'tab') {
50
+ const newIndent = ' '.repeat(size);
51
+ return data.replace(new RegExp(indent, 'gm'), newIndent);
52
+ }
53
+ else {
54
+ return data;
55
+ }
56
+ } // }}}
57
+ function indentWithTab(data) {
58
+ const { type, indent } = (0, detect_indent_1.default)(data);
59
+ if (type === 'space') {
60
+ return data.replace(new RegExp(indent, 'gm'), '\t');
61
+ }
62
+ else {
63
+ return data;
64
+ }
65
+ } // }}}
66
+ function applyFormatting({ mergedTextFiles, formats }) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ for (const file of mergedTextFiles) {
69
+ for (const format of formats) {
70
+ if (fnmatch(file.name, format.glob)) {
71
+ applyFormat(file, format);
72
+ break;
73
+ }
74
+ }
75
+ }
76
+ });
77
+ }
78
+ exports.applyFormatting = applyFormatting;
@@ -0,0 +1,31 @@
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.copyBinaryFiles = void 0;
16
+ const path_1 = __importDefault(require("path"));
17
+ const fs_extra_1 = __importDefault(require("fs-extra"));
18
+ function copyBinaryFiles({ binaryFiles, incomingPath, targetPath, options }) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const cwd = path_1.default.join(incomingPath, 'configs');
21
+ for (const file of binaryFiles) {
22
+ const source = path_1.default.join(cwd, file);
23
+ const target = path_1.default.join(targetPath, file);
24
+ yield fs_extra_1.default.copyFile(source, target);
25
+ if (options.verbose) {
26
+ console.log(`${file} has been written as a binary file`);
27
+ }
28
+ }
29
+ });
30
+ }
31
+ exports.copyBinaryFiles = copyBinaryFiles;
@@ -0,0 +1,42 @@
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.composeSteps = exports.steps = void 0;
13
+ const apply_formatting_1 = require("./apply-formatting");
14
+ const copy_binary_files_1 = require("./copy-binary-files");
15
+ const insert_final_new_line_1 = require("./insert-final-new-line");
16
+ const merge_text_files_1 = require("./merge-text-files");
17
+ const read_editor_config_1 = require("./read-editor-config");
18
+ const read_files_1 = require("./read-files");
19
+ const read_incoming_package_1 = require("./read-incoming-package");
20
+ const read_target_config_1 = require("./read-target-config");
21
+ const update_target_config_1 = require("./update-target-config");
22
+ const write_text_files_1 = require("./write-text-files");
23
+ exports.steps = {
24
+ applyFormatting: apply_formatting_1.applyFormatting,
25
+ copyBinaryFiles: copy_binary_files_1.copyBinaryFiles,
26
+ insertFinalNewLine: insert_final_new_line_1.insertFinalNewLine,
27
+ mergeTextFiles: merge_text_files_1.mergeTextFiles,
28
+ readEditorConfig: read_editor_config_1.readEditorConfig,
29
+ readFiles: read_files_1.readFiles,
30
+ readIncomingPackage: read_incoming_package_1.readIncomingPackage,
31
+ readTargetConfig: read_target_config_1.readTargetConfig,
32
+ updateTargetConfig: update_target_config_1.updateTargetConfig,
33
+ writeTextFiles: write_text_files_1.writeTextFiles,
34
+ };
35
+ function composeSteps(...steps) {
36
+ return (context) => __awaiter(this, void 0, void 0, function* () {
37
+ for (const step of steps) {
38
+ yield step(context);
39
+ }
40
+ });
41
+ }
42
+ exports.composeSteps = composeSteps;
@@ -0,0 +1,25 @@
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.insertFinalNewLine = void 0;
13
+ function insertFinalNewLine({ mergedTextFiles }) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ for (const file of mergedTextFiles) {
16
+ if (file.finalNewLine) {
17
+ const withFinalNewLine = file.data.endsWith('\n');
18
+ if (!withFinalNewLine) {
19
+ file.data = `${file.data}\n`;
20
+ }
21
+ }
22
+ }
23
+ });
24
+ }
25
+ exports.insertFinalNewLine = insertFinalNewLine;