@zokugun/artifact 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +123 -80
- 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 +17 -9
- 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 +159 -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 +68 -0
- package/lib/configs/utils/normalize-file-always.d.ts +3 -0
- package/lib/configs/utils/normalize-file-always.js +28 -0
- package/lib/configs/utils/normalize-file-uninstall.d.ts +3 -0
- package/lib/configs/utils/normalize-file-uninstall.js +31 -0
- package/lib/configs/utils/normalize-file-upsert.d.ts +3 -0
- package/lib/configs/utils/normalize-file-upsert.js +54 -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 +19 -15
- 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 +41 -86
- package/lib/steps/configure-uninstall-file-actions.d.ts +3 -0
- package/lib/steps/configure-uninstall-file-actions.js +53 -0
- package/lib/steps/configure-update-file-actions.d.ts +3 -0
- package/lib/steps/configure-update-file-actions.js +64 -97
- 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 +41 -27
- 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 +19 -8
- 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 +73 -0
- package/lib/steps/unmerge-text-files.d.ts +3 -0
- package/lib/steps/unmerge-text-files.js +63 -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 +58 -0
- package/lib/types/context.d.ts +56 -0
- package/lib/types/format.d.ts +10 -0
- package/lib/types/step.d.ts +3 -0
- package/lib/types/text-file.d.ts +7 -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 +5 -0
- package/lib/utils/detect-indent.js +60 -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 +123 -101
- package/lib/utils/dev-null.js +0 -7
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapDelete = mapDelete;
|
|
4
|
+
const is_it_type_1 = require("@zokugun/is-it-type");
|
|
5
|
+
async function mapDelete({ current, incoming }) {
|
|
6
|
+
if (!incoming) {
|
|
7
|
+
return current ?? {};
|
|
8
|
+
}
|
|
9
|
+
if (!current) {
|
|
10
|
+
return {};
|
|
11
|
+
}
|
|
12
|
+
for (const [key, value] of Object.entries(incoming)) {
|
|
13
|
+
if ((0, is_it_type_1.isArray)(value) && (0, is_it_type_1.isArray)(current[key])) {
|
|
14
|
+
return current;
|
|
15
|
+
}
|
|
16
|
+
else if ((0, is_it_type_1.isRecord)(value) && (0, is_it_type_1.isRecord)(current[key])) {
|
|
17
|
+
const newValue = await mapDelete({ current: current[key], incoming: value });
|
|
18
|
+
if ((0, is_it_type_1.isEmptyRecord)(newValue)) {
|
|
19
|
+
delete current[key];
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
current[key] = newValue;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
if (current[key] === value) {
|
|
27
|
+
delete current[key];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return current;
|
|
32
|
+
}
|
package/lib/routes/overwrite.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.overwrite = overwrite;
|
|
4
|
-
function overwrite({ current, incoming }) {
|
|
5
|
-
if (
|
|
4
|
+
async function overwrite({ current, incoming }) {
|
|
5
|
+
if (incoming === undefined) {
|
|
6
6
|
return current ?? [];
|
|
7
7
|
}
|
|
8
8
|
else {
|
package/lib/routes/primitive.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.primitive = primitive;
|
|
4
|
-
function primitive({ current, incoming }) {
|
|
5
|
-
if (
|
|
4
|
+
async function primitive({ current, incoming }) {
|
|
5
|
+
if (incoming === undefined) {
|
|
6
6
|
return current ?? [];
|
|
7
7
|
}
|
|
8
|
-
if (
|
|
8
|
+
if (current === undefined) {
|
|
9
9
|
return incoming;
|
|
10
10
|
}
|
|
11
11
|
if (current === incoming) {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type AsyncDResult } from '@zokugun/xtry';
|
|
2
|
+
import { type Format } from '../types/format.js';
|
|
3
|
+
import { type TextFile } from '../types/text-file.js';
|
|
4
|
+
export declare function applyFormatting({ formats, mergedTextFiles, transformedFiles }: {
|
|
5
|
+
formats: Format[];
|
|
6
|
+
mergedTextFiles: TextFile[];
|
|
7
|
+
transformedFiles?: TextFile[];
|
|
8
|
+
}): AsyncDResult;
|
|
@@ -4,11 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.applyFormatting = applyFormatting;
|
|
7
|
+
const xtry_1 = require("@zokugun/xtry");
|
|
7
8
|
const detect_indent_1 = __importDefault(require("detect-indent"));
|
|
8
|
-
const
|
|
9
|
-
const
|
|
9
|
+
const format_js_1 = require("../types/format.js");
|
|
10
|
+
const get_format_js_1 = require("../utils/get-format.js");
|
|
10
11
|
function applyFormat(file, format) {
|
|
11
|
-
if (format.indentStyle ===
|
|
12
|
+
if (format.indentStyle === format_js_1.IndentStyle.SPACE) {
|
|
12
13
|
file.data = indentWithSpace(file.data, format.indentSize);
|
|
13
14
|
}
|
|
14
15
|
else {
|
|
@@ -21,10 +22,6 @@ function applyFormat(file, format) {
|
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
} // }}}
|
|
24
|
-
function fnmatch(filepath, glob) {
|
|
25
|
-
const matchOptions = { matchBase: true, dot: true, noext: true };
|
|
26
|
-
return (0, fnmatch_1.default)(filepath, glob, matchOptions);
|
|
27
|
-
} // }}}
|
|
28
25
|
function indentWithSpace(data, size) {
|
|
29
26
|
const { type, indent } = (0, detect_indent_1.default)(data);
|
|
30
27
|
if (type === 'space') {
|
|
@@ -32,14 +29,14 @@ function indentWithSpace(data, size) {
|
|
|
32
29
|
return data;
|
|
33
30
|
}
|
|
34
31
|
else {
|
|
35
|
-
data = data.
|
|
32
|
+
data = data.replaceAll(new RegExp(indent, 'gm'), '\t');
|
|
36
33
|
const newIndent = ' '.repeat(size);
|
|
37
|
-
return data.
|
|
34
|
+
return data.replaceAll(/\t/gm, newIndent);
|
|
38
35
|
}
|
|
39
36
|
}
|
|
40
37
|
else if (type === 'tab') {
|
|
41
38
|
const newIndent = ' '.repeat(size);
|
|
42
|
-
return data.
|
|
39
|
+
return data.replaceAll(new RegExp(indent, 'gm'), newIndent);
|
|
43
40
|
}
|
|
44
41
|
else {
|
|
45
42
|
return data;
|
|
@@ -48,19 +45,26 @@ function indentWithSpace(data, size) {
|
|
|
48
45
|
function indentWithTab(data) {
|
|
49
46
|
const { type, indent, amount } = (0, detect_indent_1.default)(data);
|
|
50
47
|
if (type === 'space' && amount > 1) {
|
|
51
|
-
return data.
|
|
48
|
+
return data.replaceAll(new RegExp(indent, 'gm'), '\t');
|
|
52
49
|
}
|
|
53
50
|
else {
|
|
54
51
|
return data;
|
|
55
52
|
}
|
|
56
53
|
} // }}}
|
|
57
|
-
async function applyFormatting({ mergedTextFiles,
|
|
54
|
+
async function applyFormatting({ formats, mergedTextFiles, transformedFiles }) {
|
|
58
55
|
for (const file of mergedTextFiles) {
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
const format = (0, get_format_js_1.getFormat)(file.name, formats);
|
|
57
|
+
if (format) {
|
|
58
|
+
applyFormat(file, format);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (transformedFiles) {
|
|
62
|
+
for (const file of transformedFiles) {
|
|
63
|
+
const format = (0, get_format_js_1.getFormat)(file.name, formats);
|
|
64
|
+
if (format) {
|
|
61
65
|
applyFormat(file, format);
|
|
62
|
-
break;
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
68
|
}
|
|
69
|
+
return xtry_1.OK;
|
|
66
70
|
}
|
|
@@ -5,11 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.configureBranches = configureBranches;
|
|
7
7
|
const node_path_1 = __importDefault(require("node: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
|
async function configureBranches(context) {
|
|
11
13
|
const cwd = node_path_1.default.join(context.incomingPath, 'branches');
|
|
12
|
-
if (await
|
|
14
|
+
if (await async_1.default.isExisting(cwd)) {
|
|
13
15
|
const directories = await (0, globby_1.default)('*', {
|
|
14
16
|
cwd,
|
|
15
17
|
onlyDirectories: true,
|
|
@@ -19,7 +21,7 @@ async function configureBranches(context) {
|
|
|
19
21
|
const match = /^\[(@[\w-]+:[\w-]+|[\w-]+)(?::([\w-]+))?]$/.exec(directory);
|
|
20
22
|
if (match) {
|
|
21
23
|
const [branch, name, variant] = match;
|
|
22
|
-
const packageName = name.
|
|
24
|
+
const packageName = name.replaceAll(/:(artifact-)?/g, '/artifact-');
|
|
23
25
|
const artifact = context.config.artifacts[packageName];
|
|
24
26
|
let found = false;
|
|
25
27
|
if (artifact) {
|
|
@@ -44,7 +46,7 @@ async function configureBranches(context) {
|
|
|
44
46
|
}
|
|
45
47
|
if (found) {
|
|
46
48
|
if (context.options.verbose) {
|
|
47
|
-
|
|
49
|
+
cli_utils_1.logger.debug(`- branch: ${name}${variant ? `:${variant}` : ''} has been matched`);
|
|
48
50
|
}
|
|
49
51
|
bucket.push({
|
|
50
52
|
name: context.incomingName,
|
|
@@ -56,11 +58,12 @@ async function configureBranches(context) {
|
|
|
56
58
|
}
|
|
57
59
|
else {
|
|
58
60
|
if (context.options.verbose) {
|
|
59
|
-
|
|
61
|
+
cli_utils_1.logger.debug(`- branch: ${name}${variant ? `:${variant}` : ''} hasn't been matched (${artifact ? 'variant' : 'artifact'} not found)`);
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
}
|
|
64
66
|
context.blocks.unshift(...bucket);
|
|
65
67
|
}
|
|
68
|
+
return xtry_1.OK;
|
|
66
69
|
}
|
|
@@ -1,123 +1,67 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.configureInstallFileActions = configureInstallFileActions;
|
|
4
|
-
const
|
|
4
|
+
const is_it_type_1 = require("@zokugun/is-it-type");
|
|
5
|
+
const xtry_1 = require("@zokugun/xtry");
|
|
5
6
|
const micromatch_1 = require("micromatch");
|
|
6
|
-
const
|
|
7
|
-
const routes_1 = require("../routes");
|
|
8
|
-
function buildRoute(route) {
|
|
9
|
-
if (Array.isArray(route) && route.length > 0) {
|
|
10
|
-
let result = buildRoute(route[0]);
|
|
11
|
-
for (let i = 1; i < route.length; i++) {
|
|
12
|
-
if (route[i] === 'mapSort') {
|
|
13
|
-
result = (0, compositors_1.mapSort)(result);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
throw new Error('Can\'t build route');
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return result;
|
|
20
|
-
}
|
|
21
|
-
else if ((0, lodash_1.isPlainObject)(route)) {
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
23
|
-
const { compose: rtCompose, fork: rtFork, mapSort: rtMapSort } = route;
|
|
24
|
-
if (rtCompose) {
|
|
25
|
-
const map = {};
|
|
26
|
-
for (const [name, route] of Object.entries(rtCompose)) {
|
|
27
|
-
map[name] = buildRoute(route);
|
|
28
|
-
}
|
|
29
|
-
return (0, compositors_1.compose)(map);
|
|
30
|
-
}
|
|
31
|
-
else if (rtFork) {
|
|
32
|
-
const map = [];
|
|
33
|
-
if (rtFork.array) {
|
|
34
|
-
map.push([Array.isArray, buildRoute(rtFork.array)]);
|
|
35
|
-
}
|
|
36
|
-
if (rtFork.object) {
|
|
37
|
-
map.push([lodash_1.isPlainObject, buildRoute(rtFork.object)]);
|
|
38
|
-
}
|
|
39
|
-
if (rtFork.default) {
|
|
40
|
-
map.push(buildRoute(rtFork.default));
|
|
41
|
-
}
|
|
42
|
-
return (0, compositors_1.fork)(...map);
|
|
43
|
-
}
|
|
44
|
-
else if (rtMapSort) {
|
|
45
|
-
return (0, compositors_1.mapSort)(buildRoute(rtMapSort));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
else if (route === 'command') {
|
|
49
|
-
return routes_1.command;
|
|
50
|
-
}
|
|
51
|
-
else if (route === 'linesConcat') {
|
|
52
|
-
return routes_1.linesConcat;
|
|
53
|
-
}
|
|
54
|
-
else if (route === 'listConcat') {
|
|
55
|
-
return routes_1.listConcat;
|
|
56
|
-
}
|
|
57
|
-
else if (route === 'mapConcat') {
|
|
58
|
-
return routes_1.mapConcat;
|
|
59
|
-
}
|
|
60
|
-
else if (route === 'overwrite') {
|
|
61
|
-
return routes_1.overwrite;
|
|
62
|
-
}
|
|
63
|
-
else if (route === 'primitive') {
|
|
64
|
-
return routes_1.primitive;
|
|
65
|
-
}
|
|
66
|
-
throw new Error('Can\'t build route');
|
|
67
|
-
} // }}}
|
|
68
|
-
function buildTravel(route) {
|
|
69
|
-
if (route.json) {
|
|
70
|
-
return (0, compositors_1.json)(buildRoute(route.json));
|
|
71
|
-
}
|
|
72
|
-
else if (route.rc) {
|
|
73
|
-
return (0, compositors_1.rc)(buildRoute(route.rc));
|
|
74
|
-
}
|
|
75
|
-
else if (route.yaml) {
|
|
76
|
-
return (0, compositors_1.yaml)(buildRoute(route.yaml));
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
throw new Error('Can\'t build route');
|
|
80
|
-
}
|
|
81
|
-
} // }}}
|
|
7
|
+
const build_travel_js_1 = require("../utils/build-travel.js");
|
|
82
8
|
async function configureInstallFileActions(context) {
|
|
83
9
|
const { install } = context.incomingConfig;
|
|
84
10
|
if (!install) {
|
|
85
|
-
return;
|
|
11
|
+
return xtry_1.OK;
|
|
86
12
|
}
|
|
87
13
|
const overwrites = [];
|
|
88
14
|
const filters = {};
|
|
89
15
|
const routes = {};
|
|
16
|
+
const transformations = {};
|
|
90
17
|
for (const [file, fileUpdate] of Object.entries(install)) {
|
|
91
|
-
const {
|
|
92
|
-
if (
|
|
93
|
-
context.
|
|
18
|
+
const { filter, ifExists, rename, route, transforms } = fileUpdate;
|
|
19
|
+
if (rename) {
|
|
20
|
+
context.renamedPatterns.push({
|
|
21
|
+
from: file,
|
|
22
|
+
to: rename,
|
|
23
|
+
});
|
|
94
24
|
continue;
|
|
95
25
|
}
|
|
96
|
-
if (overwrite) {
|
|
26
|
+
if (ifExists === 'overwrite') {
|
|
97
27
|
overwrites.push(file);
|
|
98
28
|
}
|
|
29
|
+
else if (ifExists === 'remove') {
|
|
30
|
+
context.removedPatterns.push(file);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
else if (ifExists === 'skip') {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
99
36
|
if (filter) {
|
|
100
37
|
filters[file] = filter;
|
|
101
38
|
}
|
|
102
39
|
if (route) {
|
|
103
40
|
const { alias } = route;
|
|
41
|
+
const travel = (0, build_travel_js_1.buildTravel)(route);
|
|
42
|
+
if (travel.fails) {
|
|
43
|
+
return travel;
|
|
44
|
+
}
|
|
104
45
|
if (alias) {
|
|
105
46
|
routes[file] = {
|
|
106
47
|
alias,
|
|
107
|
-
travel:
|
|
48
|
+
travel: travel.value,
|
|
108
49
|
};
|
|
109
50
|
}
|
|
110
51
|
else {
|
|
111
52
|
routes[file] = {
|
|
112
|
-
travel:
|
|
53
|
+
travel: travel.value,
|
|
113
54
|
};
|
|
114
55
|
}
|
|
115
56
|
}
|
|
57
|
+
if (transforms) {
|
|
58
|
+
transformations[file] = transforms;
|
|
59
|
+
}
|
|
116
60
|
}
|
|
117
61
|
if (overwrites.length > 0) {
|
|
118
62
|
context.onExisting = (file) => (0, micromatch_1.isMatch)(file, overwrites) ? 'overwrite' : 'merge';
|
|
119
63
|
}
|
|
120
|
-
if (
|
|
64
|
+
if ((0, is_it_type_1.isNonEmptyRecord)(filters)) {
|
|
121
65
|
context.filters = (file) => {
|
|
122
66
|
for (const [pattern, value] of Object.entries(filters)) {
|
|
123
67
|
if ((0, micromatch_1.isMatch)(file, pattern)) {
|
|
@@ -127,7 +71,7 @@ async function configureInstallFileActions(context) {
|
|
|
127
71
|
return undefined;
|
|
128
72
|
};
|
|
129
73
|
}
|
|
130
|
-
if (
|
|
74
|
+
if ((0, is_it_type_1.isNonEmptyRecord)(routes)) {
|
|
131
75
|
context.routes = (file) => {
|
|
132
76
|
for (const [pattern, route] of Object.entries(routes)) {
|
|
133
77
|
if ((0, micromatch_1.isMatch)(file, pattern)) {
|
|
@@ -137,4 +81,15 @@ async function configureInstallFileActions(context) {
|
|
|
137
81
|
return undefined;
|
|
138
82
|
};
|
|
139
83
|
}
|
|
84
|
+
if ((0, is_it_type_1.isNonEmptyRecord)(transformations)) {
|
|
85
|
+
context.transforms = (file) => {
|
|
86
|
+
for (const [pattern, transforms] of Object.entries(transformations)) {
|
|
87
|
+
if ((0, micromatch_1.isMatch)(file, pattern)) {
|
|
88
|
+
return transforms;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return undefined;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return xtry_1.OK;
|
|
140
95
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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.configureUninstallFileActions = configureUninstallFileActions;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
|
|
9
|
+
const is_it_type_1 = require("@zokugun/is-it-type");
|
|
10
|
+
const xtry_1 = require("@zokugun/xtry");
|
|
11
|
+
const micromatch_1 = require("micromatch");
|
|
12
|
+
async function configureUninstallFileActions(context) {
|
|
13
|
+
const { uninstall } = context.incomingConfig;
|
|
14
|
+
if (!uninstall) {
|
|
15
|
+
return xtry_1.OK;
|
|
16
|
+
}
|
|
17
|
+
const cwd = node_path_1.default.join(context.incomingPath, 'configs');
|
|
18
|
+
const transformations = {};
|
|
19
|
+
for (const [file, fileUpdate] of Object.entries(uninstall)) {
|
|
20
|
+
const { ifExists, transforms } = fileUpdate;
|
|
21
|
+
if (ifExists === 'remove') {
|
|
22
|
+
context.removedPatterns.push(file);
|
|
23
|
+
}
|
|
24
|
+
else if (ifExists === 'unmerge') {
|
|
25
|
+
const filePath = node_path_1.default.join(cwd, file);
|
|
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 = data.endsWith('\n');
|
|
32
|
+
context.textFiles.push({
|
|
33
|
+
name: file,
|
|
34
|
+
data,
|
|
35
|
+
finalNewLine,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (transforms) {
|
|
39
|
+
transformations[file] = transforms;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if ((0, is_it_type_1.isNonEmptyRecord)(transformations)) {
|
|
43
|
+
context.transforms = (file) => {
|
|
44
|
+
for (const [pattern, transforms] of Object.entries(transformations)) {
|
|
45
|
+
if ((0, micromatch_1.isMatch)(file, pattern)) {
|
|
46
|
+
return transforms;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return undefined;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return xtry_1.OK;
|
|
53
|
+
}
|
|
@@ -1,134 +1,90 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.configureUpdateFileActions = configureUpdateFileActions;
|
|
4
|
-
const
|
|
4
|
+
const is_it_type_1 = require("@zokugun/is-it-type");
|
|
5
|
+
const xtry_1 = require("@zokugun/xtry");
|
|
5
6
|
const micromatch_1 = require("micromatch");
|
|
6
|
-
const
|
|
7
|
-
const routes_1 = require("../routes");
|
|
8
|
-
function buildRoute(route) {
|
|
9
|
-
if (Array.isArray(route) && route.length > 0) {
|
|
10
|
-
let result = buildRoute(route[0]);
|
|
11
|
-
for (let i = 1; i < route.length; i++) {
|
|
12
|
-
if (route[i] === 'mapSort') {
|
|
13
|
-
result = (0, compositors_1.mapSort)(result);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
throw new Error('Can\'t build route');
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return result;
|
|
20
|
-
}
|
|
21
|
-
else if ((0, lodash_1.isPlainObject)(route)) {
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
23
|
-
const { compose: rtCompose, fork: rtFork, mapSort: rtMapSort } = route;
|
|
24
|
-
if (rtCompose) {
|
|
25
|
-
const map = {};
|
|
26
|
-
for (const [name, route] of Object.entries(rtCompose)) {
|
|
27
|
-
map[name] = buildRoute(route);
|
|
28
|
-
}
|
|
29
|
-
return (0, compositors_1.compose)(map);
|
|
30
|
-
}
|
|
31
|
-
else if (rtFork) {
|
|
32
|
-
const map = [];
|
|
33
|
-
if (rtFork.array) {
|
|
34
|
-
map.push([Array.isArray, buildRoute(rtFork.array)]);
|
|
35
|
-
}
|
|
36
|
-
if (rtFork.object) {
|
|
37
|
-
map.push([lodash_1.isPlainObject, buildRoute(rtFork.object)]);
|
|
38
|
-
}
|
|
39
|
-
if (rtFork.default) {
|
|
40
|
-
map.push(buildRoute(rtFork.default));
|
|
41
|
-
}
|
|
42
|
-
return (0, compositors_1.fork)(...map);
|
|
43
|
-
}
|
|
44
|
-
else if (rtMapSort) {
|
|
45
|
-
return (0, compositors_1.mapSort)(buildRoute(rtMapSort));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
else if (route === 'command') {
|
|
49
|
-
return routes_1.command;
|
|
50
|
-
}
|
|
51
|
-
else if (route === 'linesConcat') {
|
|
52
|
-
return routes_1.linesConcat;
|
|
53
|
-
}
|
|
54
|
-
else if (route === 'listConcat') {
|
|
55
|
-
return routes_1.listConcat;
|
|
56
|
-
}
|
|
57
|
-
else if (route === 'mapConcat') {
|
|
58
|
-
return routes_1.mapConcat;
|
|
59
|
-
}
|
|
60
|
-
else if (route === 'overwrite') {
|
|
61
|
-
return routes_1.overwrite;
|
|
62
|
-
}
|
|
63
|
-
else if (route === 'primitive') {
|
|
64
|
-
return routes_1.primitive;
|
|
65
|
-
}
|
|
66
|
-
throw new Error('Can\'t build route');
|
|
67
|
-
} // }}}
|
|
68
|
-
function buildTravel(route) {
|
|
69
|
-
if (route.json) {
|
|
70
|
-
return (0, compositors_1.json)(buildRoute(route.json));
|
|
71
|
-
}
|
|
72
|
-
else if (route.rc) {
|
|
73
|
-
return (0, compositors_1.rc)(buildRoute(route.rc));
|
|
74
|
-
}
|
|
75
|
-
else if (route.yaml) {
|
|
76
|
-
return (0, compositors_1.yaml)(buildRoute(route.yaml));
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
throw new Error('Can\'t build route');
|
|
80
|
-
}
|
|
81
|
-
} // }}}
|
|
7
|
+
const build_travel_js_1 = require("../utils/build-travel.js");
|
|
82
8
|
async function configureUpdateFileActions(context) {
|
|
83
9
|
const { update } = context.incomingConfig;
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
context.onMissing = () => 'skip';
|
|
88
|
-
}
|
|
10
|
+
if (update === false) {
|
|
11
|
+
context.onExisting = () => 'skip';
|
|
12
|
+
context.onMissing = () => 'skip';
|
|
89
13
|
}
|
|
90
|
-
else
|
|
91
|
-
const
|
|
92
|
-
|
|
14
|
+
else {
|
|
15
|
+
const existingActions = {
|
|
16
|
+
merge: [],
|
|
17
|
+
overwrite: [],
|
|
18
|
+
skip: [],
|
|
19
|
+
};
|
|
93
20
|
const skipMissings = [];
|
|
94
21
|
const filters = {};
|
|
95
22
|
const routes = {};
|
|
23
|
+
const transformations = {};
|
|
96
24
|
for (const [file, fileUpdate] of Object.entries(update)) {
|
|
97
|
-
const {
|
|
98
|
-
if (
|
|
25
|
+
const { filter, ifExists, ifMissing, rename, route, transforms } = fileUpdate;
|
|
26
|
+
if (rename) {
|
|
27
|
+
context.renamedPatterns.push({
|
|
28
|
+
from: file,
|
|
29
|
+
to: rename,
|
|
30
|
+
});
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (ifMissing === 'skip') {
|
|
99
34
|
skipMissings.push(file);
|
|
100
35
|
}
|
|
101
|
-
if (
|
|
102
|
-
|
|
36
|
+
if (ifExists === 'force-merge') {
|
|
37
|
+
existingActions.merge.push(file);
|
|
38
|
+
}
|
|
39
|
+
else if (ifExists === 'skip') {
|
|
40
|
+
existingActions.skip.push(file);
|
|
41
|
+
}
|
|
42
|
+
else if (ifExists === 'overwrite') {
|
|
43
|
+
existingActions.overwrite.push(file);
|
|
103
44
|
}
|
|
104
|
-
else if (
|
|
105
|
-
|
|
45
|
+
else if (ifExists === 'remove') {
|
|
46
|
+
context.removedPatterns.push(file);
|
|
47
|
+
continue;
|
|
106
48
|
}
|
|
107
49
|
if (filter) {
|
|
108
50
|
filters[file] = filter;
|
|
109
51
|
}
|
|
110
52
|
if (route) {
|
|
111
53
|
const { alias } = route;
|
|
54
|
+
const travel = (0, build_travel_js_1.buildTravel)(route);
|
|
55
|
+
if (travel.fails) {
|
|
56
|
+
return travel;
|
|
57
|
+
}
|
|
112
58
|
if (alias) {
|
|
113
59
|
routes[file] = {
|
|
114
60
|
alias,
|
|
115
|
-
travel:
|
|
61
|
+
travel: travel.value,
|
|
116
62
|
};
|
|
117
63
|
}
|
|
118
64
|
else {
|
|
119
65
|
routes[file] = {
|
|
120
|
-
travel:
|
|
66
|
+
travel: travel.value,
|
|
121
67
|
};
|
|
122
68
|
}
|
|
123
69
|
}
|
|
70
|
+
if (transforms) {
|
|
71
|
+
transformations[file] = transforms;
|
|
72
|
+
}
|
|
124
73
|
}
|
|
125
74
|
if (skipMissings.length > 0) {
|
|
126
75
|
context.onMissing = (file) => (0, micromatch_1.isMatch)(file, skipMissings) ? 'skip' : 'continue';
|
|
127
76
|
}
|
|
128
|
-
if (
|
|
129
|
-
context.onExisting = (file) =>
|
|
77
|
+
if (existingActions.overwrite.length > 0 || existingActions.skip.length > 0) {
|
|
78
|
+
context.onExisting = (file) => {
|
|
79
|
+
for (const [action, files] of Object.entries(existingActions)) {
|
|
80
|
+
if ((0, micromatch_1.isMatch)(file, files)) {
|
|
81
|
+
return action;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return 'merge';
|
|
85
|
+
};
|
|
130
86
|
}
|
|
131
|
-
if (
|
|
87
|
+
if ((0, is_it_type_1.isNonEmptyRecord)(filters)) {
|
|
132
88
|
context.filters = (file) => {
|
|
133
89
|
for (const [pattern, value] of Object.entries(filters)) {
|
|
134
90
|
if ((0, micromatch_1.isMatch)(file, pattern)) {
|
|
@@ -138,7 +94,7 @@ async function configureUpdateFileActions(context) {
|
|
|
138
94
|
return undefined;
|
|
139
95
|
};
|
|
140
96
|
}
|
|
141
|
-
if (
|
|
97
|
+
if ((0, is_it_type_1.isNonEmptyRecord)(routes)) {
|
|
142
98
|
context.routes = (file) => {
|
|
143
99
|
for (const [pattern, route] of Object.entries(routes)) {
|
|
144
100
|
if ((0, micromatch_1.isMatch)(file, pattern)) {
|
|
@@ -148,5 +104,16 @@ async function configureUpdateFileActions(context) {
|
|
|
148
104
|
return undefined;
|
|
149
105
|
};
|
|
150
106
|
}
|
|
107
|
+
if ((0, is_it_type_1.isNonEmptyRecord)(transformations)) {
|
|
108
|
+
context.transforms = (file) => {
|
|
109
|
+
for (const [pattern, transforms] of Object.entries(transformations)) {
|
|
110
|
+
if ((0, micromatch_1.isMatch)(file, pattern)) {
|
|
111
|
+
return transforms;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return undefined;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
151
117
|
}
|
|
118
|
+
return xtry_1.OK;
|
|
152
119
|
}
|