@zokugun/artifact 0.5.2 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/artifact +1 -1
- package/lib/cli.d.ts +1 -0
- package/lib/cli.js +12 -4
- package/lib/commands/add.d.ts +6 -0
- package/lib/commands/add.js +47 -36
- package/lib/commands/index.d.ts +4 -0
- package/lib/commands/index.js +9 -7
- package/lib/commands/list.d.ts +1 -0
- package/lib/commands/list.js +13 -8
- package/lib/commands/remove.d.ts +6 -0
- package/lib/commands/remove.js +79 -0
- package/lib/commands/update.d.ts +5 -0
- package/lib/commands/update.js +43 -39
- package/lib/compositors/compose.d.ts +7 -0
- package/lib/compositors/compose.js +13 -13
- package/lib/compositors/fork.d.ts +3 -0
- package/lib/compositors/fork.js +4 -4
- package/lib/compositors/index.d.ts +6 -0
- package/lib/compositors/index.js +12 -12
- package/lib/compositors/json.d.ts +2 -0
- package/lib/compositors/json.js +14 -12
- package/lib/compositors/map-sort.d.ts +2 -0
- package/lib/compositors/map-sort.js +2 -2
- package/lib/compositors/rc.d.ts +2 -0
- package/lib/compositors/rc.js +13 -10
- package/lib/compositors/yaml.d.ts +2 -0
- package/lib/compositors/yaml.js +8 -11
- package/lib/configs/index.d.ts +3 -0
- package/lib/configs/index.js +3 -2
- package/lib/configs/install/index.d.ts +3 -0
- package/lib/configs/install/index.js +6 -6
- package/lib/configs/install/read-install-config.d.ts +6 -0
- package/lib/configs/install/read-install-config.js +128 -81
- package/lib/configs/install/update-install-config.d.ts +2 -0
- package/lib/configs/install/write-install-config.d.ts +5 -0
- package/lib/configs/install/write-install-config.js +25 -10
- package/lib/configs/package/index.d.ts +1 -0
- package/lib/configs/package/index.js +2 -2
- package/lib/configs/package/read-package-config.d.ts +3 -0
- package/lib/configs/package/read-package-config.js +160 -40
- package/lib/configs/uninstall/index.d.ts +1 -0
- package/lib/configs/uninstall/index.js +5 -0
- package/lib/configs/uninstall/update-uninstall-config.d.ts +2 -0
- package/lib/configs/uninstall/update-uninstall-config.js +6 -0
- package/lib/configs/utils/constants.d.ts +11 -0
- package/lib/configs/utils/constants.js +24 -0
- package/lib/configs/utils/is-transform.d.ts +2 -0
- package/lib/configs/utils/is-transform.js +16 -0
- package/lib/configs/utils/merge-upsert-property.d.ts +3 -0
- package/lib/configs/utils/merge-upsert-property.js +78 -0
- package/lib/configs/utils/normalize-file-always.d.ts +3 -0
- package/lib/configs/utils/normalize-file-always.js +29 -0
- package/lib/configs/utils/normalize-file-uninstall.d.ts +3 -0
- package/lib/configs/utils/normalize-file-uninstall.js +32 -0
- package/lib/configs/utils/normalize-file-upsert.d.ts +3 -0
- package/lib/configs/utils/normalize-file-upsert.js +55 -0
- package/lib/journeys/commitlint/index.d.ts +2 -0
- package/lib/journeys/commitlint/index.js +15 -15
- package/lib/journeys/config.ts/index.d.ts +2 -0
- package/lib/journeys/config.ts/index.js +5 -5
- package/lib/journeys/default/index.d.ts +2 -0
- package/lib/journeys/default/index.js +11 -14
- package/lib/journeys/fixpack/index.d.ts +2 -0
- package/lib/journeys/fixpack/index.js +13 -13
- package/lib/journeys/gitignore/index.d.ts +2 -0
- package/lib/journeys/gitignore/index.js +5 -5
- package/lib/journeys/ignore/index.d.ts +2 -0
- package/lib/journeys/ignore/index.js +5 -5
- package/lib/journeys/index.d.ts +2 -0
- package/lib/journeys/index.js +20 -20
- package/lib/journeys/npmignore/index.d.ts +2 -0
- package/lib/journeys/npmignore/index.js +5 -5
- package/lib/journeys/package/index.d.ts +2 -0
- package/lib/journeys/package/index.js +27 -30
- package/lib/journeys/rc/index.d.ts +2 -0
- package/lib/journeys/rc/index.js +12 -12
- package/lib/journeys/tsconfig/index.d.ts +2 -0
- package/lib/journeys/tsconfig/index.js +13 -16
- package/lib/parsers/json.d.ts +2 -0
- package/lib/parsers/jsonc/index.d.ts +2 -0
- package/lib/parsers/jsonc/index.js +4 -4
- package/lib/parsers/jsonc/parse.d.ts +5 -0
- package/lib/parsers/jsonc/parse.js +1 -13
- package/lib/parsers/jsonc/stringify.d.ts +2 -0
- package/lib/parsers/jsonc/stringify.js +2 -2
- package/lib/parsers/jsonc/transform.d.ts +10 -0
- package/lib/parsers/yaml.d.ts +2 -0
- package/lib/routes/command.d.ts +4 -0
- package/lib/routes/command.js +10 -10
- package/lib/routes/index.d.ts +8 -0
- package/lib/routes/index.js +17 -15
- package/lib/routes/lines-concat.d.ts +4 -0
- package/lib/routes/lines-concat.js +7 -7
- package/lib/routes/list-concat.d.ts +4 -0
- package/lib/routes/list-concat.js +3 -7
- package/lib/routes/list-sort-concat.d.ts +4 -0
- package/lib/routes/list-sort-concat.js +1 -1
- package/lib/routes/map-concat.d.ts +4 -0
- package/lib/routes/map-concat.js +1 -1
- package/lib/routes/map-delete.d.ts +4 -0
- package/lib/routes/map-delete.js +32 -0
- package/lib/routes/overwrite.d.ts +4 -0
- package/lib/routes/overwrite.js +2 -2
- package/lib/routes/primitive.d.ts +4 -0
- package/lib/routes/primitive.js +3 -3
- package/lib/steps/apply-formatting.d.ts +8 -0
- package/lib/steps/apply-formatting.js +50 -25
- package/lib/steps/configure-branches.d.ts +3 -0
- package/lib/steps/configure-branches.js +8 -5
- package/lib/steps/configure-install-file-actions.d.ts +3 -0
- package/lib/steps/configure-install-file-actions.js +59 -94
- package/lib/steps/configure-uninstall-file-actions.d.ts +3 -0
- package/lib/steps/configure-uninstall-file-actions.js +57 -0
- package/lib/steps/configure-update-file-actions.d.ts +3 -0
- package/lib/steps/configure-update-file-actions.js +65 -102
- package/lib/steps/copy-binary-files.d.ts +3 -0
- package/lib/steps/copy-binary-files.js +24 -11
- package/lib/steps/execute-first-block.d.ts +3 -0
- package/lib/steps/execute-first-block.js +35 -14
- package/lib/steps/execute-next-block.d.ts +3 -0
- package/lib/steps/execute-next-block.js +8 -3
- package/lib/steps/index.d.ts +54 -0
- package/lib/steps/index.js +76 -54
- package/lib/steps/insert-final-new-line.d.ts +6 -0
- package/lib/steps/insert-final-new-line.js +13 -1
- package/lib/steps/merge-text-files.d.ts +3 -0
- package/lib/steps/merge-text-files.js +47 -28
- package/lib/steps/read-editor-config.d.ts +3 -0
- package/lib/steps/read-editor-config.js +21 -26
- package/lib/steps/read-files.d.ts +3 -0
- package/lib/steps/read-files.js +26 -10
- package/lib/steps/read-incoming-config.d.ts +3 -0
- package/lib/steps/read-incoming-config.js +7 -5
- package/lib/steps/read-incoming-package.d.ts +3 -0
- package/lib/steps/read-incoming-package.js +12 -7
- package/lib/steps/remove-files.d.ts +3 -0
- package/lib/steps/remove-files.js +10 -4
- package/lib/steps/rename-files.d.ts +3 -0
- package/lib/steps/rename-files.js +25 -0
- package/lib/steps/replace-templates.d.ts +3 -0
- package/lib/steps/replace-templates.js +19 -5
- package/lib/steps/transform-untouched-files.d.ts +3 -0
- package/lib/steps/transform-untouched-files.js +64 -0
- package/lib/steps/unmerge-text-files.d.ts +3 -0
- package/lib/steps/unmerge-text-files.js +64 -0
- package/lib/steps/validate-newer-package.d.ts +3 -0
- package/lib/steps/validate-newer-package.js +4 -2
- package/lib/steps/validate-not-present-package.d.ts +3 -0
- package/lib/steps/validate-not-present-package.js +7 -4
- package/lib/steps/validate-present-package.d.ts +3 -0
- package/lib/steps/validate-present-package.js +24 -0
- package/lib/steps/write-text-files.d.ts +3 -0
- package/lib/steps/write-text-files.js +16 -7
- package/lib/types/binary-file.d.ts +4 -0
- package/lib/types/command.d.ts +5 -0
- package/lib/types/config.d.ts +59 -0
- package/lib/types/context.d.ts +62 -0
- package/lib/types/context.js +4 -0
- package/lib/types/format.d.ts +14 -0
- package/lib/types/step.d.ts +3 -0
- package/lib/types/travel.d.ts +14 -0
- package/lib/utils/apply-transforms.d.ts +2 -0
- package/lib/utils/apply-transforms.js +48 -0
- package/lib/utils/build-journey-plan.d.ts +2 -0
- package/lib/utils/build-route.d.ts +3 -0
- package/lib/utils/build-route.js +92 -0
- package/lib/utils/build-travel-plan.d.ts +2 -0
- package/lib/utils/build-travel.d.ts +3 -0
- package/lib/utils/build-travel.js +32 -0
- package/lib/utils/command/dedupe-strings.d.ts +1 -0
- package/lib/utils/command/index.d.ts +8 -0
- package/lib/utils/command/index.js +14 -14
- package/lib/utils/command/join-command.d.ts +2 -0
- package/lib/utils/command/merge-and-chains.d.ts +1 -0
- package/lib/utils/command/merge-and-chains.js +21 -21
- package/lib/utils/command/merge-command-records.d.ts +2 -0
- package/lib/utils/command/merge-command-records.js +43 -22
- package/lib/utils/command/merge-flag-tokens.d.ts +1 -0
- package/lib/utils/command/merge-flag-tokens.js +1 -1
- package/lib/utils/command/merge-flags-as-string.d.ts +4 -0
- package/lib/utils/command/merge-flags-as-string.js +4 -4
- package/lib/utils/command/merge-or-segments.d.ts +1 -0
- package/lib/utils/command/merge-or-segments.js +28 -28
- package/lib/utils/command/merge-parts-by-prefix.d.ts +1 -0
- package/lib/utils/command/merge-parts-by-prefix.js +6 -6
- package/lib/utils/command/merge-semicolon-segments.d.ts +1 -0
- package/lib/utils/command/merge-semicolon-segments.js +35 -35
- package/lib/utils/command/merge-with-semicolon-mix.d.ts +1 -0
- package/lib/utils/command/merge-with-semicolon-mix.js +12 -12
- package/lib/utils/command/prefix-of-command.d.ts +1 -0
- package/lib/utils/command/prefix-of-command.js +2 -2
- package/lib/utils/command/split-chain.d.ts +1 -0
- package/lib/utils/command/split-command.d.ts +2 -0
- package/lib/utils/command/split-command.js +8 -8
- package/lib/utils/command/split-prefix-and-flags.d.ts +4 -0
- package/lib/utils/command/split-prefix-and-flags.js +5 -5
- package/lib/utils/command/split-segments.d.ts +1 -0
- package/lib/utils/detect-indent.d.ts +2 -0
- package/lib/utils/detect-indent.js +63 -0
- package/lib/utils/flow.d.ts +3 -0
- package/lib/utils/flow.js +12 -0
- package/lib/utils/get-format.d.ts +2 -0
- package/lib/utils/get-format.js +19 -0
- package/lib/utils/has-final-new-line.d.ts +1 -0
- package/lib/utils/has-final-new-line.js +7 -0
- package/lib/utils/read-buffer.d.ts +2 -0
- package/lib/utils/resolve-request.d.ts +3 -0
- package/lib/utils/resolve-request.js +4 -3
- package/lib/utils/template.d.ts +17 -0
- package/lib/utils/template.js +79 -57
- package/lib/utils/to-lines.d.ts +1 -0
- package/lib/utils/trim-final-newline.d.ts +1 -0
- package/lib/utils/try-json.d.ts +1 -0
- package/lib/utils/try-json.js +2 -2
- package/package.json +74 -51
- package/lib/types/text-file.js +0 -2
- package/lib/utils/dev-null.js +0 -7
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type AsyncDResult } from '@zokugun/xtry';
|
|
2
|
+
import { type TextFile } from '../types/context.js';
|
|
3
|
+
export declare function insertFinalNewLine({ mergedTextFiles, transformedFiles }: {
|
|
4
|
+
mergedTextFiles: TextFile[];
|
|
5
|
+
transformedFiles?: TextFile[];
|
|
6
|
+
}): AsyncDResult;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.insertFinalNewLine = insertFinalNewLine;
|
|
4
|
-
|
|
4
|
+
const xtry_1 = require("@zokugun/xtry");
|
|
5
|
+
async function insertFinalNewLine({ mergedTextFiles, transformedFiles }) {
|
|
5
6
|
for (const file of mergedTextFiles) {
|
|
6
7
|
if (file.finalNewLine) {
|
|
7
8
|
const withFinalNewLine = file.data.endsWith('\n');
|
|
@@ -10,4 +11,15 @@ async function insertFinalNewLine({ mergedTextFiles }) {
|
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
13
|
}
|
|
14
|
+
if (transformedFiles) {
|
|
15
|
+
for (const file of transformedFiles) {
|
|
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
|
+
return xtry_1.OK;
|
|
13
25
|
}
|
|
@@ -5,94 +5,113 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.mergeTextFiles = mergeTextFiles;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
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 index_js_1 = require("../journeys/index.js");
|
|
12
|
+
const detect_indent_js_1 = require("../utils/detect-indent.js");
|
|
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 }) {
|
|
11
15
|
for (const file of textFiles) {
|
|
12
16
|
if (options.verbose) {
|
|
13
|
-
|
|
17
|
+
cli_utils_1.logger.debug(`${file.name} is going to be merged`);
|
|
14
18
|
}
|
|
15
|
-
const journey = routes(file.name) ?? (0,
|
|
19
|
+
const journey = routes(file.name) ?? (0, index_js_1.getJourney)(file.name);
|
|
16
20
|
if (!journey) {
|
|
17
21
|
if (options.verbose) {
|
|
18
|
-
|
|
22
|
+
cli_utils_1.logger.debug(`${file.name}, no merger has been found`);
|
|
19
23
|
}
|
|
20
24
|
const filePath = path_1.default.join(targetPath, file.name);
|
|
21
|
-
|
|
22
|
-
if (exists) {
|
|
25
|
+
if (await async_1.default.isExisting(filePath)) {
|
|
23
26
|
switch (onExisting(file.name)) {
|
|
24
|
-
case 'merge':
|
|
27
|
+
case 'merge': {
|
|
25
28
|
break;
|
|
26
|
-
|
|
29
|
+
}
|
|
30
|
+
case 'overwrite': {
|
|
27
31
|
break;
|
|
28
|
-
|
|
32
|
+
}
|
|
33
|
+
case 'skip': {
|
|
29
34
|
continue;
|
|
35
|
+
}
|
|
30
36
|
}
|
|
31
37
|
}
|
|
32
38
|
else {
|
|
33
39
|
switch (onMissing(file.name)) {
|
|
34
|
-
case 'continue':
|
|
40
|
+
case 'continue': {
|
|
35
41
|
break;
|
|
36
|
-
|
|
42
|
+
}
|
|
43
|
+
case 'skip': {
|
|
37
44
|
continue;
|
|
45
|
+
}
|
|
38
46
|
}
|
|
39
47
|
}
|
|
40
48
|
mergedTextFiles.push(file);
|
|
41
49
|
if (options.verbose) {
|
|
42
|
-
|
|
50
|
+
cli_utils_1.logger.debug(`${file.name} has been copied`);
|
|
43
51
|
}
|
|
44
52
|
continue;
|
|
45
53
|
}
|
|
46
54
|
if (options.verbose) {
|
|
47
|
-
|
|
55
|
+
cli_utils_1.logger.debug(`${file.name}, a merger has been found`);
|
|
48
56
|
}
|
|
49
57
|
const fileName = journey.alias ? path_1.default.join(path_1.default.dirname(file.name), journey.alias) : file.name;
|
|
50
58
|
const filePath = path_1.default.join(targetPath, fileName);
|
|
51
|
-
|
|
52
|
-
if (exists) {
|
|
59
|
+
if (await async_1.default.isExisting(filePath)) {
|
|
53
60
|
switch (onExisting(file.name)) {
|
|
54
61
|
case 'merge': {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
62
|
+
const current = await async_1.default.readFile(filePath, 'utf8');
|
|
63
|
+
if (current.fails) {
|
|
64
|
+
return (0, xtry_1.err)((0, xtry_1.stringifyError)(current.error));
|
|
65
|
+
}
|
|
66
|
+
const finalNewLine = (0, has_final_new_line_js_1.hasFinalNewLine)(current.value);
|
|
67
|
+
const indent = (0, detect_indent_js_1.detectIndent)(current.value);
|
|
68
|
+
const data = await journey.travel({
|
|
69
|
+
current: current.value,
|
|
58
70
|
incoming: file.data,
|
|
59
71
|
filters: filters(file.name),
|
|
72
|
+
transforms: transforms(file.name),
|
|
60
73
|
});
|
|
61
74
|
mergedTextFiles.push({
|
|
62
75
|
name: fileName,
|
|
63
76
|
data,
|
|
64
|
-
finalNewLine
|
|
77
|
+
finalNewLine,
|
|
78
|
+
indent,
|
|
65
79
|
mode: file.mode,
|
|
66
80
|
});
|
|
67
81
|
if (options.verbose) {
|
|
68
|
-
|
|
82
|
+
cli_utils_1.logger.debug(`${file.name} has been merged`);
|
|
69
83
|
}
|
|
70
84
|
break;
|
|
71
85
|
}
|
|
72
|
-
case 'overwrite':
|
|
86
|
+
case 'overwrite': {
|
|
73
87
|
mergedTextFiles.push(file);
|
|
74
88
|
if (options.verbose) {
|
|
75
|
-
|
|
89
|
+
cli_utils_1.logger.debug(`${file.name} has been overwritten`);
|
|
76
90
|
}
|
|
77
91
|
continue;
|
|
78
|
-
|
|
92
|
+
}
|
|
93
|
+
case 'skip': {
|
|
79
94
|
continue;
|
|
95
|
+
}
|
|
80
96
|
}
|
|
81
97
|
}
|
|
82
98
|
else {
|
|
83
99
|
switch (onMissing(file.name)) {
|
|
84
|
-
case 'continue':
|
|
100
|
+
case 'continue': {
|
|
85
101
|
mergedTextFiles.push({
|
|
86
102
|
...file,
|
|
87
103
|
name: fileName,
|
|
88
104
|
});
|
|
89
105
|
if (options.verbose) {
|
|
90
|
-
|
|
106
|
+
cli_utils_1.logger.debug(`${file.name} has been copied`);
|
|
91
107
|
}
|
|
92
108
|
continue;
|
|
93
|
-
|
|
109
|
+
}
|
|
110
|
+
case 'skip': {
|
|
94
111
|
continue;
|
|
112
|
+
}
|
|
95
113
|
}
|
|
96
114
|
}
|
|
97
115
|
}
|
|
116
|
+
return xtry_1.OK;
|
|
98
117
|
}
|
|
@@ -38,50 +38,44 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.readEditorConfig = readEditorConfig;
|
|
40
40
|
const path_1 = __importDefault(require("path"));
|
|
41
|
+
const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
|
|
42
|
+
const xtry_1 = require("@zokugun/xtry");
|
|
41
43
|
const editorconfig = __importStar(require("editorconfig"));
|
|
42
|
-
const
|
|
43
|
-
const format_1 = require("../types/format");
|
|
44
|
+
const format_js_1 = require("../types/format.js");
|
|
44
45
|
function buildFullGlob(glob) {
|
|
45
46
|
switch (glob.indexOf('/')) {
|
|
46
|
-
case -1:
|
|
47
|
+
case -1: {
|
|
47
48
|
glob = '**/' + glob;
|
|
48
49
|
break;
|
|
49
|
-
|
|
50
|
+
}
|
|
51
|
+
case 0: {
|
|
50
52
|
glob = glob.slice(1);
|
|
51
53
|
break;
|
|
52
|
-
|
|
54
|
+
}
|
|
55
|
+
default: {
|
|
53
56
|
break;
|
|
57
|
+
}
|
|
54
58
|
}
|
|
55
|
-
return glob.
|
|
59
|
+
return glob.replaceAll('**', '{*,**/**/**}');
|
|
56
60
|
} // }}}
|
|
57
61
|
async function readEditorConfig({ incomingPath, targetPath, formats }) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
catch {
|
|
65
|
-
}
|
|
66
|
-
if (!data) {
|
|
67
|
-
try {
|
|
68
|
-
const file = path_1.default.join(targetPath, '.editorconfig');
|
|
69
|
-
data = await fs_extra_1.default.readFile(file, 'utf-8');
|
|
70
|
-
}
|
|
71
|
-
catch {
|
|
72
|
-
}
|
|
62
|
+
const incomingFile = path_1.default.join(incomingPath, 'configs', '.editorconfig');
|
|
63
|
+
let readResult = await async_1.default.readFile(incomingFile, 'utf8');
|
|
64
|
+
if (readResult.fails) {
|
|
65
|
+
const targetFile = path_1.default.join(targetPath, '.editorconfig');
|
|
66
|
+
readResult = await async_1.default.readFile(targetFile, 'utf8');
|
|
73
67
|
}
|
|
74
|
-
if (
|
|
75
|
-
return;
|
|
68
|
+
if (readResult.fails) {
|
|
69
|
+
return xtry_1.OK;
|
|
76
70
|
}
|
|
77
|
-
const rules = editorconfig.parseString(
|
|
71
|
+
const rules = editorconfig.parseString(readResult.value);
|
|
78
72
|
for (const [glob, rule] of rules) {
|
|
79
73
|
if (!glob) {
|
|
80
74
|
continue;
|
|
81
75
|
}
|
|
82
76
|
const indentStyle = (rule.indent_style || 'space');
|
|
83
77
|
const indentSize = (rule.indent_size && Number.parseInt(rule.indent_size, 10)) || 2;
|
|
84
|
-
const insertFinalNewline =
|
|
78
|
+
const insertFinalNewline = rule.insert_final_newline === undefined ? true : rule.insert_final_newline === 'true';
|
|
85
79
|
formats.push({
|
|
86
80
|
glob: buildFullGlob(glob),
|
|
87
81
|
indentStyle,
|
|
@@ -91,9 +85,10 @@ async function readEditorConfig({ incomingPath, targetPath, formats }) {
|
|
|
91
85
|
}
|
|
92
86
|
formats.push({
|
|
93
87
|
glob: buildFullGlob('{*.yml,*.yaml}'),
|
|
94
|
-
indentStyle:
|
|
88
|
+
indentStyle: format_js_1.IndentStyle.SPACE,
|
|
95
89
|
indentSize: 2,
|
|
96
90
|
insertFinalNewline: true,
|
|
97
91
|
});
|
|
98
92
|
formats.reverse();
|
|
93
|
+
return xtry_1.OK;
|
|
99
94
|
}
|
package/lib/steps/read-files.js
CHANGED
|
@@ -5,10 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.readFiles = readFiles;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const
|
|
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");
|
|
9
11
|
const globby_1 = __importDefault(require("globby"));
|
|
10
12
|
const istextorbinary_1 = require("istextorbinary");
|
|
11
|
-
const
|
|
13
|
+
const detect_indent_js_1 = require("../utils/detect-indent.js");
|
|
14
|
+
const has_final_new_line_js_1 = require("../utils/has-final-new-line.js");
|
|
15
|
+
const read_buffer_js_1 = require("../utils/read-buffer.js");
|
|
12
16
|
async function readFiles({ incomingPath, textFiles, binaryFiles, options }) {
|
|
13
17
|
const cwd = path_1.default.join(incomingPath, 'configs');
|
|
14
18
|
const files = await (0, globby_1.default)(['**/*', '!**/*.lock', '!**/*-lock.*'], {
|
|
@@ -18,20 +22,30 @@ async function readFiles({ incomingPath, textFiles, binaryFiles, options }) {
|
|
|
18
22
|
for (const file of files) {
|
|
19
23
|
const filePath = path_1.default.join(cwd, file);
|
|
20
24
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
21
|
-
if ((0, istextorbinary_1.isText)(file) || (0, istextorbinary_1.getEncoding)(await (0,
|
|
22
|
-
const
|
|
23
|
-
|
|
25
|
+
if ((0, istextorbinary_1.isText)(file) || (0, istextorbinary_1.getEncoding)(await (0, read_buffer_js_1.readBuffer)(filePath, 24)) === 'utf8') {
|
|
26
|
+
const result = await async_1.default.readFile(filePath, 'utf8');
|
|
27
|
+
if (result.fails) {
|
|
28
|
+
return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
|
|
29
|
+
}
|
|
30
|
+
const data = result.value;
|
|
31
|
+
const finalNewLine = (0, has_final_new_line_js_1.hasFinalNewLine)(data);
|
|
32
|
+
const indent = (0, detect_indent_js_1.detectIndent)(data);
|
|
24
33
|
if (data.startsWith('#!')) {
|
|
25
34
|
// the text file might be executable
|
|
26
|
-
const
|
|
35
|
+
const result = await async_1.default.stat(filePath);
|
|
36
|
+
if (result.fails) {
|
|
37
|
+
return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
|
|
38
|
+
}
|
|
39
|
+
const { mode } = result.value;
|
|
27
40
|
textFiles.push({
|
|
28
41
|
name: file,
|
|
29
42
|
data,
|
|
30
|
-
mode,
|
|
31
43
|
finalNewLine,
|
|
44
|
+
indent,
|
|
45
|
+
mode,
|
|
32
46
|
});
|
|
33
47
|
if (options.verbose) {
|
|
34
|
-
|
|
48
|
+
cli_utils_1.logger.debug(`${file} is a shebang file`);
|
|
35
49
|
}
|
|
36
50
|
}
|
|
37
51
|
else {
|
|
@@ -39,9 +53,10 @@ async function readFiles({ incomingPath, textFiles, binaryFiles, options }) {
|
|
|
39
53
|
name: file,
|
|
40
54
|
data,
|
|
41
55
|
finalNewLine,
|
|
56
|
+
indent,
|
|
42
57
|
});
|
|
43
58
|
if (options.verbose) {
|
|
44
|
-
|
|
59
|
+
cli_utils_1.logger.debug(`${file} is a text file`);
|
|
45
60
|
}
|
|
46
61
|
}
|
|
47
62
|
}
|
|
@@ -51,8 +66,9 @@ async function readFiles({ incomingPath, textFiles, binaryFiles, options }) {
|
|
|
51
66
|
target: file,
|
|
52
67
|
});
|
|
53
68
|
if (options.verbose) {
|
|
54
|
-
|
|
69
|
+
cli_utils_1.logger.debug(`${file} is a binary file`);
|
|
55
70
|
}
|
|
56
71
|
}
|
|
57
72
|
}
|
|
73
|
+
return xtry_1.OK;
|
|
58
74
|
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.readIncomingConfig = readIncomingConfig;
|
|
4
|
-
const
|
|
4
|
+
const xtry_1 = require("@zokugun/xtry");
|
|
5
|
+
const index_js_1 = require("../configs/index.js");
|
|
5
6
|
async function readIncomingConfig(context) {
|
|
6
7
|
if (!context.incomingConfig) {
|
|
7
|
-
const config = await (0,
|
|
8
|
-
if (
|
|
9
|
-
return
|
|
8
|
+
const config = await (0, index_js_1.readPackageConfig)(context.incomingPath);
|
|
9
|
+
if (config.fails) {
|
|
10
|
+
return config;
|
|
10
11
|
}
|
|
11
|
-
context.incomingConfig = config;
|
|
12
|
+
context.incomingConfig = config.value;
|
|
12
13
|
}
|
|
14
|
+
return xtry_1.OK;
|
|
13
15
|
}
|
|
@@ -5,18 +5,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.readIncomingPackage = readIncomingPackage;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
|
|
9
|
+
const xtry_1 = require("@zokugun/xtry");
|
|
10
|
+
const lodash_es_1 = require("lodash-es");
|
|
10
11
|
async function readIncomingPackage(context) {
|
|
11
12
|
const filePath = path_1.default.resolve(context.incomingPath, './package.json');
|
|
12
|
-
const
|
|
13
|
-
if (
|
|
14
|
-
|
|
13
|
+
const result = await async_1.default.readJSON(filePath);
|
|
14
|
+
if (result.fails) {
|
|
15
|
+
return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
+
if (!isPackageManifest(result.value)) {
|
|
18
|
+
return (0, xtry_1.err)('The package of the incoming artifact can\'t be found.');
|
|
19
|
+
}
|
|
20
|
+
context.incomingPackage = result.value;
|
|
21
|
+
return xtry_1.OK;
|
|
17
22
|
}
|
|
18
23
|
function isPackageManifest(value) {
|
|
19
|
-
if ((0,
|
|
24
|
+
if ((0, lodash_es_1.isNil)(value) || !(0, lodash_es_1.isPlainObject)(value)) {
|
|
20
25
|
return false;
|
|
21
26
|
}
|
|
22
27
|
const manifest = value;
|
|
@@ -5,12 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.removeFiles = removeFiles;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const
|
|
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");
|
|
9
11
|
const globby_1 = __importDefault(require("globby"));
|
|
10
12
|
const micromatch_1 = require("micromatch");
|
|
11
13
|
async function removeFiles({ removedPatterns, targetPath, options }) {
|
|
12
14
|
if (removedPatterns.length === 0) {
|
|
13
|
-
return;
|
|
15
|
+
return xtry_1.OK;
|
|
14
16
|
}
|
|
15
17
|
const cwd = path_1.default.join(targetPath);
|
|
16
18
|
const files = await (0, globby_1.default)(['**/*', '!**/*.lock', '!**/*-lock.*', '!.git'], {
|
|
@@ -21,11 +23,15 @@ async function removeFiles({ removedPatterns, targetPath, options }) {
|
|
|
21
23
|
if ((0, micromatch_1.isMatch)(file, removedPatterns)) {
|
|
22
24
|
if (!options.dryRun) {
|
|
23
25
|
const filePath = path_1.default.join(cwd, file);
|
|
24
|
-
await
|
|
26
|
+
const result = await async_1.default.unlink(filePath);
|
|
27
|
+
if (result.fails) {
|
|
28
|
+
return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
|
|
29
|
+
}
|
|
25
30
|
}
|
|
26
31
|
if (options.verbose) {
|
|
27
|
-
|
|
32
|
+
cli_utils_1.logger.debug(`${file} has been removed`);
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
35
|
}
|
|
36
|
+
return xtry_1.OK;
|
|
31
37
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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.renameFiles = renameFiles;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
|
|
9
|
+
const xtry_1 = require("@zokugun/xtry");
|
|
10
|
+
async function renameFiles({ renamedPatterns, targetPath }) {
|
|
11
|
+
if (renamedPatterns.length === 0) {
|
|
12
|
+
return xtry_1.OK;
|
|
13
|
+
}
|
|
14
|
+
const cwd = path_1.default.join(targetPath);
|
|
15
|
+
for (const { from, to } of renamedPatterns) {
|
|
16
|
+
const fromPath = path_1.default.join(cwd, from);
|
|
17
|
+
if (await async_1.default.isExisting(fromPath)) {
|
|
18
|
+
const result = await async_1.default.rename(fromPath, path_1.default.join(cwd, to));
|
|
19
|
+
if (result.fails) {
|
|
20
|
+
return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return xtry_1.OK;
|
|
25
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.replaceTemplates = replaceTemplates;
|
|
4
|
-
const
|
|
4
|
+
const xtry_1 = require("@zokugun/xtry");
|
|
5
|
+
const template_js_1 = require("../utils/template.js");
|
|
5
6
|
async function replaceTemplates({ textFiles, binaryFiles, targetPath, config, incomingConfig }) {
|
|
6
7
|
const variables = {
|
|
7
8
|
...incomingConfig?.variables,
|
|
@@ -9,12 +10,25 @@ async function replaceTemplates({ textFiles, binaryFiles, targetPath, config, in
|
|
|
9
10
|
...incomingConfig?.constants,
|
|
10
11
|
...config?.constants,
|
|
11
12
|
};
|
|
12
|
-
const engine = new
|
|
13
|
+
const engine = new template_js_1.TemplateEngine(targetPath, variables);
|
|
13
14
|
for (const file of textFiles) {
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
const dataResult = engine.render(file.data);
|
|
16
|
+
if (dataResult.fails) {
|
|
17
|
+
return dataResult;
|
|
18
|
+
}
|
|
19
|
+
const nameResult = engine.render(file.name);
|
|
20
|
+
if (nameResult.fails) {
|
|
21
|
+
return nameResult;
|
|
22
|
+
}
|
|
23
|
+
file.data = dataResult.value;
|
|
24
|
+
file.name = nameResult.value;
|
|
16
25
|
}
|
|
17
26
|
for (const file of binaryFiles) {
|
|
18
|
-
|
|
27
|
+
const targetResult = engine.render(file.target);
|
|
28
|
+
if (targetResult.fails) {
|
|
29
|
+
return targetResult;
|
|
30
|
+
}
|
|
31
|
+
file.target = targetResult.value;
|
|
19
32
|
}
|
|
33
|
+
return xtry_1.OK;
|
|
20
34
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.transformUntouchedFiles = transformUntouchedFiles;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const cli_utils_1 = require("@zokugun/cli-utils");
|
|
9
|
+
const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
|
|
10
|
+
const is_it_type_1 = require("@zokugun/is-it-type");
|
|
11
|
+
const xtry_1 = require("@zokugun/xtry");
|
|
12
|
+
const globby_1 = __importDefault(require("globby"));
|
|
13
|
+
const index_js_1 = require("../journeys/index.js");
|
|
14
|
+
const detect_indent_js_1 = require("../utils/detect-indent.js");
|
|
15
|
+
const has_final_new_line_js_1 = require("../utils/has-final-new-line.js");
|
|
16
|
+
async function transformUntouchedFiles({ formats, options, routes, targetPath, textFiles, transformedFiles, transforms }) {
|
|
17
|
+
if (transforms.length === 0) {
|
|
18
|
+
return xtry_1.OK;
|
|
19
|
+
}
|
|
20
|
+
const cwd = path_1.default.join(targetPath);
|
|
21
|
+
const files = await (0, globby_1.default)(['**/*', '!**/*.lock', '!**/*-lock.*'], {
|
|
22
|
+
cwd,
|
|
23
|
+
dot: true,
|
|
24
|
+
});
|
|
25
|
+
for (const file of files) {
|
|
26
|
+
if (textFiles.some(({ name }) => name === file)) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const transformations = transforms(file);
|
|
30
|
+
if (!transformations || (0, is_it_type_1.isEmptyArray)(transformations)) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const journey = routes(file) ?? (0, index_js_1.getJourney)(file);
|
|
34
|
+
if (!journey) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (options.verbose) {
|
|
38
|
+
cli_utils_1.logger.debug(`${file} is going to be transformed`);
|
|
39
|
+
}
|
|
40
|
+
const filePath = path_1.default.join(cwd, file);
|
|
41
|
+
const result = await async_1.default.readFile(filePath, 'utf8');
|
|
42
|
+
if (result.fails) {
|
|
43
|
+
return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
|
|
44
|
+
}
|
|
45
|
+
const data = result.value;
|
|
46
|
+
const finalNewLine = (0, has_final_new_line_js_1.hasFinalNewLine)(data);
|
|
47
|
+
const indent = (0, detect_indent_js_1.detectIndent)(data);
|
|
48
|
+
const transformed = await journey.travel({
|
|
49
|
+
current: data,
|
|
50
|
+
incoming: undefined,
|
|
51
|
+
transforms: transformations,
|
|
52
|
+
});
|
|
53
|
+
transformedFiles.push({
|
|
54
|
+
name: file,
|
|
55
|
+
data: transformed,
|
|
56
|
+
finalNewLine,
|
|
57
|
+
indent,
|
|
58
|
+
});
|
|
59
|
+
if (options.verbose) {
|
|
60
|
+
cli_utils_1.logger.debug(`${file} has been transformed`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return xtry_1.OK;
|
|
64
|
+
}
|