@zokugun/artifact 0.6.0 → 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/lib/configs/install/read-install-config.js +9 -5
- package/lib/configs/install/write-install-config.d.ts +1 -1
- package/lib/configs/install/write-install-config.js +10 -3
- package/lib/configs/package/read-package-config.js +52 -51
- 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/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/transform-untouched-files.js +4 -13
- package/lib/steps/unmerge-text-files.js +1 -0
- package/lib/types/config.d.ts +15 -14
- 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/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,6 +63,7 @@ async function readInstallConfig(targetPath) {
|
|
|
57
63
|
name,
|
|
58
64
|
type: 'yaml',
|
|
59
65
|
finalNewLine,
|
|
66
|
+
indent,
|
|
60
67
|
});
|
|
61
68
|
}
|
|
62
69
|
}
|
|
@@ -129,13 +136,10 @@ function normalizeConfig(data, configStats) {
|
|
|
129
136
|
}
|
|
130
137
|
else if ((0, is_it_type_1.isRecord)(data.update)) {
|
|
131
138
|
for (const [key, value] of Object.entries(data.update)) {
|
|
132
|
-
const normalized = (0, normalize_file_upsert_js_1.normalizeFileUpsert)(value, 'update');
|
|
139
|
+
const normalized = (0, normalize_file_upsert_js_1.normalizeFileUpsert)(key, value, 'update');
|
|
133
140
|
if (normalized.fails) {
|
|
134
141
|
return normalized;
|
|
135
142
|
}
|
|
136
|
-
if (update[key]) {
|
|
137
|
-
return (0, xtry_1.err)(`Conflict with the "${key}" key on "update"1.`);
|
|
138
|
-
}
|
|
139
143
|
update[key] = normalized.value;
|
|
140
144
|
}
|
|
141
145
|
}
|
|
@@ -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,30 @@ 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.constants)) {
|
|
25
|
+
exported.constants = config.constants;
|
|
26
|
+
}
|
|
27
|
+
if ((0, is_it_type_1.isNonEmptyRecord)(config.variables)) {
|
|
28
|
+
exported.variables = config.variables;
|
|
29
|
+
}
|
|
24
30
|
const file = {
|
|
25
31
|
name,
|
|
26
32
|
data: type === 'yaml' ? yaml_1.default.stringify(exported) : JSON.stringify(exported, null, '\t'),
|
|
33
|
+
indent,
|
|
27
34
|
finalNewLine,
|
|
28
35
|
};
|
|
29
36
|
await (0, insert_final_new_line_js_1.insertFinalNewLine)({ mergedTextFiles: [file] });
|
|
@@ -46,10 +46,10 @@ async function readPackageConfig(targetPath) {
|
|
|
46
46
|
function normalizeConfig(data, source) {
|
|
47
47
|
let constants = {};
|
|
48
48
|
let xtends;
|
|
49
|
-
const install =
|
|
49
|
+
const install = [];
|
|
50
50
|
let orphan = false;
|
|
51
|
-
const uninstall =
|
|
52
|
-
let update =
|
|
51
|
+
const uninstall = [];
|
|
52
|
+
let update = [];
|
|
53
53
|
let variables = {};
|
|
54
54
|
let variants = {};
|
|
55
55
|
if (!data) {
|
|
@@ -95,81 +95,82 @@ function normalizeConfig(data, source) {
|
|
|
95
95
|
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
96
|
variants = Object.fromEntries(Object.entries(data.variants).map(([key, value]) => [key, (0, is_it_type_1.isNumber)(value) ? String(value) : value]));
|
|
97
97
|
}
|
|
98
|
-
if ((0, is_it_type_1.isRecord)(data.
|
|
99
|
-
for (const [key, value] of Object.entries(data.
|
|
100
|
-
const normalized = (0,
|
|
98
|
+
if ((0, is_it_type_1.isRecord)(data.install)) {
|
|
99
|
+
for (const [key, value] of Object.entries(data.install)) {
|
|
100
|
+
const normalized = (0, normalize_file_upsert_js_1.normalizeFileUpsert)(key, value, 'install');
|
|
101
101
|
if (normalized.fails) {
|
|
102
102
|
return normalized;
|
|
103
103
|
}
|
|
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
|
-
};
|
|
104
|
+
install.push(normalized.value);
|
|
117
105
|
}
|
|
118
106
|
}
|
|
119
|
-
if (
|
|
120
|
-
|
|
121
|
-
|
|
107
|
+
if (data.update === false) {
|
|
108
|
+
update = false;
|
|
109
|
+
}
|
|
110
|
+
else if ((0, is_it_type_1.isRecord)(data.update)) {
|
|
111
|
+
for (const [key, value] of Object.entries(data.update)) {
|
|
112
|
+
const normalized = (0, normalize_file_upsert_js_1.normalizeFileUpsert)(key, value, 'update');
|
|
122
113
|
if (normalized.fails) {
|
|
123
114
|
return normalized;
|
|
124
115
|
}
|
|
125
|
-
|
|
126
|
-
update[key] = {
|
|
127
|
-
...normalized.value,
|
|
128
|
-
};
|
|
116
|
+
update.push(normalized.value);
|
|
129
117
|
}
|
|
130
118
|
}
|
|
131
|
-
if ((0, is_it_type_1.isRecord)(data.
|
|
132
|
-
for (const [key, value] of Object.entries(data.
|
|
133
|
-
const normalized = (0,
|
|
119
|
+
if ((0, is_it_type_1.isRecord)(data.uninstall)) {
|
|
120
|
+
for (const [key, value] of Object.entries(data.uninstall)) {
|
|
121
|
+
const normalized = (0, normalize_file_uninstall_js_1.normalizeFileUninstall)(key, value);
|
|
134
122
|
if (normalized.fails) {
|
|
135
123
|
return normalized;
|
|
136
124
|
}
|
|
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;
|
|
125
|
+
uninstall.push(normalized.value);
|
|
144
126
|
}
|
|
145
127
|
}
|
|
146
|
-
if ((0, is_it_type_1.isRecord)(data.
|
|
147
|
-
for (const [key, value] of Object.entries(data.
|
|
148
|
-
const normalized = (0,
|
|
128
|
+
if ((0, is_it_type_1.isRecord)(data.upsert)) {
|
|
129
|
+
for (const [key, value] of Object.entries(data.upsert)) {
|
|
130
|
+
const normalized = (0, normalize_file_upsert_js_1.normalizeFileUpsert)(key, value, 'upsert');
|
|
149
131
|
if (normalized.fails) {
|
|
150
132
|
return normalized;
|
|
151
133
|
}
|
|
152
|
-
|
|
134
|
+
const result = (0, merge_upsert_property_js_1.mergeUpsertProperty)(normalized.value, install);
|
|
135
|
+
if (result.fails) {
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
if (update) {
|
|
139
|
+
const result = (0, merge_upsert_property_js_1.mergeUpsertProperty)(normalized.value, update);
|
|
140
|
+
if (result.fails) {
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
153
144
|
}
|
|
154
145
|
}
|
|
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');
|
|
146
|
+
if ((0, is_it_type_1.isRecord)(data.always)) {
|
|
147
|
+
for (const [key, value] of Object.entries(data.always)) {
|
|
148
|
+
const normalized = (0, normalize_file_always_js_1.normalizeFileAlways)(key, value);
|
|
161
149
|
if (normalized.fails) {
|
|
162
150
|
return normalized;
|
|
163
151
|
}
|
|
164
|
-
|
|
165
|
-
|
|
152
|
+
const { ifExists, pattern, transforms } = normalized.value;
|
|
153
|
+
const result = (0, merge_upsert_property_js_1.mergeUpsertProperty)({
|
|
154
|
+
...normalized.value,
|
|
155
|
+
ifMissing: 'merge',
|
|
156
|
+
}, install);
|
|
157
|
+
if (result.fails) {
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
if (update) {
|
|
161
|
+
const result = (0, merge_upsert_property_js_1.mergeUpsertProperty)({
|
|
162
|
+
...normalized.value,
|
|
163
|
+
ifMissing: 'merge',
|
|
164
|
+
}, update);
|
|
166
165
|
if (result.fails) {
|
|
167
166
|
return result;
|
|
168
167
|
}
|
|
169
168
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
169
|
+
uninstall.push({
|
|
170
|
+
ifExists: ifExists === 'force-merge' || ifExists === 'merge' || ifExists === 'overwrite' ? 'skip' : ifExists,
|
|
171
|
+
pattern,
|
|
172
|
+
transforms,
|
|
173
|
+
});
|
|
173
174
|
}
|
|
174
175
|
}
|
|
175
176
|
return (0, xtry_1.ok)({
|
|
@@ -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,
|
|
@@ -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;
|
|
@@ -10,31 +10,34 @@ async function configureInstallFileActions(context) {
|
|
|
10
10
|
if (!install) {
|
|
11
11
|
return xtry_1.OK;
|
|
12
12
|
}
|
|
13
|
-
const
|
|
13
|
+
const existingActions = [];
|
|
14
14
|
const filters = {};
|
|
15
15
|
const routes = {};
|
|
16
16
|
const transformations = {};
|
|
17
|
-
for (const
|
|
18
|
-
const { filter, ifExists, rename, route, transforms } =
|
|
17
|
+
for (const file of install) {
|
|
18
|
+
const { filter, ifExists, pattern, rename, route, transforms } = file;
|
|
19
19
|
if (rename) {
|
|
20
20
|
context.renamedPatterns.push({
|
|
21
|
-
from:
|
|
21
|
+
from: pattern,
|
|
22
22
|
to: rename,
|
|
23
23
|
});
|
|
24
24
|
continue;
|
|
25
25
|
}
|
|
26
|
-
if (ifExists === '
|
|
27
|
-
|
|
26
|
+
if (ifExists === 'force-merge') {
|
|
27
|
+
existingActions.push({ pattern, action: 'merge' });
|
|
28
|
+
}
|
|
29
|
+
else if (ifExists === 'overwrite') {
|
|
30
|
+
existingActions.push({ pattern, action: 'overwrite' });
|
|
28
31
|
}
|
|
29
32
|
else if (ifExists === 'remove') {
|
|
30
|
-
context.removedPatterns.push(
|
|
33
|
+
context.removedPatterns.push(pattern);
|
|
31
34
|
continue;
|
|
32
35
|
}
|
|
33
36
|
else if (ifExists === 'skip') {
|
|
34
37
|
continue;
|
|
35
38
|
}
|
|
36
39
|
if (filter) {
|
|
37
|
-
filters[
|
|
40
|
+
filters[pattern] = filter;
|
|
38
41
|
}
|
|
39
42
|
if (route) {
|
|
40
43
|
const { alias } = route;
|
|
@@ -43,23 +46,30 @@ async function configureInstallFileActions(context) {
|
|
|
43
46
|
return travel;
|
|
44
47
|
}
|
|
45
48
|
if (alias) {
|
|
46
|
-
routes[
|
|
49
|
+
routes[pattern] = {
|
|
47
50
|
alias,
|
|
48
51
|
travel: travel.value,
|
|
49
52
|
};
|
|
50
53
|
}
|
|
51
54
|
else {
|
|
52
|
-
routes[
|
|
55
|
+
routes[pattern] = {
|
|
53
56
|
travel: travel.value,
|
|
54
57
|
};
|
|
55
58
|
}
|
|
56
59
|
}
|
|
57
60
|
if (transforms) {
|
|
58
|
-
transformations[
|
|
61
|
+
transformations[pattern] = transforms;
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
|
-
if (
|
|
62
|
-
context.onExisting = (file) =>
|
|
64
|
+
if (existingActions.length > 0) {
|
|
65
|
+
context.onExisting = (file) => {
|
|
66
|
+
for (const { pattern, action } of existingActions) {
|
|
67
|
+
if ((0, micromatch_1.isMatch)(file, pattern)) {
|
|
68
|
+
return action;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return 'merge';
|
|
72
|
+
};
|
|
63
73
|
}
|
|
64
74
|
if ((0, is_it_type_1.isNonEmptyRecord)(filters)) {
|
|
65
75
|
context.filters = (file) => {
|
|
@@ -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 micromatch_1 = require("micromatch");
|
|
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
|
async function configureUninstallFileActions(context) {
|
|
13
15
|
const { uninstall } = context.incomingConfig;
|
|
14
16
|
if (!uninstall) {
|
|
@@ -16,27 +18,29 @@ async function configureUninstallFileActions(context) {
|
|
|
16
18
|
}
|
|
17
19
|
const cwd = node_path_1.default.join(context.incomingPath, 'configs');
|
|
18
20
|
const transformations = {};
|
|
19
|
-
for (const
|
|
20
|
-
const { ifExists, transforms } =
|
|
21
|
+
for (const file of uninstall) {
|
|
22
|
+
const { ifExists, pattern, transforms } = file;
|
|
21
23
|
if (ifExists === 'remove') {
|
|
22
|
-
context.removedPatterns.push(
|
|
24
|
+
context.removedPatterns.push(pattern);
|
|
23
25
|
}
|
|
24
26
|
else if (ifExists === 'unmerge') {
|
|
25
|
-
const filePath = node_path_1.default.join(cwd,
|
|
27
|
+
const filePath = node_path_1.default.join(cwd, pattern);
|
|
26
28
|
const result = await async_1.default.readFile(filePath, 'utf8');
|
|
27
29
|
if (result.fails) {
|
|
28
30
|
return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
|
|
29
31
|
}
|
|
30
32
|
const data = result.value;
|
|
31
|
-
const finalNewLine =
|
|
33
|
+
const finalNewLine = (0, has_final_new_line_js_1.hasFinalNewLine)(data);
|
|
34
|
+
const indent = (0, detect_indent_js_1.detectIndent)(data);
|
|
32
35
|
context.textFiles.push({
|
|
33
|
-
name:
|
|
36
|
+
name: pattern,
|
|
34
37
|
data,
|
|
35
38
|
finalNewLine,
|
|
39
|
+
indent,
|
|
36
40
|
});
|
|
37
41
|
}
|
|
38
42
|
if (transforms) {
|
|
39
|
-
transformations[
|
|
43
|
+
transformations[pattern] = transforms;
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
46
|
if ((0, is_it_type_1.isNonEmptyRecord)(transformations)) {
|
|
@@ -12,42 +12,38 @@ async function configureUpdateFileActions(context) {
|
|
|
12
12
|
context.onMissing = () => 'skip';
|
|
13
13
|
}
|
|
14
14
|
else {
|
|
15
|
-
const existingActions =
|
|
16
|
-
merge: [],
|
|
17
|
-
overwrite: [],
|
|
18
|
-
skip: [],
|
|
19
|
-
};
|
|
15
|
+
const existingActions = [];
|
|
20
16
|
const skipMissings = [];
|
|
21
17
|
const filters = {};
|
|
22
18
|
const routes = {};
|
|
23
19
|
const transformations = {};
|
|
24
|
-
for (const
|
|
25
|
-
const { filter, ifExists, ifMissing, rename, route, transforms } =
|
|
20
|
+
for (const file of update) {
|
|
21
|
+
const { filter, ifExists, ifMissing, pattern, rename, route, transforms } = file;
|
|
26
22
|
if (rename) {
|
|
27
23
|
context.renamedPatterns.push({
|
|
28
|
-
from:
|
|
24
|
+
from: pattern,
|
|
29
25
|
to: rename,
|
|
30
26
|
});
|
|
31
27
|
continue;
|
|
32
28
|
}
|
|
33
29
|
if (ifMissing === 'skip') {
|
|
34
|
-
skipMissings.push(
|
|
30
|
+
skipMissings.push(pattern);
|
|
35
31
|
}
|
|
36
32
|
if (ifExists === 'force-merge') {
|
|
37
|
-
existingActions.
|
|
38
|
-
}
|
|
39
|
-
else if (ifExists === 'skip') {
|
|
40
|
-
existingActions.skip.push(file);
|
|
33
|
+
existingActions.push({ pattern, action: 'merge' });
|
|
41
34
|
}
|
|
42
35
|
else if (ifExists === 'overwrite') {
|
|
43
|
-
existingActions.
|
|
36
|
+
existingActions.push({ pattern, action: 'overwrite' });
|
|
44
37
|
}
|
|
45
38
|
else if (ifExists === 'remove') {
|
|
46
|
-
context.removedPatterns.push(
|
|
39
|
+
context.removedPatterns.push(pattern);
|
|
47
40
|
continue;
|
|
48
41
|
}
|
|
42
|
+
else if (ifExists === 'skip') {
|
|
43
|
+
existingActions.push({ pattern, action: 'skip' });
|
|
44
|
+
}
|
|
49
45
|
if (filter) {
|
|
50
|
-
filters[
|
|
46
|
+
filters[pattern] = filter;
|
|
51
47
|
}
|
|
52
48
|
if (route) {
|
|
53
49
|
const { alias } = route;
|
|
@@ -56,28 +52,28 @@ async function configureUpdateFileActions(context) {
|
|
|
56
52
|
return travel;
|
|
57
53
|
}
|
|
58
54
|
if (alias) {
|
|
59
|
-
routes[
|
|
55
|
+
routes[pattern] = {
|
|
60
56
|
alias,
|
|
61
57
|
travel: travel.value,
|
|
62
58
|
};
|
|
63
59
|
}
|
|
64
60
|
else {
|
|
65
|
-
routes[
|
|
61
|
+
routes[pattern] = {
|
|
66
62
|
travel: travel.value,
|
|
67
63
|
};
|
|
68
64
|
}
|
|
69
65
|
}
|
|
70
66
|
if (transforms) {
|
|
71
|
-
transformations[
|
|
67
|
+
transformations[pattern] = transforms;
|
|
72
68
|
}
|
|
73
69
|
}
|
|
74
70
|
if (skipMissings.length > 0) {
|
|
75
71
|
context.onMissing = (file) => (0, micromatch_1.isMatch)(file, skipMissings) ? 'skip' : 'continue';
|
|
76
72
|
}
|
|
77
|
-
if (existingActions.
|
|
73
|
+
if (existingActions.length > 0) {
|
|
78
74
|
context.onExisting = (file) => {
|
|
79
|
-
for (const
|
|
80
|
-
if ((0, micromatch_1.isMatch)(file,
|
|
75
|
+
for (const { pattern, action } of existingActions) {
|
|
76
|
+
if ((0, micromatch_1.isMatch)(file, pattern)) {
|
|
81
77
|
return action;
|
|
82
78
|
}
|
|
83
79
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AsyncDResult } from '@zokugun/xtry';
|
|
2
|
-
import { type TextFile } from '../types/
|
|
2
|
+
import { type TextFile } from '../types/context.js';
|
|
3
3
|
export declare function insertFinalNewLine({ mergedTextFiles, transformedFiles }: {
|
|
4
4
|
mergedTextFiles: TextFile[];
|
|
5
5
|
transformedFiles?: TextFile[];
|
|
@@ -9,6 +9,8 @@ const cli_utils_1 = require("@zokugun/cli-utils");
|
|
|
9
9
|
const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
|
|
10
10
|
const xtry_1 = require("@zokugun/xtry");
|
|
11
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");
|
|
12
14
|
async function mergeTextFiles({ targetPath, textFiles, mergedTextFiles, onExisting, onMissing, filters, routes, transforms, options }) {
|
|
13
15
|
for (const file of textFiles) {
|
|
14
16
|
if (options.verbose) {
|
|
@@ -61,6 +63,8 @@ async function mergeTextFiles({ targetPath, textFiles, mergedTextFiles, onExisti
|
|
|
61
63
|
if (current.fails) {
|
|
62
64
|
return (0, xtry_1.err)((0, xtry_1.stringifyError)(current.error));
|
|
63
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);
|
|
64
68
|
const data = await journey.travel({
|
|
65
69
|
current: current.value,
|
|
66
70
|
incoming: file.data,
|
|
@@ -70,7 +74,8 @@ async function mergeTextFiles({ targetPath, textFiles, mergedTextFiles, onExisti
|
|
|
70
74
|
mergedTextFiles.push({
|
|
71
75
|
name: fileName,
|
|
72
76
|
data,
|
|
73
|
-
finalNewLine
|
|
77
|
+
finalNewLine,
|
|
78
|
+
indent,
|
|
74
79
|
mode: file.mode,
|
|
75
80
|
});
|
|
76
81
|
if (options.verbose) {
|
package/lib/steps/read-files.js
CHANGED
|
@@ -10,6 +10,8 @@ const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
|
|
|
10
10
|
const xtry_1 = require("@zokugun/xtry");
|
|
11
11
|
const globby_1 = __importDefault(require("globby"));
|
|
12
12
|
const istextorbinary_1 = require("istextorbinary");
|
|
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");
|
|
13
15
|
const read_buffer_js_1 = require("../utils/read-buffer.js");
|
|
14
16
|
async function readFiles({ incomingPath, textFiles, binaryFiles, options }) {
|
|
15
17
|
const cwd = path_1.default.join(incomingPath, 'configs');
|
|
@@ -26,7 +28,8 @@ async function readFiles({ incomingPath, textFiles, binaryFiles, options }) {
|
|
|
26
28
|
return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
|
|
27
29
|
}
|
|
28
30
|
const data = result.value;
|
|
29
|
-
const finalNewLine =
|
|
31
|
+
const finalNewLine = (0, has_final_new_line_js_1.hasFinalNewLine)(data);
|
|
32
|
+
const indent = (0, detect_indent_js_1.detectIndent)(data);
|
|
30
33
|
if (data.startsWith('#!')) {
|
|
31
34
|
// the text file might be executable
|
|
32
35
|
const result = await async_1.default.stat(filePath);
|
|
@@ -37,8 +40,9 @@ async function readFiles({ incomingPath, textFiles, binaryFiles, options }) {
|
|
|
37
40
|
textFiles.push({
|
|
38
41
|
name: file,
|
|
39
42
|
data,
|
|
40
|
-
mode,
|
|
41
43
|
finalNewLine,
|
|
44
|
+
indent,
|
|
45
|
+
mode,
|
|
42
46
|
});
|
|
43
47
|
if (options.verbose) {
|
|
44
48
|
cli_utils_1.logger.debug(`${file} is a shebang file`);
|
|
@@ -49,6 +53,7 @@ async function readFiles({ incomingPath, textFiles, binaryFiles, options }) {
|
|
|
49
53
|
name: file,
|
|
50
54
|
data,
|
|
51
55
|
finalNewLine,
|
|
56
|
+
indent,
|
|
52
57
|
});
|
|
53
58
|
if (options.verbose) {
|
|
54
59
|
cli_utils_1.logger.debug(`${file} is a text file`);
|
|
@@ -12,7 +12,6 @@ const xtry_1 = require("@zokugun/xtry");
|
|
|
12
12
|
const globby_1 = __importDefault(require("globby"));
|
|
13
13
|
const index_js_1 = require("../journeys/index.js");
|
|
14
14
|
const detect_indent_js_1 = require("../utils/detect-indent.js");
|
|
15
|
-
const get_format_js_1 = require("../utils/get-format.js");
|
|
16
15
|
const has_final_new_line_js_1 = require("../utils/has-final-new-line.js");
|
|
17
16
|
async function transformUntouchedFiles({ formats, options, routes, targetPath, textFiles, transformedFiles, transforms }) {
|
|
18
17
|
if (transforms.length === 0) {
|
|
@@ -44,7 +43,8 @@ async function transformUntouchedFiles({ formats, options, routes, targetPath, t
|
|
|
44
43
|
return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
|
|
45
44
|
}
|
|
46
45
|
const data = result.value;
|
|
47
|
-
const finalNewLine =
|
|
46
|
+
const finalNewLine = (0, has_final_new_line_js_1.hasFinalNewLine)(data);
|
|
47
|
+
const indent = (0, detect_indent_js_1.detectIndent)(data);
|
|
48
48
|
const transformed = await journey.travel({
|
|
49
49
|
current: data,
|
|
50
50
|
incoming: undefined,
|
|
@@ -53,21 +53,12 @@ async function transformUntouchedFiles({ formats, options, routes, targetPath, t
|
|
|
53
53
|
transformedFiles.push({
|
|
54
54
|
name: file,
|
|
55
55
|
data: transformed,
|
|
56
|
-
finalNewLine
|
|
56
|
+
finalNewLine,
|
|
57
|
+
indent,
|
|
57
58
|
});
|
|
58
59
|
if (options.verbose) {
|
|
59
60
|
cli_utils_1.logger.debug(`${file} has been transformed`);
|
|
60
61
|
}
|
|
61
|
-
const format = (0, get_format_js_1.getFormat)(file, formats);
|
|
62
|
-
if (!format) {
|
|
63
|
-
const indent = (0, detect_indent_js_1.detectIndent)(data);
|
|
64
|
-
formats.push({
|
|
65
|
-
glob: file,
|
|
66
|
-
indentStyle: indent.style,
|
|
67
|
-
indentSize: indent.size,
|
|
68
|
-
insertFinalNewline: (0, has_final_new_line_js_1.hasFinalNewLine)(data),
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
62
|
}
|
|
72
63
|
return xtry_1.OK;
|
|
73
64
|
}
|
package/lib/types/config.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Indent } from './format.js';
|
|
1
2
|
export type Request = {
|
|
2
3
|
name: string;
|
|
3
4
|
variant?: string;
|
|
@@ -9,10 +10,10 @@ export type PackageManifest = {
|
|
|
9
10
|
export type PackageConfig = {
|
|
10
11
|
constants: Record<string, string>;
|
|
11
12
|
extends?: string;
|
|
12
|
-
install:
|
|
13
|
+
install: InstallFileConfig[];
|
|
13
14
|
orphan: boolean;
|
|
14
|
-
uninstall:
|
|
15
|
-
update: false |
|
|
15
|
+
uninstall: UninstallFileConfig[];
|
|
16
|
+
update: false | UpdateFileConfig[];
|
|
16
17
|
variables: Record<string, string>;
|
|
17
18
|
variants: Record<string, string>;
|
|
18
19
|
};
|
|
@@ -27,26 +28,25 @@ export type ArtifactResult = Artifact & {
|
|
|
27
28
|
export type InstallConfig = {
|
|
28
29
|
artifacts: Record<string, Artifact>;
|
|
29
30
|
constants: Record<string, string>;
|
|
30
|
-
install: Record<string,
|
|
31
|
-
update: false | Record<string,
|
|
31
|
+
install: Record<string, InstallFileConfig>;
|
|
32
|
+
update: false | Record<string, UpdateFileConfig>;
|
|
32
33
|
variables: Record<string, string>;
|
|
33
34
|
};
|
|
34
|
-
export type
|
|
35
|
-
ifExists:
|
|
35
|
+
export type FileConfig<E> = {
|
|
36
|
+
ifExists: E;
|
|
37
|
+
pattern: string;
|
|
36
38
|
transforms: FileTransform[];
|
|
37
39
|
};
|
|
38
|
-
export type
|
|
40
|
+
export type AlwaysFileConfig = FileConfig<'force-merge' | 'merge' | 'overwrite' | 'remove' | 'skip'>;
|
|
41
|
+
export type InstallFileConfig = UpsertFileConfig;
|
|
42
|
+
export type UninstallFileConfig = FileConfig<'remove' | 'skip' | 'unmerge'>;
|
|
43
|
+
export type UpdateFileConfig = UpsertFileConfig;
|
|
44
|
+
export type UpsertFileConfig = AlwaysFileConfig & {
|
|
39
45
|
filter?: string[];
|
|
40
46
|
ifMissing: 'merge' | 'skip';
|
|
41
47
|
rename?: string;
|
|
42
48
|
route?: Record<string, any>;
|
|
43
49
|
};
|
|
44
|
-
export type FileInstall = FileUpsert & {};
|
|
45
|
-
export type FileUninstall = {
|
|
46
|
-
ifExists: 'remove' | 'skip' | 'unmerge';
|
|
47
|
-
transforms: FileTransform[];
|
|
48
|
-
};
|
|
49
|
-
export type FileUpdate = FileUpsert & {};
|
|
50
50
|
export type FileTransform = {
|
|
51
51
|
description?: string;
|
|
52
52
|
jq: string;
|
|
@@ -55,4 +55,5 @@ export type InstallConfigStats = {
|
|
|
55
55
|
name: string;
|
|
56
56
|
type: string;
|
|
57
57
|
finalNewLine: boolean;
|
|
58
|
+
indent?: Indent;
|
|
58
59
|
};
|
package/lib/types/context.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { type AsyncDResult } from '@zokugun/xtry';
|
|
2
2
|
import { type BinaryFile } from './binary-file.js';
|
|
3
3
|
import { type Request, type InstallConfig, type PackageConfig, type ArtifactResult, type PackageManifest, type FileTransform } from './config.js';
|
|
4
|
-
import { type Format } from './format.js';
|
|
5
|
-
import { type TextFile } from './text-file.js';
|
|
4
|
+
import { type Indent, type Format } from './format.js';
|
|
6
5
|
import { type Journey } from './travel.js';
|
|
7
6
|
export type ExistingAction = 'merge' | 'overwrite' | 'skip';
|
|
8
7
|
export type MissingAction = 'continue' | 'skip';
|
|
@@ -54,3 +53,10 @@ export type Block = {
|
|
|
54
53
|
branch?: string;
|
|
55
54
|
incomingPath: string;
|
|
56
55
|
};
|
|
56
|
+
export type TextFile = {
|
|
57
|
+
data: string;
|
|
58
|
+
finalNewLine: boolean;
|
|
59
|
+
indent?: Indent;
|
|
60
|
+
mode?: number;
|
|
61
|
+
name: string;
|
|
62
|
+
};
|
package/lib/types/context.js
CHANGED
package/lib/types/format.d.ts
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function detectIndent(text: string):
|
|
3
|
-
style: IndentStyle;
|
|
4
|
-
size: number;
|
|
5
|
-
};
|
|
1
|
+
import { type Indent } from '../types/format.js';
|
|
2
|
+
export declare function detectIndent(text: string): Indent | undefined;
|
package/package.json
CHANGED
|
@@ -1,125 +1,126 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
2
|
+
"name": "@zokugun/artifact",
|
|
3
|
+
"description": "Boilerplate your project & keep your configurations up to date",
|
|
4
|
+
"version": "0.6.1",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Baptiste Augrain",
|
|
7
|
+
"email": "daiyam@zokugun.org"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"homepage": "https://github.com/zokugun/artifact",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/zokugun/artifact.git"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/zokugun/artifact/discussions/categories/issue-triage"
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=18.20"
|
|
20
|
+
},
|
|
21
|
+
"bin": {
|
|
22
|
+
"artifact": "bin/artifact",
|
|
23
|
+
"atf": "bin/artifact"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"audit:fix": "npm audit fix --min-release-age=0",
|
|
27
|
+
"build": "npm run clean && npm run compile:src",
|
|
28
|
+
"ci:lint": "zizmor .",
|
|
29
|
+
"ci:lint:fix": "zizmor . --fix=all",
|
|
30
|
+
"clean": "rimraf .test lib",
|
|
31
|
+
"compile:src": "tsc -p src",
|
|
32
|
+
"lint": "xo",
|
|
33
|
+
"lint:all": "fixpack && npm run ci:lint && npm run lint",
|
|
34
|
+
"lint:fix": "xo --fix",
|
|
35
|
+
"prepack": "npm run build",
|
|
36
|
+
"prepare": "husky; fixpack || true",
|
|
37
|
+
"release": "release-it",
|
|
38
|
+
"test": "tsc -p test && mocha",
|
|
39
|
+
"test:dev": "mocha",
|
|
40
|
+
"test:watch": "tsc-watch -p src -p test --onSuccess 'mocha -g=\"\"'",
|
|
41
|
+
"update:artifacts": "artifact update",
|
|
42
|
+
"update:ci": "PINACT_MIN_AGE=7 pinact run",
|
|
43
|
+
"update:deps": "taze",
|
|
44
|
+
"watch:build": "tsc-watch -p src --onSuccess 'npm run build'",
|
|
45
|
+
"watch:src": "tsc-watch -p src",
|
|
46
|
+
"watch:test": "tsc-watch -p test"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@zokugun/cli-utils": "0.3.1",
|
|
50
|
+
"@zokugun/configdotts-merge": "0.2.1",
|
|
51
|
+
"@zokugun/fs-extra-plus": "0.3.7",
|
|
52
|
+
"@zokugun/is-it-type": "0.8.1",
|
|
53
|
+
"@zokugun/xtry": "0.11.4",
|
|
54
|
+
"dayjs": "1.11.20",
|
|
55
|
+
"editorconfig": "0.15.3",
|
|
56
|
+
"globby": "11.1.0",
|
|
57
|
+
"istextorbinary": "6.0.0",
|
|
58
|
+
"jq-wasm": "1.1.0-jq-1.8.1",
|
|
59
|
+
"jsonc-parser": "3.3.1",
|
|
60
|
+
"lodash-es": "4.18.1",
|
|
61
|
+
"micromatch": "4.0.8",
|
|
62
|
+
"pacote": "21.5.0",
|
|
63
|
+
"semver": "7.7.4",
|
|
64
|
+
"tempy": "1.0.1",
|
|
65
|
+
"untildify": "4.0.0",
|
|
66
|
+
"yaml": "2.8.3"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@commitlint/cli": "19.8.1",
|
|
70
|
+
"@commitlint/config-conventional": "19.8.1",
|
|
71
|
+
"@types/chai": "4.3.20",
|
|
72
|
+
"@types/chai-as-promised": "7.1.8",
|
|
73
|
+
"@types/lodash-es": "4.17.12",
|
|
74
|
+
"@types/micromatch": "4.0.10",
|
|
75
|
+
"@types/mocha": "9.1.1",
|
|
76
|
+
"@types/node": "20.19.39",
|
|
77
|
+
"@types/npm": "7.19.3",
|
|
78
|
+
"@types/pacote": "11.1.8",
|
|
79
|
+
"@types/semver": "7.7.1",
|
|
80
|
+
"@types/universalify": "1.0.3",
|
|
81
|
+
"camelcase": "6.3.0",
|
|
82
|
+
"chai": "4.5.0",
|
|
83
|
+
"chai-as-promised": "7.1.2",
|
|
84
|
+
"eslint": "8.11.0",
|
|
85
|
+
"eslint-plugin-chai-friendly": "0.7.4",
|
|
86
|
+
"fixpack": "4.0.0",
|
|
87
|
+
"husky": "9.1.7",
|
|
88
|
+
"lint-staged": "16.4.0",
|
|
89
|
+
"memfs": "3.6.0",
|
|
90
|
+
"mocha": "9.2.2",
|
|
91
|
+
"release-it": "20.0.0",
|
|
92
|
+
"rewiremock": "3.14.6",
|
|
93
|
+
"source-map-support": "0.5.21",
|
|
94
|
+
"taze": "19.11.0",
|
|
95
|
+
"tsc-watch": "7.2.0",
|
|
96
|
+
"typescript": "5.9.3",
|
|
97
|
+
"universalify": "2.0.1",
|
|
98
|
+
"xo": "0.60.0"
|
|
99
|
+
},
|
|
100
|
+
"overrides": {
|
|
101
|
+
"mocha": {
|
|
102
|
+
"diff": "5.2.2",
|
|
103
|
+
"glob": "8.1.0",
|
|
104
|
+
"js-yaml": "4.1.1",
|
|
105
|
+
"minimatch": "4.2.6",
|
|
106
|
+
"nanoid": "3.3.11",
|
|
107
|
+
"serialize-javascript": "7.0.5"
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
"keywords": [
|
|
111
|
+
"artifact",
|
|
112
|
+
"boilerplate",
|
|
113
|
+
"boilerplates",
|
|
114
|
+
"codegeneration",
|
|
115
|
+
"codemod",
|
|
116
|
+
"codemods",
|
|
117
|
+
"configuration",
|
|
118
|
+
"configurations",
|
|
119
|
+
"generate",
|
|
120
|
+
"generator",
|
|
121
|
+
"project-generator",
|
|
122
|
+
"project-starter",
|
|
123
|
+
"project-template",
|
|
124
|
+
"scaffold"
|
|
125
|
+
]
|
|
125
126
|
}
|
package/lib/types/text-file.d.ts
DELETED
package/lib/types/text-file.js
DELETED