@zokugun/artifact 0.8.0 → 0.9.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/lib/commands/add.js +67 -37
- package/lib/commands/list.js +2 -2
- package/lib/commands/outdated.js +2 -2
- package/lib/commands/remove.js +12 -18
- package/lib/commands/update.js +36 -21
- package/lib/compositors/codec.d.ts +3 -0
- package/lib/compositors/codec.js +46 -0
- package/lib/compositors/compose.d.ts +1 -0
- package/lib/compositors/compose.js +4 -0
- package/lib/compositors/index.d.ts +1 -0
- package/lib/compositors/index.js +3 -1
- package/lib/compositors/json.js +3 -66
- package/lib/compositors/rc.js +3 -56
- package/lib/compositors/yaml.js +24 -3
- package/lib/configs/install/read-install-config.d.ts +2 -5
- package/lib/configs/install/read-install-config.js +20 -18
- package/lib/configs/install/write-install-config.d.ts +2 -2
- package/lib/configs/install/write-install-config.js +2 -1
- package/lib/configs/package/read-package-config.d.ts +2 -1
- package/lib/configs/package/read-package-config.js +96 -10
- package/lib/configs/utils/constants.d.ts +2 -2
- package/lib/configs/utils/constants.js +2 -2
- package/lib/configs/utils/merge-upsert-property.js +0 -8
- package/lib/configs/utils/normalize-file-always.js +5 -0
- package/lib/configs/utils/normalize-file-upsert.d.ts +2 -1
- package/lib/configs/utils/normalize-file-upsert.js +12 -5
- package/lib/journeys/commitlint/index.d.ts +1 -1
- package/lib/journeys/config.ts/index.d.ts +1 -1
- package/lib/journeys/config.ts/index.js +2 -6
- package/lib/journeys/default/index.d.ts +1 -1
- package/lib/journeys/gitignore/index.d.ts +1 -1
- package/lib/journeys/ignore/index.d.ts +1 -1
- package/lib/journeys/index.d.ts +2 -2
- package/lib/journeys/index.js +9 -11
- package/lib/journeys/npmignore/index.d.ts +1 -1
- package/lib/journeys/package/index.d.ts +1 -1
- package/lib/journeys/rc/index.d.ts +1 -1
- package/lib/journeys/tsconfig/index.d.ts +1 -1
- package/lib/parsers/index.d.ts +4 -0
- package/lib/parsers/index.js +41 -0
- package/lib/parsers/json.d.ts +4 -2
- package/lib/parsers/json.js +7 -2
- package/lib/parsers/jsonc/parse.d.ts +2 -5
- package/lib/parsers/jsonc/parse.js +8 -6
- package/lib/parsers/to-format.d.ts +2 -0
- package/lib/parsers/to-format.js +50 -0
- package/lib/parsers/yaml.d.ts +4 -2
- package/lib/parsers/yaml.js +7 -2
- package/lib/routes/command.js +7 -0
- package/lib/routes/index.d.ts +4 -3
- package/lib/routes/index.js +9 -7
- package/lib/routes/{list-sort-concat.d.ts → list-concat-after.d.ts} +1 -1
- package/lib/routes/{list-sort-concat.js → list-concat-after.js} +2 -2
- package/lib/routes/merge-dot-js.d.ts +2 -0
- package/lib/routes/merge-dot-js.js +8 -0
- package/lib/steps/configure-install-file-actions.js +1 -20
- package/lib/steps/configure-update-file-actions.js +1 -20
- package/lib/steps/execute-first-block.js +1 -1
- package/lib/steps/index.d.ts +0 -2
- package/lib/steps/index.js +4 -3
- package/lib/steps/merge-text-files.d.ts +1 -1
- package/lib/steps/merge-text-files.js +6 -2
- package/lib/steps/read-files.d.ts +1 -1
- package/lib/steps/read-files.js +56 -42
- package/lib/steps/read-incoming-config.js +1 -1
- package/lib/steps/remove-files.d.ts +1 -1
- package/lib/steps/remove-files.js +3 -2
- package/lib/steps/rename-files.d.ts +1 -1
- package/lib/steps/rename-files.js +3 -2
- package/lib/steps/validate-newer-package.d.ts +1 -1
- package/lib/steps/validate-newer-package.js +13 -2
- package/lib/types/config.d.ts +11 -7
- package/lib/types/context.d.ts +23 -3
- package/lib/types/context.js +6 -0
- package/lib/types/travel.d.ts +1 -0
- package/lib/utils/build-journey-plan.d.ts +2 -2
- package/lib/utils/build-route.d.ts +1 -1
- package/lib/utils/build-route.js +50 -19
- package/lib/utils/build-travel-plan.js +1 -0
- package/lib/utils/command/merge-and-chains.js +1 -1
- package/lib/utils/command/merge-command-records.js +1 -1
- package/lib/utils/command/merge-parts-by-prefix.js +12 -1
- package/lib/utils/command/merge-semicolon-segments.js +161 -4
- package/lib/utils/fnmatch.d.ts +1 -0
- package/lib/utils/fnmatch.js +11 -0
- package/lib/utils/get-format.js +2 -9
- package/lib/utils/load-package.d.ts +6 -0
- package/lib/utils/load-package.js +26 -0
- package/lib/utils/template.js +1 -3
- package/package.json +128 -127
- package/lib/journeys/fixpack/index.d.ts +0 -2
- package/lib/journeys/fixpack/index.js +0 -16
- package/lib/steps/validate-not-present-package.d.ts +0 -3
- package/lib/steps/validate-not-present-package.js +0 -24
- package/lib/utils/try-json.d.ts +0 -1
- package/lib/utils/try-json.js +0 -11
package/lib/commands/add.js
CHANGED
|
@@ -12,10 +12,10 @@ const tempy_1 = __importDefault(require("tempy"));
|
|
|
12
12
|
const index_js_1 = require("../configs/index.js");
|
|
13
13
|
const read_listing_config_js_1 = require("../configs/package/read-listing-config.js");
|
|
14
14
|
const index_js_2 = require("../steps/index.js");
|
|
15
|
+
const load_package_js_1 = require("../utils/load-package.js");
|
|
15
16
|
const resolve_request_js_1 = require("../utils/resolve-request.js");
|
|
16
17
|
const { mainFlow } = (0, index_js_2.composeSteps)([
|
|
17
18
|
index_js_2.steps.readIncomingPackage,
|
|
18
|
-
index_js_2.steps.validateNotPresentPackage,
|
|
19
19
|
index_js_2.steps.readIncomingConfig,
|
|
20
20
|
index_js_2.steps.executeFirstBlock,
|
|
21
21
|
], [
|
|
@@ -37,24 +37,6 @@ const { mainFlow } = (0, index_js_2.composeSteps)([
|
|
|
37
37
|
]);
|
|
38
38
|
async function add(specs, inputOptions) {
|
|
39
39
|
cli_utils_1.logger.beginTimer();
|
|
40
|
-
const targetPath = node_process_1.default.cwd();
|
|
41
|
-
const options = {
|
|
42
|
-
dryRun: inputOptions?.dryRun ?? false,
|
|
43
|
-
force: inputOptions?.force ?? false,
|
|
44
|
-
skip: inputOptions?.skip ?? false,
|
|
45
|
-
variables: {},
|
|
46
|
-
verbose: inputOptions?.verbose ?? false,
|
|
47
|
-
};
|
|
48
|
-
if (inputOptions?.var) {
|
|
49
|
-
for (const { name, value } of inputOptions.var) {
|
|
50
|
-
options.variables[name] = value;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
const configResult = await (0, index_js_1.readInstallConfig)(targetPath);
|
|
54
|
-
if (configResult.fails) {
|
|
55
|
-
cli_utils_1.logger.fatal(configResult.error);
|
|
56
|
-
}
|
|
57
|
-
const { config, configStats } = configResult.value;
|
|
58
40
|
if (specs.length === 1 && /^@\w+$/.test(specs[0])) {
|
|
59
41
|
const request = `${specs.shift()}/artifact-listing`;
|
|
60
42
|
const spinner = cli_utils_1.logger.createSpinner(`${cli_utils_1.c.cyan.bold(request)}`);
|
|
@@ -96,28 +78,76 @@ async function add(specs, inputOptions) {
|
|
|
96
78
|
}
|
|
97
79
|
}
|
|
98
80
|
}
|
|
81
|
+
const targetPath = node_process_1.default.cwd();
|
|
82
|
+
const options = {
|
|
83
|
+
dryRun: inputOptions?.dryRun ?? false,
|
|
84
|
+
force: inputOptions?.force ?? false,
|
|
85
|
+
skip: inputOptions?.skip ?? false,
|
|
86
|
+
variables: {},
|
|
87
|
+
verbose: inputOptions?.verbose ?? false,
|
|
88
|
+
};
|
|
89
|
+
if (inputOptions?.var) {
|
|
90
|
+
for (const { name, value } of inputOptions.var) {
|
|
91
|
+
options.variables[name] = value;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const configResult = await (0, index_js_1.readInstallConfig)(targetPath);
|
|
95
|
+
if (configResult.fails) {
|
|
96
|
+
cli_utils_1.logger.fatal(configResult.error);
|
|
97
|
+
}
|
|
98
|
+
const config = configResult.value;
|
|
99
|
+
const requests = [];
|
|
99
100
|
for (const spec of specs) {
|
|
100
|
-
const
|
|
101
|
-
if (
|
|
102
|
-
cli_utils_1.logger.fatal(
|
|
101
|
+
const request = (0, resolve_request_js_1.resolveRequest)(spec);
|
|
102
|
+
if (request.fails) {
|
|
103
|
+
cli_utils_1.logger.fatal(request.error);
|
|
103
104
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
105
|
+
if (!options.force) {
|
|
106
|
+
const { name } = request.value;
|
|
107
|
+
const artifact = config.artifacts[name];
|
|
108
|
+
if (artifact) {
|
|
109
|
+
if (options.skip) {
|
|
110
|
+
if (options.verbose) {
|
|
111
|
+
cli_utils_1.logger.debug(`The "${name}" artifact is already present, skipping...`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
cli_utils_1.logger.fatal(`The "${name}" artifact has already been added.`);
|
|
113
116
|
}
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
cli_utils_1.logger.fatal(pkgResult.from);
|
|
118
117
|
}
|
|
119
118
|
}
|
|
120
|
-
|
|
119
|
+
requests.push(request.value);
|
|
120
|
+
}
|
|
121
|
+
const global = {
|
|
122
|
+
journeys: {},
|
|
123
|
+
overwrittenTextFiles: [],
|
|
124
|
+
routes: {},
|
|
125
|
+
};
|
|
126
|
+
for (const [name, { version }] of Object.entries(config.artifacts)) {
|
|
127
|
+
const spinner = cli_utils_1.logger.createSpinner(`${cli_utils_1.c.cyan.bold(name)}`);
|
|
128
|
+
const dir = await (0, load_package_js_1.loadPackage)(`${name}@${version}`, spinner, options);
|
|
129
|
+
if (!dir) {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
const result = await (0, index_js_1.readPackageConfig)(dir, global.routes);
|
|
133
|
+
if (result.fails) {
|
|
134
|
+
cli_utils_1.logger.fatal(result.error);
|
|
135
|
+
}
|
|
136
|
+
for (const [name, journey] of Object.entries(result.value.journeys)) {
|
|
137
|
+
global.journeys[name] = journey;
|
|
138
|
+
}
|
|
139
|
+
for (const [name, route] of Object.entries(result.value.routes)) {
|
|
140
|
+
global.routes[name] = route;
|
|
141
|
+
}
|
|
142
|
+
spinner.succeed();
|
|
143
|
+
}
|
|
144
|
+
for (const request of requests) {
|
|
145
|
+
const spinner = cli_utils_1.logger.createSpinner(`${cli_utils_1.c.cyan.bold(request.name)}`);
|
|
146
|
+
const dir = await (0, load_package_js_1.loadPackage)(request.name, spinner, options);
|
|
147
|
+
if (!dir) {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
const flowResult = await mainFlow(targetPath, dir, request, config, global, options);
|
|
121
151
|
if (flowResult.fails) {
|
|
122
152
|
cli_utils_1.logger.fatal(flowResult.error);
|
|
123
153
|
}
|
|
@@ -126,7 +156,7 @@ async function add(specs, inputOptions) {
|
|
|
126
156
|
continue;
|
|
127
157
|
}
|
|
128
158
|
(0, index_js_1.updateInstallConfig)(config, flowResult.value.result);
|
|
129
|
-
await (0, index_js_1.writeInstallConfig)(config,
|
|
159
|
+
await (0, index_js_1.writeInstallConfig)(config, flowResult.value.formats, targetPath, options);
|
|
130
160
|
spinner.succeed();
|
|
131
161
|
}
|
|
132
162
|
cli_utils_1.logger.finishTimer();
|
package/lib/commands/list.js
CHANGED
|
@@ -31,14 +31,14 @@ async function list() {
|
|
|
31
31
|
cli_utils_1.logger.fatal((0, xtry_1.stringifyError)(packageResult.error));
|
|
32
32
|
}
|
|
33
33
|
const { name } = packageResult.value;
|
|
34
|
-
const
|
|
34
|
+
const config = configResult.value;
|
|
35
35
|
const artifacts = Object.entries(config.artifacts);
|
|
36
36
|
cli_utils_1.logger.newLine();
|
|
37
37
|
if (artifacts.length === 0) {
|
|
38
38
|
cli_utils_1.logger.info('No artifacts have been installed.');
|
|
39
39
|
}
|
|
40
40
|
else {
|
|
41
|
-
cli_utils_1.logger.print(`${name} ${cli_utils_1.c.grey(
|
|
41
|
+
cli_utils_1.logger.print(`${name} ${cli_utils_1.c.grey(config.file.name)}`);
|
|
42
42
|
cli_utils_1.logger.newLine();
|
|
43
43
|
const table = [];
|
|
44
44
|
for (const [name, artifact] of artifacts) {
|
package/lib/commands/outdated.js
CHANGED
|
@@ -26,14 +26,14 @@ async function outdated() {
|
|
|
26
26
|
cli_utils_1.logger.fatal((0, xtry_1.stringifyError)(packageResult.error));
|
|
27
27
|
}
|
|
28
28
|
const { name } = packageResult.value;
|
|
29
|
-
const
|
|
29
|
+
const config = configResult.value;
|
|
30
30
|
const artifacts = Object.entries(config.artifacts);
|
|
31
31
|
cli_utils_1.logger.newLine();
|
|
32
32
|
if (artifacts.length === 0) {
|
|
33
33
|
cli_utils_1.logger.info('No artifacts have been installed.');
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
36
|
-
cli_utils_1.logger.print(`${name} ${cli_utils_1.c.grey(
|
|
36
|
+
cli_utils_1.logger.print(`${name} ${cli_utils_1.c.grey(config.file.name)}`);
|
|
37
37
|
const bar = new cli_progress_1.SingleBar({
|
|
38
38
|
clearOnComplete: true,
|
|
39
39
|
hideCursor: true,
|
package/lib/commands/remove.js
CHANGED
|
@@ -7,10 +7,9 @@ exports.remove = remove;
|
|
|
7
7
|
const process_1 = __importDefault(require("process"));
|
|
8
8
|
const cli_utils_1 = require("@zokugun/cli-utils");
|
|
9
9
|
const async_1 = require("@zokugun/xtry/async");
|
|
10
|
-
const pacote_1 = __importDefault(require("pacote"));
|
|
11
|
-
const tempy_1 = __importDefault(require("tempy"));
|
|
12
10
|
const index_js_1 = require("../configs/index.js");
|
|
13
11
|
const index_js_2 = require("../steps/index.js");
|
|
12
|
+
const load_package_js_1 = require("../utils/load-package.js");
|
|
14
13
|
const resolve_request_js_1 = require("../utils/resolve-request.js");
|
|
15
14
|
const { mainFlow } = (0, index_js_2.composeSteps)([
|
|
16
15
|
index_js_2.steps.readIncomingPackage,
|
|
@@ -43,7 +42,7 @@ async function remove(specs, inputOptions) {
|
|
|
43
42
|
if (configResult.fails) {
|
|
44
43
|
cli_utils_1.logger.fatal(configResult.error);
|
|
45
44
|
}
|
|
46
|
-
const
|
|
45
|
+
const config = configResult.value;
|
|
47
46
|
if (specs.length === 0) {
|
|
48
47
|
const { value } = await (0, async_1.xtry)(cli_utils_1.enquirer.prompt({
|
|
49
48
|
type: 'multiselect',
|
|
@@ -70,6 +69,11 @@ async function remove(specs, inputOptions) {
|
|
|
70
69
|
}
|
|
71
70
|
}
|
|
72
71
|
}
|
|
72
|
+
const global = {
|
|
73
|
+
journeys: {},
|
|
74
|
+
overwrittenTextFiles: [],
|
|
75
|
+
routes: {},
|
|
76
|
+
};
|
|
73
77
|
for (const spec of specs) {
|
|
74
78
|
const requestResult = (0, resolve_request_js_1.resolveRequest)(spec);
|
|
75
79
|
if (requestResult.fails) {
|
|
@@ -77,21 +81,11 @@ async function remove(specs, inputOptions) {
|
|
|
77
81
|
}
|
|
78
82
|
const request = requestResult.value;
|
|
79
83
|
const spinner = cli_utils_1.logger.createSpinner(`${cli_utils_1.c.cyan.bold(request.name)}`);
|
|
80
|
-
const dir =
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (options.force || options.skip) {
|
|
84
|
-
spinner.fail();
|
|
85
|
-
if (options.verbose) {
|
|
86
|
-
cli_utils_1.logger.debug(`The artifact '${spec}' couldn't be found, skipping...`);
|
|
87
|
-
}
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
cli_utils_1.logger.fatal(pkgResult.from);
|
|
92
|
-
}
|
|
84
|
+
const dir = await (0, load_package_js_1.loadPackage)(request.name, spinner, options);
|
|
85
|
+
if (!dir) {
|
|
86
|
+
continue;
|
|
93
87
|
}
|
|
94
|
-
const flowResult = await mainFlow(targetPath, dir, request, config, options);
|
|
88
|
+
const flowResult = await mainFlow(targetPath, dir, request, config, global, options);
|
|
95
89
|
if (flowResult.fails) {
|
|
96
90
|
cli_utils_1.logger.fatal(flowResult.error);
|
|
97
91
|
}
|
|
@@ -100,7 +94,7 @@ async function remove(specs, inputOptions) {
|
|
|
100
94
|
continue;
|
|
101
95
|
}
|
|
102
96
|
(0, index_js_1.updateUninstallConfig)(config, flowResult.value.result);
|
|
103
|
-
await (0, index_js_1.writeInstallConfig)(config,
|
|
97
|
+
await (0, index_js_1.writeInstallConfig)(config, flowResult.value.formats, targetPath, options);
|
|
104
98
|
spinner.succeed();
|
|
105
99
|
}
|
|
106
100
|
cli_utils_1.logger.finishTimer();
|
package/lib/commands/update.js
CHANGED
|
@@ -7,10 +7,9 @@ exports.update = update;
|
|
|
7
7
|
const process_1 = __importDefault(require("process"));
|
|
8
8
|
const cli_utils_1 = require("@zokugun/cli-utils");
|
|
9
9
|
const lodash_es_1 = require("lodash-es");
|
|
10
|
-
const pacote_1 = __importDefault(require("pacote"));
|
|
11
|
-
const tempy_1 = __importDefault(require("tempy"));
|
|
12
10
|
const index_js_1 = require("../configs/index.js");
|
|
13
11
|
const index_js_2 = require("../steps/index.js");
|
|
12
|
+
const load_package_js_1 = require("../utils/load-package.js");
|
|
14
13
|
const { mainFlow } = (0, index_js_2.composeSteps)([
|
|
15
14
|
index_js_2.steps.readIncomingPackage,
|
|
16
15
|
index_js_2.steps.validateNewerPackage,
|
|
@@ -47,34 +46,50 @@ async function update(inputOptions) {
|
|
|
47
46
|
if (configResult.fails) {
|
|
48
47
|
cli_utils_1.logger.fatal(configResult.error);
|
|
49
48
|
}
|
|
50
|
-
const
|
|
49
|
+
const config = configResult.value;
|
|
50
|
+
const global = {
|
|
51
|
+
journeys: {},
|
|
52
|
+
overwrittenTextFiles: [],
|
|
53
|
+
routes: {},
|
|
54
|
+
};
|
|
51
55
|
for (const [name, artifact] of Object.entries(config.artifacts)) {
|
|
52
56
|
const spinner = cli_utils_1.logger.createSpinner(`${cli_utils_1.c.cyan.bold(name)}`);
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
if (!
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
const request = artifact.requires ? { name, variant: (0, lodash_es_1.last)(artifact.requires) } : { name };
|
|
58
|
+
const dir = await (0, load_package_js_1.loadPackage)(request.name, spinner, options);
|
|
59
|
+
if (!dir) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const result = await mainFlow(targetPath, dir, request, config, global, options);
|
|
63
|
+
if (result.fails) {
|
|
64
|
+
cli_utils_1.logger.fatal(result.error);
|
|
65
|
+
}
|
|
66
|
+
const context = result.value;
|
|
67
|
+
if (context?.incomingConfig) {
|
|
68
|
+
for (const [name, journey] of Object.entries(context.incomingConfig.journeys)) {
|
|
69
|
+
global.journeys[name] = journey;
|
|
62
70
|
}
|
|
63
|
-
|
|
64
|
-
|
|
71
|
+
for (const [name, route] of Object.entries(context.incomingConfig.routes)) {
|
|
72
|
+
global.routes[name] = route;
|
|
65
73
|
}
|
|
66
74
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
75
|
+
else {
|
|
76
|
+
const result = await (0, index_js_1.readPackageConfig)(dir, global.routes);
|
|
77
|
+
if (result.fails) {
|
|
78
|
+
cli_utils_1.logger.fatal(result.error);
|
|
79
|
+
}
|
|
80
|
+
for (const [name, journey] of Object.entries(result.value.journeys)) {
|
|
81
|
+
global.journeys[name] = journey;
|
|
82
|
+
}
|
|
83
|
+
for (const [name, route] of Object.entries(result.value.routes)) {
|
|
84
|
+
global.routes[name] = route;
|
|
85
|
+
}
|
|
71
86
|
}
|
|
72
|
-
if (!
|
|
87
|
+
if (!context?.result) {
|
|
73
88
|
spinner.succeed();
|
|
74
89
|
continue;
|
|
75
90
|
}
|
|
76
|
-
(0, index_js_1.updateInstallConfig)(config,
|
|
77
|
-
await (0, index_js_1.writeInstallConfig)(config,
|
|
91
|
+
(0, index_js_1.updateInstallConfig)(config, context.result);
|
|
92
|
+
await (0, index_js_1.writeInstallConfig)(config, context.formats, targetPath, options);
|
|
78
93
|
spinner.succeed();
|
|
79
94
|
}
|
|
80
95
|
cli_utils_1.logger.finishTimer();
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.codec = codec;
|
|
4
|
+
const is_it_type_1 = require("@zokugun/is-it-type");
|
|
5
|
+
const list_concat_js_1 = require("../routes/list-concat.js");
|
|
6
|
+
const primitive_js_1 = require("../routes/primitive.js");
|
|
7
|
+
const apply_transforms_js_1 = require("../utils/apply-transforms.js");
|
|
8
|
+
const flow_js_1 = require("../utils/flow.js");
|
|
9
|
+
const compose_js_1 = require("./compose.js");
|
|
10
|
+
const fork_js_1 = require("./fork.js");
|
|
11
|
+
const merge = (0, compose_js_1.compose)({
|
|
12
|
+
$$default: (0, fork_js_1.fork)([is_it_type_1.isArray, list_concat_js_1.listConcat], [is_it_type_1.isRecord, async (...args) => merge(...args)], primitive_js_1.primitive),
|
|
13
|
+
});
|
|
14
|
+
function codec(codecs, ...routes) {
|
|
15
|
+
return async ({ current, incoming, filters, ignores, transforms }) => {
|
|
16
|
+
if (!(0, is_it_type_1.isNonBlankString)(current)) {
|
|
17
|
+
return incoming;
|
|
18
|
+
}
|
|
19
|
+
for (const { parse, stringify } of codecs) {
|
|
20
|
+
const currentResult = parse(current);
|
|
21
|
+
if (currentResult.fails) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if ((0, is_it_type_1.isNonBlankString)(incoming)) {
|
|
25
|
+
const incomingResult = parse(incoming);
|
|
26
|
+
if (incomingResult.fails) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const incomingData = incomingResult.value.data;
|
|
30
|
+
if (!(0, is_it_type_1.isArray)(incomingData) && !(0, is_it_type_1.isRecord)(incomingData)) {
|
|
31
|
+
return incoming;
|
|
32
|
+
}
|
|
33
|
+
const mergedTransform = currentResult.value.transform
|
|
34
|
+
? await merge({ current: currentResult.value.transform, incoming: incomingResult.value.transform })
|
|
35
|
+
: incomingResult.value.transform;
|
|
36
|
+
const run = (0, flow_js_1.flow)(...routes, (0, apply_transforms_js_1.applyTransforms)(transforms), (data) => stringify(data, mergedTransform));
|
|
37
|
+
return run({ current: currentResult.value.data, incoming: incomingData, filters, ignores });
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
const run = (0, flow_js_1.flow)(...routes, (0, apply_transforms_js_1.applyTransforms)(transforms), (data) => stringify(data, currentResult.value.transform));
|
|
41
|
+
return run({ current: currentResult.value.data, filters, ignores });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return incoming;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -7,7 +7,11 @@ async function apply(map, keys, current, incoming, result) {
|
|
|
7
7
|
return;
|
|
8
8
|
}
|
|
9
9
|
const ignores = map.$$ignore ?? [];
|
|
10
|
+
const removes = map.$$remove ?? [];
|
|
10
11
|
for (const key of keys) {
|
|
12
|
+
if (removes.includes(key)) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
11
15
|
const currentValue = current[key];
|
|
12
16
|
const transform = map[key] ?? map.$$default;
|
|
13
17
|
if (!transform || !(0, lodash_es_1.has)(incoming, key) || ignores.includes(key)) {
|
package/lib/compositors/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.yaml = exports.rc = exports.mapSort = exports.json = exports.fork = exports.compose = void 0;
|
|
3
|
+
exports.yaml = exports.rc = exports.mapSort = exports.json = exports.fork = exports.compose = exports.codec = void 0;
|
|
4
|
+
var codec_js_1 = require("./codec.js");
|
|
5
|
+
Object.defineProperty(exports, "codec", { enumerable: true, get: function () { return codec_js_1.codec; } });
|
|
4
6
|
var compose_js_1 = require("./compose.js");
|
|
5
7
|
Object.defineProperty(exports, "compose", { enumerable: true, get: function () { return compose_js_1.compose; } });
|
|
6
8
|
var fork_js_1 = require("./fork.js");
|
package/lib/compositors/json.js
CHANGED
|
@@ -1,71 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.json = json;
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const JSONC = __importStar(require("../parsers/jsonc/index.js"));
|
|
40
|
-
const index_js_1 = require("../routes/index.js");
|
|
41
|
-
const apply_transforms_js_1 = require("../utils/apply-transforms.js");
|
|
42
|
-
const flow_js_1 = require("../utils/flow.js");
|
|
43
|
-
const compose_js_1 = require("./compose.js");
|
|
44
|
-
const fork_js_1 = require("./fork.js");
|
|
45
|
-
function tryJson(value) {
|
|
46
|
-
try {
|
|
47
|
-
return JSON.parse(value);
|
|
48
|
-
}
|
|
49
|
-
catch {
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
const merge = (0, compose_js_1.compose)({
|
|
54
|
-
$$default: (0, fork_js_1.fork)([is_it_type_1.isArray, index_js_1.listConcat], [is_it_type_1.isRecord, async (...args) => merge(...args)], index_js_1.primitive),
|
|
55
|
-
});
|
|
4
|
+
const index_js_1 = require("../parsers/index.js");
|
|
5
|
+
const codec_js_1 = require("./codec.js");
|
|
56
6
|
function json(...routes) {
|
|
57
|
-
return
|
|
58
|
-
const currentData = current && tryJson(current);
|
|
59
|
-
const incomingData = incoming && tryJson(incoming);
|
|
60
|
-
if ((!current || currentData) && (!incoming || incomingData)) {
|
|
61
|
-
return await (0, flow_js_1.flow)(...routes, (0, apply_transforms_js_1.applyTransforms)(transforms), JSON.stringify)({ current: currentData, incoming: incomingData, filters, ignores, transforms });
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
const { data: currentData, transform: currentTransform } = JSONC.parse(current);
|
|
65
|
-
const { data: incomingData, transform: incomingTransform } = JSONC.parse(incoming);
|
|
66
|
-
const mergedTransform = await merge({ current: currentTransform, incoming: incomingTransform });
|
|
67
|
-
const toJSON = (data) => JSONC.stringify(data, mergedTransform);
|
|
68
|
-
return await (0, flow_js_1.flow)(...routes, (0, apply_transforms_js_1.applyTransforms)(transforms), toJSON)({ current: currentData, incoming: incomingData, filters, ignores, transforms });
|
|
69
|
-
}
|
|
70
|
-
};
|
|
7
|
+
return (0, codec_js_1.codec)([index_js_1.JSON, index_js_1.JSONC], ...routes);
|
|
71
8
|
}
|
package/lib/compositors/rc.js
CHANGED
|
@@ -1,61 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.rc = rc;
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const JSON = __importStar(require("../parsers/json.js"));
|
|
40
|
-
const YAML = __importStar(require("../parsers/yaml.js"));
|
|
41
|
-
const apply_transforms_js_1 = require("../utils/apply-transforms.js");
|
|
42
|
-
const flow_js_1 = require("../utils/flow.js");
|
|
43
|
-
const try_json_js_1 = require("../utils/try-json.js");
|
|
4
|
+
const index_js_1 = require("../parsers/index.js");
|
|
5
|
+
const codec_js_1 = require("./codec.js");
|
|
44
6
|
function rc(...routes) {
|
|
45
|
-
return
|
|
46
|
-
const currentData = current && ((0, try_json_js_1.tryJSON)(current) ?? YAML.parse(current));
|
|
47
|
-
const incomingData = incoming && (0, try_json_js_1.tryJSON)(incoming);
|
|
48
|
-
if (incomingData) {
|
|
49
|
-
return await (0, flow_js_1.flow)(...routes, (0, apply_transforms_js_1.applyTransforms)(transforms), JSON.stringify)({ current: currentData, incoming: incomingData, filters, ignores });
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
const incomingData = incoming && YAML.parse(incoming);
|
|
53
|
-
if ((0, lodash_es_1.isArray)(incomingData) || (0, is_it_type_1.isRecord)(incomingData)) {
|
|
54
|
-
return await (0, flow_js_1.flow)(...routes, (0, apply_transforms_js_1.applyTransforms)(transforms), YAML.stringify)({ current: currentData, incoming: incomingData, filters, ignores });
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
return incoming;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
7
|
+
return (0, codec_js_1.codec)([index_js_1.JSON, index_js_1.YAML], ...routes);
|
|
61
8
|
}
|
package/lib/compositors/yaml.js
CHANGED
|
@@ -34,13 +34,34 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.yaml = yaml;
|
|
37
|
+
const is_it_type_1 = require("@zokugun/is-it-type");
|
|
37
38
|
const YAML = __importStar(require("../parsers/yaml.js"));
|
|
38
39
|
const apply_transforms_js_1 = require("../utils/apply-transforms.js");
|
|
39
40
|
const flow_js_1 = require("../utils/flow.js");
|
|
40
41
|
function yaml(...routes) {
|
|
41
42
|
return async ({ current, incoming, filters, ignores, transforms }) => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
if (!(0, is_it_type_1.isNonBlankString)(current)) {
|
|
44
|
+
return incoming;
|
|
45
|
+
}
|
|
46
|
+
const currentResult = YAML.parse(current);
|
|
47
|
+
if (currentResult.fails) {
|
|
48
|
+
return incoming;
|
|
49
|
+
}
|
|
50
|
+
if ((0, is_it_type_1.isNonBlankString)(incoming)) {
|
|
51
|
+
const incomingResult = YAML.parse(incoming);
|
|
52
|
+
if (incomingResult.fails) {
|
|
53
|
+
return current;
|
|
54
|
+
}
|
|
55
|
+
const incomingData = incomingResult.value.data;
|
|
56
|
+
if (!(0, is_it_type_1.isArray)(incomingData) && !(0, is_it_type_1.isRecord)(incomingData)) {
|
|
57
|
+
return incoming;
|
|
58
|
+
}
|
|
59
|
+
const run = (0, flow_js_1.flow)(...routes, (0, apply_transforms_js_1.applyTransforms)(transforms), YAML.stringify);
|
|
60
|
+
return run({ current: currentResult.value.data, incoming: incomingData, filters, ignores });
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const run = (0, flow_js_1.flow)(...routes, (0, apply_transforms_js_1.applyTransforms)(transforms), YAML.stringify);
|
|
64
|
+
return run({ current: currentResult.value.data, filters, ignores });
|
|
65
|
+
}
|
|
45
66
|
};
|
|
46
67
|
}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
import { type AsyncDResult } from '@zokugun/xtry';
|
|
2
|
-
import { type InstallConfig
|
|
3
|
-
export declare function readInstallConfig(targetPath: string): AsyncDResult<
|
|
4
|
-
config: InstallConfig;
|
|
5
|
-
configStats: InstallConfigStats;
|
|
6
|
-
}>;
|
|
2
|
+
import { type InstallConfig } from '../../types/config.js';
|
|
3
|
+
export declare function readInstallConfig(targetPath: string): AsyncDResult<InstallConfig>;
|