@zokugun/artifact 0.6.0 → 0.6.2
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/lib/configs/install/read-install-config.js +10 -12
- package/lib/configs/install/write-install-config.d.ts +1 -1
- package/lib/configs/install/write-install-config.js +7 -3
- package/lib/configs/package/read-package-config.js +53 -58
- package/lib/configs/utils/merge-upsert-property.d.ts +2 -2
- package/lib/configs/utils/merge-upsert-property.js +28 -18
- package/lib/configs/utils/normalize-file-always.d.ts +2 -2
- package/lib/configs/utils/normalize-file-always.js +2 -1
- package/lib/configs/utils/normalize-file-uninstall.d.ts +2 -2
- package/lib/configs/utils/normalize-file-uninstall.js +2 -1
- package/lib/configs/utils/normalize-file-upsert.d.ts +2 -2
- package/lib/configs/utils/normalize-file-upsert.js +2 -1
- package/lib/journeys/commitlint/index.js +4 -4
- package/lib/journeys/fixpack/index.js +4 -4
- package/lib/steps/apply-formatting.d.ts +1 -1
- package/lib/steps/apply-formatting.js +35 -14
- package/lib/steps/configure-install-file-actions.js +23 -13
- package/lib/steps/configure-uninstall-file-actions.js +11 -7
- package/lib/steps/configure-update-file-actions.js +18 -22
- package/lib/steps/insert-final-new-line.d.ts +1 -1
- package/lib/steps/merge-text-files.js +6 -1
- package/lib/steps/read-files.js +7 -2
- package/lib/steps/replace-templates.js +0 -2
- package/lib/steps/transform-untouched-files.js +4 -13
- package/lib/steps/unmerge-text-files.js +1 -0
- package/lib/types/config.d.ts +18 -18
- package/lib/types/context.d.ts +8 -2
- package/lib/types/context.js +4 -0
- package/lib/types/format.d.ts +4 -0
- package/lib/utils/detect-indent.d.ts +2 -5
- package/lib/utils/detect-indent.js +3 -0
- package/lib/utils/template.d.ts +2 -1
- package/lib/utils/template.js +18 -6
- package/package.json +124 -123
- package/lib/types/text-file.d.ts +0 -7
- package/lib/types/text-file.js +0 -2
|
@@ -9,6 +9,8 @@ const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
|
|
|
9
9
|
const is_it_type_1 = require("@zokugun/is-it-type");
|
|
10
10
|
const xtry_1 = require("@zokugun/xtry");
|
|
11
11
|
const yaml_1 = __importDefault(require("yaml"));
|
|
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");
|
|
12
14
|
const constants_js_1 = require("../utils/constants.js");
|
|
13
15
|
const normalize_file_upsert_js_1 = require("../utils/normalize-file-upsert.js");
|
|
14
16
|
async function readInstallConfig(targetPath) {
|
|
@@ -29,12 +31,14 @@ async function readInstallConfig(targetPath) {
|
|
|
29
31
|
finalNewLine: true,
|
|
30
32
|
});
|
|
31
33
|
}
|
|
32
|
-
const finalNewLine =
|
|
34
|
+
const finalNewLine = (0, has_final_new_line_js_1.hasFinalNewLine)(content);
|
|
35
|
+
const indent = (0, detect_indent_js_1.detectIndent)(content);
|
|
33
36
|
if (type === 'json') {
|
|
34
37
|
return normalizeConfig(JSON.parse(content), {
|
|
35
38
|
name,
|
|
36
39
|
type: 'json',
|
|
37
40
|
finalNewLine,
|
|
41
|
+
indent,
|
|
38
42
|
});
|
|
39
43
|
}
|
|
40
44
|
else if (type === 'yaml') {
|
|
@@ -42,6 +46,7 @@ async function readInstallConfig(targetPath) {
|
|
|
42
46
|
name,
|
|
43
47
|
type: 'yaml',
|
|
44
48
|
finalNewLine,
|
|
49
|
+
indent,
|
|
45
50
|
});
|
|
46
51
|
}
|
|
47
52
|
else {
|
|
@@ -50,6 +55,7 @@ async function readInstallConfig(targetPath) {
|
|
|
50
55
|
name,
|
|
51
56
|
type: 'json',
|
|
52
57
|
finalNewLine,
|
|
58
|
+
indent,
|
|
53
59
|
});
|
|
54
60
|
}
|
|
55
61
|
catch {
|
|
@@ -57,13 +63,13 @@ async function readInstallConfig(targetPath) {
|
|
|
57
63
|
name,
|
|
58
64
|
type: 'yaml',
|
|
59
65
|
finalNewLine,
|
|
66
|
+
indent,
|
|
60
67
|
});
|
|
61
68
|
}
|
|
62
69
|
}
|
|
63
70
|
}
|
|
64
71
|
function normalizeConfig(data, configStats) {
|
|
65
72
|
const artifacts = {};
|
|
66
|
-
let constants = {};
|
|
67
73
|
const install = {};
|
|
68
74
|
let update = {};
|
|
69
75
|
let variables = {};
|
|
@@ -71,7 +77,6 @@ function normalizeConfig(data, configStats) {
|
|
|
71
77
|
return (0, xtry_1.ok)({
|
|
72
78
|
config: {
|
|
73
79
|
artifacts,
|
|
74
|
-
constants,
|
|
75
80
|
install,
|
|
76
81
|
update,
|
|
77
82
|
variables,
|
|
@@ -121,31 +126,24 @@ function normalizeConfig(data, configStats) {
|
|
|
121
126
|
}
|
|
122
127
|
}
|
|
123
128
|
}
|
|
124
|
-
if ((0, is_it_type_1.isRecord)(data.constants, (_key, value) => (0, is_it_type_1.isString)(value))) {
|
|
125
|
-
constants = data.constants;
|
|
126
|
-
}
|
|
127
129
|
if (data.update === false) {
|
|
128
130
|
update = false;
|
|
129
131
|
}
|
|
130
132
|
else if ((0, is_it_type_1.isRecord)(data.update)) {
|
|
131
133
|
for (const [key, value] of Object.entries(data.update)) {
|
|
132
|
-
const normalized = (0, normalize_file_upsert_js_1.normalizeFileUpsert)(value, 'update');
|
|
134
|
+
const normalized = (0, normalize_file_upsert_js_1.normalizeFileUpsert)(key, value, 'update');
|
|
133
135
|
if (normalized.fails) {
|
|
134
136
|
return normalized;
|
|
135
137
|
}
|
|
136
|
-
if (update[key]) {
|
|
137
|
-
return (0, xtry_1.err)(`Conflict with the "${key}" key on "update"1.`);
|
|
138
|
-
}
|
|
139
138
|
update[key] = normalized.value;
|
|
140
139
|
}
|
|
141
140
|
}
|
|
142
|
-
if ((0, is_it_type_1.isRecord)(data.variables, (_key, value) => (0, is_it_type_1.
|
|
141
|
+
if ((0, is_it_type_1.isRecord)(data.variables, (_key, value) => (0, is_it_type_1.isPrimitive)(value))) {
|
|
143
142
|
variables = data.variables;
|
|
144
143
|
}
|
|
145
144
|
return (0, xtry_1.ok)({
|
|
146
145
|
config: {
|
|
147
146
|
artifacts,
|
|
148
|
-
constants,
|
|
149
147
|
install,
|
|
150
148
|
update,
|
|
151
149
|
variables,
|
|
@@ -2,4 +2,4 @@ import { type AsyncDResult } from '@zokugun/xtry';
|
|
|
2
2
|
import { type InstallConfig, type InstallConfigStats } from '../../types/config.js';
|
|
3
3
|
import { type Options } from '../../types/context.js';
|
|
4
4
|
import { type Format } from '../../types/format.js';
|
|
5
|
-
export declare function writeInstallConfig(config: InstallConfig, { name, finalNewLine, type }: InstallConfigStats, formats: Format[], targetPath: string, options: Options): AsyncDResult;
|
|
5
|
+
export declare function writeInstallConfig(config: InstallConfig, { name, finalNewLine, indent, type }: InstallConfigStats, formats: Format[], targetPath: string, options: Options): AsyncDResult;
|
|
@@ -7,23 +7,27 @@ exports.writeInstallConfig = writeInstallConfig;
|
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const cli_utils_1 = require("@zokugun/cli-utils");
|
|
9
9
|
const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
|
|
10
|
+
const is_it_type_1 = require("@zokugun/is-it-type");
|
|
10
11
|
const xtry_1 = require("@zokugun/xtry");
|
|
11
|
-
const lodash_es_1 = require("lodash-es");
|
|
12
12
|
const yaml_1 = __importDefault(require("yaml"));
|
|
13
13
|
const apply_formatting_js_1 = require("../../steps/apply-formatting.js");
|
|
14
14
|
const insert_final_new_line_js_1 = require("../../steps/insert-final-new-line.js");
|
|
15
15
|
const constants_js_1 = require("../utils/constants.js");
|
|
16
|
-
async function writeInstallConfig(config, { name, finalNewLine, type }, formats, targetPath, options) {
|
|
16
|
+
async function writeInstallConfig(config, { name, finalNewLine, indent, type }, formats, targetPath, options) {
|
|
17
17
|
const exported = {
|
|
18
18
|
$schema: `https://raw.githubusercontent.com/zokugun/artifact/v${constants_js_1.VERSION_RELEASE}/schemas/v${constants_js_1.MAX_VERSION}/install.json`,
|
|
19
19
|
artifacts: config.artifacts,
|
|
20
20
|
};
|
|
21
|
-
if (
|
|
21
|
+
if ((0, is_it_type_1.isNonEmptyRecord)(config.update)) {
|
|
22
22
|
exported.update = config.update;
|
|
23
23
|
}
|
|
24
|
+
if ((0, is_it_type_1.isNonEmptyRecord)(config.variables)) {
|
|
25
|
+
exported.variables = config.variables;
|
|
26
|
+
}
|
|
24
27
|
const file = {
|
|
25
28
|
name,
|
|
26
29
|
data: type === 'yaml' ? yaml_1.default.stringify(exported) : JSON.stringify(exported, null, '\t'),
|
|
30
|
+
indent,
|
|
27
31
|
finalNewLine,
|
|
28
32
|
};
|
|
29
33
|
await (0, insert_final_new_line_js_1.insertFinalNewLine)({ mergedTextFiles: [file] });
|
|
@@ -44,17 +44,15 @@ async function readPackageConfig(targetPath) {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
function normalizeConfig(data, source) {
|
|
47
|
-
let constants = {};
|
|
48
47
|
let xtends;
|
|
49
|
-
const install =
|
|
48
|
+
const install = [];
|
|
50
49
|
let orphan = false;
|
|
51
|
-
const uninstall =
|
|
52
|
-
let update =
|
|
50
|
+
const uninstall = [];
|
|
51
|
+
let update = [];
|
|
53
52
|
let variables = {};
|
|
54
53
|
let variants = {};
|
|
55
54
|
if (!data) {
|
|
56
55
|
return (0, xtry_1.ok)({
|
|
57
|
-
constants,
|
|
58
56
|
extends: xtends,
|
|
59
57
|
install,
|
|
60
58
|
orphan,
|
|
@@ -77,9 +75,6 @@ function normalizeConfig(data, source) {
|
|
|
77
75
|
return (0, xtry_1.err)(`Don't support newer version (v${version}) in the package's "${source}".`);
|
|
78
76
|
}
|
|
79
77
|
}
|
|
80
|
-
if ((0, is_it_type_1.isRecord)(data.constants, (_key, value) => (0, is_it_type_1.isString)(value))) {
|
|
81
|
-
constants = data.constants;
|
|
82
|
-
}
|
|
83
78
|
if ((0, is_it_type_1.isString)(data.extends)) {
|
|
84
79
|
xtends = data.extends;
|
|
85
80
|
}
|
|
@@ -89,91 +84,91 @@ function normalizeConfig(data, source) {
|
|
|
89
84
|
if (data.orphan === true) {
|
|
90
85
|
orphan = true;
|
|
91
86
|
}
|
|
92
|
-
if ((0, is_it_type_1.isRecord)(data.variables, (_key, value) => (0, is_it_type_1.
|
|
87
|
+
if ((0, is_it_type_1.isRecord)(data.variables, (_key, value) => (0, is_it_type_1.isPrimitive)(value))) {
|
|
93
88
|
variables = data.variables;
|
|
94
89
|
}
|
|
95
90
|
if ((0, is_it_type_1.isRecord)(data.variants, (_key, value) => (0, is_it_type_1.isString)(value) || (0, is_it_type_1.isNumber)(value))) {
|
|
96
91
|
variants = Object.fromEntries(Object.entries(data.variants).map(([key, value]) => [key, (0, is_it_type_1.isNumber)(value) ? String(value) : value]));
|
|
97
92
|
}
|
|
98
|
-
if ((0, is_it_type_1.isRecord)(data.
|
|
99
|
-
for (const [key, value] of Object.entries(data.
|
|
100
|
-
const normalized = (0,
|
|
93
|
+
if ((0, is_it_type_1.isRecord)(data.install)) {
|
|
94
|
+
for (const [key, value] of Object.entries(data.install)) {
|
|
95
|
+
const normalized = (0, normalize_file_upsert_js_1.normalizeFileUpsert)(key, value, 'install');
|
|
101
96
|
if (normalized.fails) {
|
|
102
97
|
return normalized;
|
|
103
98
|
}
|
|
104
|
-
|
|
105
|
-
install[key] = {
|
|
106
|
-
...normalized.value,
|
|
107
|
-
ifMissing: 'merge',
|
|
108
|
-
};
|
|
109
|
-
uninstall[key] = {
|
|
110
|
-
ifExists: ifExists === 'force-merge' || ifExists === 'merge' || ifExists === 'overwrite' ? 'skip' : ifExists,
|
|
111
|
-
transforms,
|
|
112
|
-
};
|
|
113
|
-
update[key] = {
|
|
114
|
-
...normalized.value,
|
|
115
|
-
ifMissing: 'merge',
|
|
116
|
-
};
|
|
99
|
+
install.push(normalized.value);
|
|
117
100
|
}
|
|
118
101
|
}
|
|
119
|
-
if (
|
|
120
|
-
|
|
121
|
-
|
|
102
|
+
if (data.update === false) {
|
|
103
|
+
update = false;
|
|
104
|
+
}
|
|
105
|
+
else if ((0, is_it_type_1.isRecord)(data.update)) {
|
|
106
|
+
for (const [key, value] of Object.entries(data.update)) {
|
|
107
|
+
const normalized = (0, normalize_file_upsert_js_1.normalizeFileUpsert)(key, value, 'update');
|
|
122
108
|
if (normalized.fails) {
|
|
123
109
|
return normalized;
|
|
124
110
|
}
|
|
125
|
-
|
|
126
|
-
update[key] = {
|
|
127
|
-
...normalized.value,
|
|
128
|
-
};
|
|
111
|
+
update.push(normalized.value);
|
|
129
112
|
}
|
|
130
113
|
}
|
|
131
|
-
if ((0, is_it_type_1.isRecord)(data.
|
|
132
|
-
for (const [key, value] of Object.entries(data.
|
|
133
|
-
const normalized = (0,
|
|
114
|
+
if ((0, is_it_type_1.isRecord)(data.uninstall)) {
|
|
115
|
+
for (const [key, value] of Object.entries(data.uninstall)) {
|
|
116
|
+
const normalized = (0, normalize_file_uninstall_js_1.normalizeFileUninstall)(key, value);
|
|
134
117
|
if (normalized.fails) {
|
|
135
118
|
return normalized;
|
|
136
119
|
}
|
|
137
|
-
|
|
138
|
-
const result = (0, merge_upsert_property_js_1.mergeUpsertProperty)(key, update[key], normalized.value);
|
|
139
|
-
if (result.fails) {
|
|
140
|
-
return result;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
install[key] = normalized.value;
|
|
120
|
+
uninstall.push(normalized.value);
|
|
144
121
|
}
|
|
145
122
|
}
|
|
146
|
-
if ((0, is_it_type_1.isRecord)(data.
|
|
147
|
-
for (const [key, value] of Object.entries(data.
|
|
148
|
-
const normalized = (0,
|
|
123
|
+
if ((0, is_it_type_1.isRecord)(data.upsert)) {
|
|
124
|
+
for (const [key, value] of Object.entries(data.upsert)) {
|
|
125
|
+
const normalized = (0, normalize_file_upsert_js_1.normalizeFileUpsert)(key, value, 'upsert');
|
|
149
126
|
if (normalized.fails) {
|
|
150
127
|
return normalized;
|
|
151
128
|
}
|
|
152
|
-
|
|
129
|
+
const result = (0, merge_upsert_property_js_1.mergeUpsertProperty)(normalized.value, install);
|
|
130
|
+
if (result.fails) {
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
if (update) {
|
|
134
|
+
const result = (0, merge_upsert_property_js_1.mergeUpsertProperty)(normalized.value, update);
|
|
135
|
+
if (result.fails) {
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
153
139
|
}
|
|
154
140
|
}
|
|
155
|
-
if (data.
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
else if ((0, is_it_type_1.isRecord)(data.update)) {
|
|
159
|
-
for (const [key, value] of Object.entries(data.update)) {
|
|
160
|
-
const normalized = (0, normalize_file_upsert_js_1.normalizeFileUpsert)(value, 'update');
|
|
141
|
+
if ((0, is_it_type_1.isRecord)(data.always)) {
|
|
142
|
+
for (const [key, value] of Object.entries(data.always)) {
|
|
143
|
+
const normalized = (0, normalize_file_always_js_1.normalizeFileAlways)(key, value);
|
|
161
144
|
if (normalized.fails) {
|
|
162
145
|
return normalized;
|
|
163
146
|
}
|
|
164
|
-
|
|
165
|
-
|
|
147
|
+
const { ifExists, pattern, transforms } = normalized.value;
|
|
148
|
+
const result = (0, merge_upsert_property_js_1.mergeUpsertProperty)({
|
|
149
|
+
...normalized.value,
|
|
150
|
+
ifMissing: 'merge',
|
|
151
|
+
}, install);
|
|
152
|
+
if (result.fails) {
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
if (update) {
|
|
156
|
+
const result = (0, merge_upsert_property_js_1.mergeUpsertProperty)({
|
|
157
|
+
...normalized.value,
|
|
158
|
+
ifMissing: 'merge',
|
|
159
|
+
}, update);
|
|
166
160
|
if (result.fails) {
|
|
167
161
|
return result;
|
|
168
162
|
}
|
|
169
163
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
164
|
+
uninstall.push({
|
|
165
|
+
ifExists: ifExists === 'force-merge' || ifExists === 'merge' || ifExists === 'overwrite' ? 'skip' : ifExists,
|
|
166
|
+
pattern,
|
|
167
|
+
transforms,
|
|
168
|
+
});
|
|
173
169
|
}
|
|
174
170
|
}
|
|
175
171
|
return (0, xtry_1.ok)({
|
|
176
|
-
constants,
|
|
177
172
|
extends: xtends,
|
|
178
173
|
install,
|
|
179
174
|
orphan,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type DResult } from '@zokugun/xtry';
|
|
2
|
-
import { type
|
|
3
|
-
export declare function mergeUpsertProperty(
|
|
2
|
+
import { type UpsertFileConfig } from '../../types/config.js';
|
|
3
|
+
export declare function mergeUpsertProperty(file: UpsertFileConfig, configs: UpsertFileConfig[]): DResult;
|
|
@@ -1,20 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mergeUpsertProperty = mergeUpsertProperty;
|
|
4
|
+
const is_it_type_1 = require("@zokugun/is-it-type");
|
|
4
5
|
const xtry_1 = require("@zokugun/xtry");
|
|
5
6
|
const lodash_es_1 = require("lodash-es");
|
|
6
|
-
function mergeUpsertProperty(
|
|
7
|
+
function mergeUpsertProperty(file, configs) {
|
|
8
|
+
for (const config of configs) {
|
|
9
|
+
if (config.pattern === file.pattern) {
|
|
10
|
+
return merge(config, file);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
configs.push(file);
|
|
14
|
+
return xtry_1.OK;
|
|
15
|
+
}
|
|
16
|
+
function merge(currentValue, newValue) {
|
|
7
17
|
if (newValue.filter) {
|
|
8
|
-
if (
|
|
18
|
+
if (currentValue.filter) {
|
|
9
19
|
return (0, xtry_1.err)('Not Implemented: filter');
|
|
10
20
|
}
|
|
11
21
|
else {
|
|
12
|
-
|
|
22
|
+
currentValue.filter = newValue.filter;
|
|
13
23
|
}
|
|
14
24
|
}
|
|
15
25
|
if (newValue.ifExists && newValue.ifExists !== 'merge') {
|
|
16
|
-
if (
|
|
17
|
-
if (
|
|
26
|
+
if (currentValue.ifExists) {
|
|
27
|
+
if (currentValue.ifExists === 'merge' || currentValue.ifExists === newValue.ifExists) {
|
|
18
28
|
// pass
|
|
19
29
|
}
|
|
20
30
|
else {
|
|
@@ -22,12 +32,12 @@ function mergeUpsertProperty(key, oldValue, newValue) {
|
|
|
22
32
|
}
|
|
23
33
|
}
|
|
24
34
|
else {
|
|
25
|
-
|
|
35
|
+
currentValue.ifExists = newValue.ifExists;
|
|
26
36
|
}
|
|
27
37
|
}
|
|
28
38
|
if (newValue.ifMissing && newValue.ifMissing !== 'merge') {
|
|
29
|
-
if (
|
|
30
|
-
if (
|
|
39
|
+
if (currentValue.ifMissing) {
|
|
40
|
+
if (currentValue.ifMissing === 'merge' || currentValue.ifMissing === newValue.ifMissing) {
|
|
31
41
|
// pass
|
|
32
42
|
}
|
|
33
43
|
else {
|
|
@@ -35,33 +45,33 @@ function mergeUpsertProperty(key, oldValue, newValue) {
|
|
|
35
45
|
}
|
|
36
46
|
}
|
|
37
47
|
else {
|
|
38
|
-
|
|
48
|
+
currentValue.ifMissing = newValue.ifMissing;
|
|
39
49
|
}
|
|
40
50
|
}
|
|
41
51
|
if (newValue.rename) {
|
|
42
|
-
if (
|
|
52
|
+
if (currentValue.rename) {
|
|
43
53
|
return (0, xtry_1.err)('Not Implemented: rename');
|
|
44
54
|
}
|
|
45
55
|
else {
|
|
46
|
-
|
|
56
|
+
currentValue.rename = newValue.rename;
|
|
47
57
|
}
|
|
48
58
|
}
|
|
49
59
|
if (newValue.route) {
|
|
50
|
-
if (
|
|
60
|
+
if (currentValue.route) {
|
|
51
61
|
return (0, xtry_1.err)('Not Implemented: route');
|
|
52
62
|
}
|
|
53
63
|
else {
|
|
54
|
-
|
|
64
|
+
currentValue.route = newValue.route;
|
|
55
65
|
}
|
|
56
66
|
}
|
|
57
|
-
if (
|
|
58
|
-
if (
|
|
59
|
-
if (!(0, lodash_es_1.isEqual)(
|
|
60
|
-
return (0, xtry_1.err)(`There is a conflict on the "transforms" property for the "${
|
|
67
|
+
if ((0, is_it_type_1.isNonEmptyArray)(newValue.transforms)) {
|
|
68
|
+
if ((0, is_it_type_1.isNonEmptyArray)(currentValue.transforms)) {
|
|
69
|
+
if (!(0, lodash_es_1.isEqual)(currentValue.transforms, newValue.transforms)) {
|
|
70
|
+
return (0, xtry_1.err)(`There is a conflict on the "transforms" property for the "${newValue.pattern}" file`);
|
|
61
71
|
}
|
|
62
72
|
}
|
|
63
73
|
else {
|
|
64
|
-
|
|
74
|
+
currentValue.transforms = newValue.transforms;
|
|
65
75
|
}
|
|
66
76
|
}
|
|
67
77
|
return xtry_1.OK;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type DResult } from '@zokugun/xtry';
|
|
2
|
-
import { type
|
|
3
|
-
export declare function normalizeFileAlways(data: unknown): DResult<
|
|
2
|
+
import { type AlwaysFileConfig } from '../../types/config.js';
|
|
3
|
+
export declare function normalizeFileAlways(pattern: string, data: unknown): DResult<AlwaysFileConfig>;
|
|
@@ -4,7 +4,7 @@ exports.normalizeFileAlways = normalizeFileAlways;
|
|
|
4
4
|
const is_it_type_1 = require("@zokugun/is-it-type");
|
|
5
5
|
const xtry_1 = require("@zokugun/xtry");
|
|
6
6
|
const is_transform_js_1 = require("./is-transform.js");
|
|
7
|
-
function normalizeFileAlways(data) {
|
|
7
|
+
function normalizeFileAlways(pattern, data) {
|
|
8
8
|
if (!(0, is_it_type_1.isRecord)(data)) {
|
|
9
9
|
return (0, xtry_1.err)('"always" must be an object.');
|
|
10
10
|
}
|
|
@@ -23,6 +23,7 @@ function normalizeFileAlways(data) {
|
|
|
23
23
|
}
|
|
24
24
|
return (0, xtry_1.ok)({
|
|
25
25
|
ifExists,
|
|
26
|
+
pattern,
|
|
26
27
|
transforms,
|
|
27
28
|
});
|
|
28
29
|
} // }}}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type DResult } from '@zokugun/xtry';
|
|
2
|
-
import { type
|
|
3
|
-
export declare function normalizeFileUninstall(data: unknown): DResult<
|
|
2
|
+
import { type UninstallFileConfig } from '../../types/config.js';
|
|
3
|
+
export declare function normalizeFileUninstall(pattern: string, data: unknown): DResult<UninstallFileConfig>;
|
|
@@ -4,7 +4,7 @@ exports.normalizeFileUninstall = normalizeFileUninstall;
|
|
|
4
4
|
const is_it_type_1 = require("@zokugun/is-it-type");
|
|
5
5
|
const xtry_1 = require("@zokugun/xtry");
|
|
6
6
|
const is_transform_js_1 = require("./is-transform.js");
|
|
7
|
-
function normalizeFileUninstall(data) {
|
|
7
|
+
function normalizeFileUninstall(pattern, data) {
|
|
8
8
|
if (!(0, is_it_type_1.isRecord)(data)) {
|
|
9
9
|
return (0, xtry_1.err)('"uninstall" must be an object.');
|
|
10
10
|
}
|
|
@@ -26,6 +26,7 @@ function normalizeFileUninstall(data) {
|
|
|
26
26
|
}
|
|
27
27
|
return (0, xtry_1.ok)({
|
|
28
28
|
ifExists,
|
|
29
|
+
pattern,
|
|
29
30
|
transforms,
|
|
30
31
|
});
|
|
31
32
|
} // }}}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type DResult } from '@zokugun/xtry';
|
|
2
|
-
import { type
|
|
3
|
-
export declare function normalizeFileUpsert(data: unknown, name: 'install' | 'update' | 'upsert'): DResult<
|
|
2
|
+
import { type UpsertFileConfig } from '../../types/config.js';
|
|
3
|
+
export declare function normalizeFileUpsert(pattern: string, data: unknown, name: 'install' | 'update' | 'upsert'): DResult<UpsertFileConfig>;
|
|
@@ -4,7 +4,7 @@ exports.normalizeFileUpsert = normalizeFileUpsert;
|
|
|
4
4
|
const is_it_type_1 = require("@zokugun/is-it-type");
|
|
5
5
|
const xtry_1 = require("@zokugun/xtry");
|
|
6
6
|
const is_transform_js_1 = require("./is-transform.js");
|
|
7
|
-
function normalizeFileUpsert(data, name) {
|
|
7
|
+
function normalizeFileUpsert(pattern, data, name) {
|
|
8
8
|
if (!(0, is_it_type_1.isRecord)(data)) {
|
|
9
9
|
return (0, xtry_1.err)(`"${name}" must be an object.`);
|
|
10
10
|
}
|
|
@@ -47,6 +47,7 @@ function normalizeFileUpsert(data, name) {
|
|
|
47
47
|
filter,
|
|
48
48
|
ifExists,
|
|
49
49
|
ifMissing,
|
|
50
|
+
pattern,
|
|
50
51
|
rename,
|
|
51
52
|
route,
|
|
52
53
|
transforms,
|
|
@@ -4,14 +4,14 @@ const index_js_1 = require("../../compositors/index.js");
|
|
|
4
4
|
const index_js_2 = require("../../routes/index.js");
|
|
5
5
|
const build_journey_plan_js_1 = require("../../utils/build-journey-plan.js");
|
|
6
6
|
const build_travel_plan_js_1 = require("../../utils/build-travel-plan.js");
|
|
7
|
-
const mainRoute = (0, index_js_1.compose)({
|
|
7
|
+
const mainRoute = (0, index_js_1.mapSort)((0, index_js_1.compose)({
|
|
8
8
|
extends: index_js_2.listConcat,
|
|
9
9
|
parserPreset: index_js_2.primitive,
|
|
10
|
-
rules: (0, index_js_1.compose)({
|
|
10
|
+
rules: (0, index_js_1.mapSort)((0, index_js_1.compose)({
|
|
11
11
|
$$default: index_js_2.overwrite,
|
|
12
|
-
}),
|
|
12
|
+
})),
|
|
13
13
|
$$default: index_js_2.primitive,
|
|
14
|
-
});
|
|
14
|
+
}));
|
|
15
15
|
const jsonRoute = (0, index_js_1.json)(mainRoute);
|
|
16
16
|
const yamlRoute = (0, index_js_1.yaml)(mainRoute);
|
|
17
17
|
const rcRoute = (0, index_js_1.rc)(mainRoute);
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const is_it_type_1 = require("@zokugun/is-it-type");
|
|
4
4
|
const index_js_1 = require("../../compositors/index.js");
|
|
5
5
|
const index_js_2 = require("../../routes/index.js");
|
|
6
6
|
const build_journey_plan_js_1 = require("../../utils/build-journey-plan.js");
|
|
7
7
|
const build_travel_plan_js_1 = require("../../utils/build-travel-plan.js");
|
|
8
|
-
const mainRoute = (0, index_js_1.compose)({
|
|
8
|
+
const mainRoute = (0, index_js_1.mapSort)((0, index_js_1.compose)({
|
|
9
9
|
sortToTop: index_js_2.listSortConcat,
|
|
10
|
-
$$default: (0, index_js_1.fork)([
|
|
11
|
-
});
|
|
10
|
+
$$default: (0, index_js_1.fork)([is_it_type_1.isArray, index_js_2.listConcat], [is_it_type_1.isRecord, index_js_2.mapConcat], index_js_2.primitive),
|
|
11
|
+
}));
|
|
12
12
|
const jsonRoute = (0, index_js_1.json)(mainRoute);
|
|
13
13
|
const yamlRoute = (0, index_js_1.yaml)(mainRoute);
|
|
14
14
|
const rcRoute = (0, index_js_1.rc)(mainRoute);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type AsyncDResult } from '@zokugun/xtry';
|
|
2
|
+
import { type TextFile } from '../types/context.js';
|
|
2
3
|
import { type Format } from '../types/format.js';
|
|
3
|
-
import { type TextFile } from '../types/text-file.js';
|
|
4
4
|
export declare function applyFormatting({ formats, mergedTextFiles, transformedFiles }: {
|
|
5
5
|
formats: Format[];
|
|
6
6
|
mergedTextFiles: TextFile[];
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.applyFormatting = applyFormatting;
|
|
7
4
|
const xtry_1 = require("@zokugun/xtry");
|
|
8
|
-
const detect_indent_1 = __importDefault(require("detect-indent"));
|
|
9
5
|
const format_js_1 = require("../types/format.js");
|
|
6
|
+
const detect_indent_js_1 = require("../utils/detect-indent.js");
|
|
10
7
|
const get_format_js_1 = require("../utils/get-format.js");
|
|
11
8
|
function applyFormat(file, format) {
|
|
12
9
|
if (format.indentStyle === format_js_1.IndentStyle.SPACE) {
|
|
@@ -23,29 +20,39 @@ function applyFormat(file, format) {
|
|
|
23
20
|
}
|
|
24
21
|
} // }}}
|
|
25
22
|
function indentWithSpace(data, size) {
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
28
|
-
|
|
23
|
+
const indent = (0, detect_indent_js_1.detectIndent)(data);
|
|
24
|
+
if (!indent) {
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
else if (indent.style === format_js_1.IndentStyle.SPACE) {
|
|
28
|
+
if (indent.size === size) {
|
|
29
29
|
return data;
|
|
30
30
|
}
|
|
31
31
|
else {
|
|
32
|
-
|
|
32
|
+
const oldIndent = ' '.repeat(indent.size);
|
|
33
33
|
const newIndent = ' '.repeat(size);
|
|
34
|
-
|
|
34
|
+
const space2tab = new RegExp(`^(?:${oldIndent})+`, 'gm');
|
|
35
|
+
data = data.replaceAll(space2tab, (spaces) => '\t'.repeat(spaces.length / indent.size));
|
|
36
|
+
return data.replaceAll(/^\t+/gm, (tabs) => newIndent.repeat(tabs.length));
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
|
-
else if (
|
|
39
|
+
else if (indent.style === format_js_1.IndentStyle.TAB) {
|
|
38
40
|
const newIndent = ' '.repeat(size);
|
|
39
|
-
return data.replaceAll(
|
|
41
|
+
return data.replaceAll(/^\t+/gm, (tabs) => newIndent.repeat(tabs.length));
|
|
40
42
|
}
|
|
41
43
|
else {
|
|
42
44
|
return data;
|
|
43
45
|
}
|
|
44
46
|
} // }}}
|
|
45
47
|
function indentWithTab(data) {
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
48
|
-
return data
|
|
48
|
+
const indent = (0, detect_indent_js_1.detectIndent)(data);
|
|
49
|
+
if (!indent) {
|
|
50
|
+
return data;
|
|
51
|
+
}
|
|
52
|
+
else if (indent.style === format_js_1.IndentStyle.SPACE) {
|
|
53
|
+
const oldIndent = ' '.repeat(indent.size);
|
|
54
|
+
const space2tab = new RegExp(`^(?:${oldIndent})+`, 'gm');
|
|
55
|
+
return data.replaceAll(space2tab, (spaces) => '\t'.repeat(spaces.length / indent.size));
|
|
49
56
|
}
|
|
50
57
|
else {
|
|
51
58
|
return data;
|
|
@@ -57,6 +64,13 @@ async function applyFormatting({ formats, mergedTextFiles, transformedFiles }) {
|
|
|
57
64
|
if (format) {
|
|
58
65
|
applyFormat(file, format);
|
|
59
66
|
}
|
|
67
|
+
else if (file.indent) {
|
|
68
|
+
applyFormat(file, {
|
|
69
|
+
indentStyle: file.indent.style,
|
|
70
|
+
indentSize: file.indent.size,
|
|
71
|
+
insertFinalNewline: file.finalNewLine,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
60
74
|
}
|
|
61
75
|
if (transformedFiles) {
|
|
62
76
|
for (const file of transformedFiles) {
|
|
@@ -64,6 +78,13 @@ async function applyFormatting({ formats, mergedTextFiles, transformedFiles }) {
|
|
|
64
78
|
if (format) {
|
|
65
79
|
applyFormat(file, format);
|
|
66
80
|
}
|
|
81
|
+
else if (file.indent) {
|
|
82
|
+
applyFormat(file, {
|
|
83
|
+
indentStyle: file.indent.style,
|
|
84
|
+
indentSize: file.indent.size,
|
|
85
|
+
insertFinalNewline: file.finalNewLine,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
67
88
|
}
|
|
68
89
|
}
|
|
69
90
|
return xtry_1.OK;
|