@zokugun/artifact 0.5.2 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/artifact +1 -1
- package/lib/cli.d.ts +1 -0
- package/lib/cli.js +12 -4
- package/lib/commands/add.d.ts +6 -0
- package/lib/commands/add.js +47 -36
- package/lib/commands/index.d.ts +4 -0
- package/lib/commands/index.js +9 -7
- package/lib/commands/list.d.ts +1 -0
- package/lib/commands/list.js +13 -8
- package/lib/commands/remove.d.ts +6 -0
- package/lib/commands/remove.js +79 -0
- package/lib/commands/update.d.ts +5 -0
- package/lib/commands/update.js +43 -39
- package/lib/compositors/compose.d.ts +7 -0
- package/lib/compositors/compose.js +13 -13
- package/lib/compositors/fork.d.ts +3 -0
- package/lib/compositors/fork.js +4 -4
- package/lib/compositors/index.d.ts +6 -0
- package/lib/compositors/index.js +12 -12
- package/lib/compositors/json.d.ts +2 -0
- package/lib/compositors/json.js +14 -12
- package/lib/compositors/map-sort.d.ts +2 -0
- package/lib/compositors/map-sort.js +2 -2
- package/lib/compositors/rc.d.ts +2 -0
- package/lib/compositors/rc.js +13 -10
- package/lib/compositors/yaml.d.ts +2 -0
- package/lib/compositors/yaml.js +8 -11
- package/lib/configs/index.d.ts +3 -0
- package/lib/configs/index.js +3 -2
- package/lib/configs/install/index.d.ts +3 -0
- package/lib/configs/install/index.js +6 -6
- package/lib/configs/install/read-install-config.d.ts +6 -0
- package/lib/configs/install/read-install-config.js +128 -81
- package/lib/configs/install/update-install-config.d.ts +2 -0
- package/lib/configs/install/write-install-config.d.ts +5 -0
- package/lib/configs/install/write-install-config.js +25 -10
- package/lib/configs/package/index.d.ts +1 -0
- package/lib/configs/package/index.js +2 -2
- package/lib/configs/package/read-package-config.d.ts +3 -0
- package/lib/configs/package/read-package-config.js +160 -40
- package/lib/configs/uninstall/index.d.ts +1 -0
- package/lib/configs/uninstall/index.js +5 -0
- package/lib/configs/uninstall/update-uninstall-config.d.ts +2 -0
- package/lib/configs/uninstall/update-uninstall-config.js +6 -0
- package/lib/configs/utils/constants.d.ts +11 -0
- package/lib/configs/utils/constants.js +24 -0
- package/lib/configs/utils/is-transform.d.ts +2 -0
- package/lib/configs/utils/is-transform.js +16 -0
- package/lib/configs/utils/merge-upsert-property.d.ts +3 -0
- package/lib/configs/utils/merge-upsert-property.js +78 -0
- package/lib/configs/utils/normalize-file-always.d.ts +3 -0
- package/lib/configs/utils/normalize-file-always.js +29 -0
- package/lib/configs/utils/normalize-file-uninstall.d.ts +3 -0
- package/lib/configs/utils/normalize-file-uninstall.js +32 -0
- package/lib/configs/utils/normalize-file-upsert.d.ts +3 -0
- package/lib/configs/utils/normalize-file-upsert.js +55 -0
- package/lib/journeys/commitlint/index.d.ts +2 -0
- package/lib/journeys/commitlint/index.js +15 -15
- package/lib/journeys/config.ts/index.d.ts +2 -0
- package/lib/journeys/config.ts/index.js +5 -5
- package/lib/journeys/default/index.d.ts +2 -0
- package/lib/journeys/default/index.js +11 -14
- package/lib/journeys/fixpack/index.d.ts +2 -0
- package/lib/journeys/fixpack/index.js +13 -13
- package/lib/journeys/gitignore/index.d.ts +2 -0
- package/lib/journeys/gitignore/index.js +5 -5
- package/lib/journeys/ignore/index.d.ts +2 -0
- package/lib/journeys/ignore/index.js +5 -5
- package/lib/journeys/index.d.ts +2 -0
- package/lib/journeys/index.js +20 -20
- package/lib/journeys/npmignore/index.d.ts +2 -0
- package/lib/journeys/npmignore/index.js +5 -5
- package/lib/journeys/package/index.d.ts +2 -0
- package/lib/journeys/package/index.js +27 -30
- package/lib/journeys/rc/index.d.ts +2 -0
- package/lib/journeys/rc/index.js +12 -12
- package/lib/journeys/tsconfig/index.d.ts +2 -0
- package/lib/journeys/tsconfig/index.js +13 -16
- package/lib/parsers/json.d.ts +2 -0
- package/lib/parsers/jsonc/index.d.ts +2 -0
- package/lib/parsers/jsonc/index.js +4 -4
- package/lib/parsers/jsonc/parse.d.ts +5 -0
- package/lib/parsers/jsonc/parse.js +1 -13
- package/lib/parsers/jsonc/stringify.d.ts +2 -0
- package/lib/parsers/jsonc/stringify.js +2 -2
- package/lib/parsers/jsonc/transform.d.ts +10 -0
- package/lib/parsers/yaml.d.ts +2 -0
- package/lib/routes/command.d.ts +4 -0
- package/lib/routes/command.js +10 -10
- package/lib/routes/index.d.ts +8 -0
- package/lib/routes/index.js +17 -15
- package/lib/routes/lines-concat.d.ts +4 -0
- package/lib/routes/lines-concat.js +7 -7
- package/lib/routes/list-concat.d.ts +4 -0
- package/lib/routes/list-concat.js +3 -7
- package/lib/routes/list-sort-concat.d.ts +4 -0
- package/lib/routes/list-sort-concat.js +1 -1
- package/lib/routes/map-concat.d.ts +4 -0
- package/lib/routes/map-concat.js +1 -1
- package/lib/routes/map-delete.d.ts +4 -0
- package/lib/routes/map-delete.js +32 -0
- package/lib/routes/overwrite.d.ts +4 -0
- package/lib/routes/overwrite.js +2 -2
- package/lib/routes/primitive.d.ts +4 -0
- package/lib/routes/primitive.js +3 -3
- package/lib/steps/apply-formatting.d.ts +8 -0
- package/lib/steps/apply-formatting.js +50 -25
- package/lib/steps/configure-branches.d.ts +3 -0
- package/lib/steps/configure-branches.js +8 -5
- package/lib/steps/configure-install-file-actions.d.ts +3 -0
- package/lib/steps/configure-install-file-actions.js +59 -94
- package/lib/steps/configure-uninstall-file-actions.d.ts +3 -0
- package/lib/steps/configure-uninstall-file-actions.js +57 -0
- package/lib/steps/configure-update-file-actions.d.ts +3 -0
- package/lib/steps/configure-update-file-actions.js +65 -102
- package/lib/steps/copy-binary-files.d.ts +3 -0
- package/lib/steps/copy-binary-files.js +24 -11
- package/lib/steps/execute-first-block.d.ts +3 -0
- package/lib/steps/execute-first-block.js +35 -14
- package/lib/steps/execute-next-block.d.ts +3 -0
- package/lib/steps/execute-next-block.js +8 -3
- package/lib/steps/index.d.ts +54 -0
- package/lib/steps/index.js +76 -54
- package/lib/steps/insert-final-new-line.d.ts +6 -0
- package/lib/steps/insert-final-new-line.js +13 -1
- package/lib/steps/merge-text-files.d.ts +3 -0
- package/lib/steps/merge-text-files.js +47 -28
- package/lib/steps/read-editor-config.d.ts +3 -0
- package/lib/steps/read-editor-config.js +21 -26
- package/lib/steps/read-files.d.ts +3 -0
- package/lib/steps/read-files.js +26 -10
- package/lib/steps/read-incoming-config.d.ts +3 -0
- package/lib/steps/read-incoming-config.js +7 -5
- package/lib/steps/read-incoming-package.d.ts +3 -0
- package/lib/steps/read-incoming-package.js +12 -7
- package/lib/steps/remove-files.d.ts +3 -0
- package/lib/steps/remove-files.js +10 -4
- package/lib/steps/rename-files.d.ts +3 -0
- package/lib/steps/rename-files.js +25 -0
- package/lib/steps/replace-templates.d.ts +3 -0
- package/lib/steps/replace-templates.js +19 -5
- package/lib/steps/transform-untouched-files.d.ts +3 -0
- package/lib/steps/transform-untouched-files.js +64 -0
- package/lib/steps/unmerge-text-files.d.ts +3 -0
- package/lib/steps/unmerge-text-files.js +64 -0
- package/lib/steps/validate-newer-package.d.ts +3 -0
- package/lib/steps/validate-newer-package.js +4 -2
- package/lib/steps/validate-not-present-package.d.ts +3 -0
- package/lib/steps/validate-not-present-package.js +7 -4
- package/lib/steps/validate-present-package.d.ts +3 -0
- package/lib/steps/validate-present-package.js +24 -0
- package/lib/steps/write-text-files.d.ts +3 -0
- package/lib/steps/write-text-files.js +16 -7
- package/lib/types/binary-file.d.ts +4 -0
- package/lib/types/command.d.ts +5 -0
- package/lib/types/config.d.ts +59 -0
- package/lib/types/context.d.ts +62 -0
- package/lib/types/context.js +4 -0
- package/lib/types/format.d.ts +14 -0
- package/lib/types/step.d.ts +3 -0
- package/lib/types/travel.d.ts +14 -0
- package/lib/utils/apply-transforms.d.ts +2 -0
- package/lib/utils/apply-transforms.js +48 -0
- package/lib/utils/build-journey-plan.d.ts +2 -0
- package/lib/utils/build-route.d.ts +3 -0
- package/lib/utils/build-route.js +92 -0
- package/lib/utils/build-travel-plan.d.ts +2 -0
- package/lib/utils/build-travel.d.ts +3 -0
- package/lib/utils/build-travel.js +32 -0
- package/lib/utils/command/dedupe-strings.d.ts +1 -0
- package/lib/utils/command/index.d.ts +8 -0
- package/lib/utils/command/index.js +14 -14
- package/lib/utils/command/join-command.d.ts +2 -0
- package/lib/utils/command/merge-and-chains.d.ts +1 -0
- package/lib/utils/command/merge-and-chains.js +21 -21
- package/lib/utils/command/merge-command-records.d.ts +2 -0
- package/lib/utils/command/merge-command-records.js +43 -22
- package/lib/utils/command/merge-flag-tokens.d.ts +1 -0
- package/lib/utils/command/merge-flag-tokens.js +1 -1
- package/lib/utils/command/merge-flags-as-string.d.ts +4 -0
- package/lib/utils/command/merge-flags-as-string.js +4 -4
- package/lib/utils/command/merge-or-segments.d.ts +1 -0
- package/lib/utils/command/merge-or-segments.js +28 -28
- package/lib/utils/command/merge-parts-by-prefix.d.ts +1 -0
- package/lib/utils/command/merge-parts-by-prefix.js +6 -6
- package/lib/utils/command/merge-semicolon-segments.d.ts +1 -0
- package/lib/utils/command/merge-semicolon-segments.js +35 -35
- package/lib/utils/command/merge-with-semicolon-mix.d.ts +1 -0
- package/lib/utils/command/merge-with-semicolon-mix.js +12 -12
- package/lib/utils/command/prefix-of-command.d.ts +1 -0
- package/lib/utils/command/prefix-of-command.js +2 -2
- package/lib/utils/command/split-chain.d.ts +1 -0
- package/lib/utils/command/split-command.d.ts +2 -0
- package/lib/utils/command/split-command.js +8 -8
- package/lib/utils/command/split-prefix-and-flags.d.ts +4 -0
- package/lib/utils/command/split-prefix-and-flags.js +5 -5
- package/lib/utils/command/split-segments.d.ts +1 -0
- package/lib/utils/detect-indent.d.ts +2 -0
- package/lib/utils/detect-indent.js +63 -0
- package/lib/utils/flow.d.ts +3 -0
- package/lib/utils/flow.js +12 -0
- package/lib/utils/get-format.d.ts +2 -0
- package/lib/utils/get-format.js +19 -0
- package/lib/utils/has-final-new-line.d.ts +1 -0
- package/lib/utils/has-final-new-line.js +7 -0
- package/lib/utils/read-buffer.d.ts +2 -0
- package/lib/utils/resolve-request.d.ts +3 -0
- package/lib/utils/resolve-request.js +4 -3
- package/lib/utils/template.d.ts +17 -0
- package/lib/utils/template.js +79 -57
- package/lib/utils/to-lines.d.ts +1 -0
- package/lib/utils/trim-final-newline.d.ts +1 -0
- package/lib/utils/try-json.d.ts +1 -0
- package/lib/utils/try-json.js +2 -2
- package/package.json +74 -51
- package/lib/types/text-file.js +0 -2
- package/lib/utils/dev-null.js +0 -7
package/lib/compositors/json.js
CHANGED
|
@@ -34,12 +34,14 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.json = json;
|
|
37
|
-
const
|
|
38
|
-
const JSON = __importStar(require("../parsers/json"));
|
|
39
|
-
const JSONC = __importStar(require("../parsers/jsonc"));
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const
|
|
37
|
+
const is_it_type_1 = require("@zokugun/is-it-type");
|
|
38
|
+
const JSON = __importStar(require("../parsers/json.js"));
|
|
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");
|
|
43
45
|
function tryJson(value) {
|
|
44
46
|
try {
|
|
45
47
|
return JSON.parse(value);
|
|
@@ -48,22 +50,22 @@ function tryJson(value) {
|
|
|
48
50
|
return undefined;
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
|
-
const merge = (0,
|
|
52
|
-
$$default: (0,
|
|
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),
|
|
53
55
|
});
|
|
54
56
|
function json(...routes) {
|
|
55
|
-
return ({ current, incoming, filters, ignores }) => {
|
|
57
|
+
return async ({ current, incoming, filters, ignores, transforms }) => {
|
|
56
58
|
const currentData = current && tryJson(current);
|
|
57
59
|
const incomingData = incoming && tryJson(incoming);
|
|
58
60
|
if ((!current || currentData) && (!incoming || incomingData)) {
|
|
59
|
-
return (0,
|
|
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 });
|
|
60
62
|
}
|
|
61
63
|
else {
|
|
62
64
|
const { data: currentData, transform: currentTransform } = JSONC.parse(current);
|
|
63
65
|
const { data: incomingData, transform: incomingTransform } = JSONC.parse(incoming);
|
|
64
|
-
const mergedTransform = merge({ current: currentTransform, incoming: incomingTransform });
|
|
66
|
+
const mergedTransform = await merge({ current: currentTransform, incoming: incomingTransform });
|
|
65
67
|
const toJSON = (data) => JSONC.stringify(data, mergedTransform);
|
|
66
|
-
return (0,
|
|
68
|
+
return await (0, flow_js_1.flow)(...routes, (0, apply_transforms_js_1.applyTransforms)(transforms), toJSON)({ current: currentData, incoming: incomingData, filters, ignores, transforms });
|
|
67
69
|
}
|
|
68
70
|
};
|
|
69
71
|
}
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.mapSort = mapSort;
|
|
4
4
|
const { compare } = new Intl.Collator('en');
|
|
5
5
|
function mapSort(route) {
|
|
6
|
-
return (args) => {
|
|
7
|
-
const result = route(args);
|
|
6
|
+
return async (args) => {
|
|
7
|
+
const result = await route(args);
|
|
8
8
|
const sorted = {};
|
|
9
9
|
const keys = Object.keys(result).sort((a, b) => compare(a, b));
|
|
10
10
|
for (const key of keys) {
|
package/lib/compositors/rc.js
CHANGED
|
@@ -34,21 +34,24 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.rc = rc;
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
37
|
+
const is_it_type_1 = require("@zokugun/is-it-type");
|
|
38
|
+
const lodash_es_1 = require("lodash-es");
|
|
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");
|
|
41
44
|
function rc(...routes) {
|
|
42
|
-
return ({ current, incoming, filters, ignores }) => {
|
|
43
|
-
const currentData = current && ((0,
|
|
44
|
-
const incomingData = incoming && (0,
|
|
45
|
+
return async ({ current, incoming, filters, ignores, transforms }) => {
|
|
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);
|
|
45
48
|
if (incomingData) {
|
|
46
|
-
return (0,
|
|
49
|
+
return await (0, flow_js_1.flow)(...routes, (0, apply_transforms_js_1.applyTransforms)(transforms), JSON.stringify)({ current: currentData, incoming: incomingData, filters, ignores });
|
|
47
50
|
}
|
|
48
51
|
else {
|
|
49
52
|
const incomingData = incoming && YAML.parse(incoming);
|
|
50
|
-
if ((0,
|
|
51
|
-
return (0,
|
|
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 });
|
|
52
55
|
}
|
|
53
56
|
else {
|
|
54
57
|
return incoming;
|
package/lib/compositors/yaml.js
CHANGED
|
@@ -34,16 +34,13 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.yaml = yaml;
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
current: typeof current === 'undefined' ? undefined : YAML.parse(current),
|
|
42
|
-
incoming: YAML.parse(incoming),
|
|
43
|
-
filters,
|
|
44
|
-
ignores,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
37
|
+
const YAML = __importStar(require("../parsers/yaml.js"));
|
|
38
|
+
const apply_transforms_js_1 = require("../utils/apply-transforms.js");
|
|
39
|
+
const flow_js_1 = require("../utils/flow.js");
|
|
47
40
|
function yaml(...routes) {
|
|
48
|
-
return (
|
|
41
|
+
return async ({ current, incoming, filters, ignores, transforms }) => {
|
|
42
|
+
const currentData = current === undefined ? undefined : YAML.parse(current);
|
|
43
|
+
const incomingData = YAML.parse(incoming);
|
|
44
|
+
return await (0, flow_js_1.flow)(...routes, (0, apply_transforms_js_1.applyTransforms)(transforms), YAML.stringify)({ current: currentData, incoming: incomingData, filters, ignores, transforms });
|
|
45
|
+
};
|
|
49
46
|
}
|
package/lib/configs/index.js
CHANGED
|
@@ -14,5 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./install"), exports);
|
|
18
|
-
__exportStar(require("./package"), exports);
|
|
17
|
+
__exportStar(require("./install/index.js"), exports);
|
|
18
|
+
__exportStar(require("./package/index.js"), exports);
|
|
19
|
+
__exportStar(require("./uninstall/index.js"), exports);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateInstallConfig = exports.writeInstallConfig = exports.readInstallConfig = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "readInstallConfig", { enumerable: true, get: function () { return
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "writeInstallConfig", { enumerable: true, get: function () { return
|
|
8
|
-
var
|
|
9
|
-
Object.defineProperty(exports, "updateInstallConfig", { enumerable: true, get: function () { return
|
|
4
|
+
var read_install_config_js_1 = require("./read-install-config.js");
|
|
5
|
+
Object.defineProperty(exports, "readInstallConfig", { enumerable: true, get: function () { return read_install_config_js_1.readInstallConfig; } });
|
|
6
|
+
var write_install_config_js_1 = require("./write-install-config.js");
|
|
7
|
+
Object.defineProperty(exports, "writeInstallConfig", { enumerable: true, get: function () { return write_install_config_js_1.writeInstallConfig; } });
|
|
8
|
+
var update_install_config_js_1 = require("./update-install-config.js");
|
|
9
|
+
Object.defineProperty(exports, "updateInstallConfig", { enumerable: true, get: function () { return update_install_config_js_1.updateInstallConfig; } });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type AsyncDResult } from '@zokugun/xtry';
|
|
2
|
+
import { type InstallConfig, type InstallConfigStats } from '../../types/config.js';
|
|
3
|
+
export declare function readInstallConfig(targetPath: string): AsyncDResult<{
|
|
4
|
+
config: InstallConfig;
|
|
5
|
+
configStats: InstallConfigStats;
|
|
6
|
+
}>;
|
|
@@ -5,108 +5,155 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.readInstallConfig = readInstallConfig;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const
|
|
8
|
+
const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
|
|
9
|
+
const is_it_type_1 = require("@zokugun/is-it-type");
|
|
10
|
+
const xtry_1 = require("@zokugun/xtry");
|
|
9
11
|
const yaml_1 = __importDefault(require("yaml"));
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
name: '.artifactrc.yaml',
|
|
17
|
-
type: 'yaml',
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
name: '.artifactrc.json',
|
|
21
|
-
type: 'json',
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
name: '.artifactrc',
|
|
25
|
-
},
|
|
26
|
-
];
|
|
12
|
+
const detect_indent_js_1 = require("../../utils/detect-indent.js");
|
|
13
|
+
const has_final_new_line_js_1 = require("../../utils/has-final-new-line.js");
|
|
14
|
+
const constants_js_1 = require("../utils/constants.js");
|
|
15
|
+
const normalize_file_upsert_js_1 = require("../utils/normalize-file-upsert.js");
|
|
27
16
|
async function readInstallConfig(targetPath) {
|
|
28
17
|
let content;
|
|
29
18
|
let name;
|
|
30
19
|
let type;
|
|
31
|
-
for (const place of
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
type = place
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
20
|
+
for (const place of constants_js_1.CONFIG_LOCATIONS) {
|
|
21
|
+
const result = await async_1.default.readFile(path_1.default.join(targetPath, place.name), 'utf8');
|
|
22
|
+
if (!result.fails) {
|
|
23
|
+
content = result.value;
|
|
24
|
+
({ name, type } = place);
|
|
39
25
|
}
|
|
40
26
|
}
|
|
41
|
-
if (!content) {
|
|
42
|
-
return {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
},
|
|
48
|
-
configStats: {
|
|
49
|
-
name: '.artifactrc.yml',
|
|
50
|
-
type: 'yaml',
|
|
51
|
-
finalNewLine: true,
|
|
52
|
-
},
|
|
53
|
-
};
|
|
27
|
+
if (!content || !name) {
|
|
28
|
+
return normalizeConfig(content, {
|
|
29
|
+
name: '.artifactrc.yml',
|
|
30
|
+
type: 'yaml',
|
|
31
|
+
finalNewLine: true,
|
|
32
|
+
});
|
|
54
33
|
}
|
|
55
|
-
const finalNewLine =
|
|
56
|
-
|
|
34
|
+
const finalNewLine = (0, has_final_new_line_js_1.hasFinalNewLine)(content);
|
|
35
|
+
const indent = (0, detect_indent_js_1.detectIndent)(content);
|
|
57
36
|
if (type === 'json') {
|
|
58
|
-
|
|
37
|
+
return normalizeConfig(JSON.parse(content), {
|
|
38
|
+
name,
|
|
39
|
+
type: 'json',
|
|
40
|
+
finalNewLine,
|
|
41
|
+
indent,
|
|
42
|
+
});
|
|
59
43
|
}
|
|
60
44
|
else if (type === 'yaml') {
|
|
61
|
-
|
|
45
|
+
return normalizeConfig(yaml_1.default.parse(content), {
|
|
46
|
+
name,
|
|
47
|
+
type: 'yaml',
|
|
48
|
+
finalNewLine,
|
|
49
|
+
indent,
|
|
50
|
+
});
|
|
62
51
|
}
|
|
63
52
|
else {
|
|
64
53
|
try {
|
|
65
|
-
|
|
66
|
-
|
|
54
|
+
return normalizeConfig(JSON.parse(content), {
|
|
55
|
+
name,
|
|
56
|
+
type: 'json',
|
|
57
|
+
finalNewLine,
|
|
58
|
+
indent,
|
|
59
|
+
});
|
|
67
60
|
}
|
|
68
61
|
catch {
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
return normalizeConfig(yaml_1.default.parse(content), {
|
|
63
|
+
name,
|
|
64
|
+
type: 'yaml',
|
|
65
|
+
finalNewLine,
|
|
66
|
+
indent,
|
|
67
|
+
});
|
|
71
68
|
}
|
|
72
69
|
}
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
}
|
|
71
|
+
function normalizeConfig(data, configStats) {
|
|
72
|
+
const artifacts = {};
|
|
73
|
+
let constants = {};
|
|
74
|
+
const install = {};
|
|
75
|
+
let update = {};
|
|
76
|
+
let variables = {};
|
|
77
|
+
if (!data) {
|
|
78
|
+
return (0, xtry_1.ok)({
|
|
79
|
+
config: {
|
|
80
|
+
artifacts,
|
|
81
|
+
constants,
|
|
82
|
+
install,
|
|
83
|
+
update,
|
|
84
|
+
variables,
|
|
85
|
+
},
|
|
86
|
+
configStats,
|
|
87
|
+
});
|
|
75
88
|
}
|
|
76
|
-
if (
|
|
77
|
-
|
|
89
|
+
if (!(0, is_it_type_1.isRecord)(data)) {
|
|
90
|
+
return (0, xtry_1.err)(`Config file ${configStats.name} must export an object.`);
|
|
78
91
|
}
|
|
79
|
-
if (
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
version,
|
|
88
|
-
};
|
|
92
|
+
if ((0, is_it_type_1.isString)(data.$schema)) {
|
|
93
|
+
const match = constants_js_1.VERSION_INSTALL_REGEX.exec(data.$schema);
|
|
94
|
+
if (!match) {
|
|
95
|
+
return (0, xtry_1.err)(`Cannot validate the "$schema" in the project's "${configStats.name}".`);
|
|
96
|
+
}
|
|
97
|
+
const version = Number.parseInt(match[2], 10);
|
|
98
|
+
if (version > constants_js_1.MAX_VERSION) {
|
|
99
|
+
return (0, xtry_1.err)(`Don't support newer version (v${version}) in the project's "${configStats.name}".`);
|
|
89
100
|
}
|
|
90
|
-
return {
|
|
91
|
-
config,
|
|
92
|
-
configStats: {
|
|
93
|
-
name: name,
|
|
94
|
-
type,
|
|
95
|
-
finalNewLine,
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
101
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
102
|
+
if ((0, is_it_type_1.isArray)(data.artifacts)) {
|
|
103
|
+
for (const artifact of data.artifacts) {
|
|
104
|
+
if ((0, is_it_type_1.isRecord)(artifact) && (0, is_it_type_1.isString)(artifact.name) && (0, is_it_type_1.isString)(artifact.version)) {
|
|
105
|
+
const normalized = {
|
|
106
|
+
version: artifact.version,
|
|
107
|
+
};
|
|
108
|
+
if ((0, is_it_type_1.isString)(artifact.variant)) {
|
|
109
|
+
normalized.requires = [artifact.variant];
|
|
110
|
+
}
|
|
111
|
+
artifacts[artifact.name] = normalized;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
108
114
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
115
|
+
else if ((0, is_it_type_1.isRecord)(data.artifacts)) {
|
|
116
|
+
for (const [key, artifact] of Object.entries(data.artifacts)) {
|
|
117
|
+
if ((0, is_it_type_1.isRecord)(artifact) && (0, is_it_type_1.isString)(artifact.version)) {
|
|
118
|
+
const normalized = {
|
|
119
|
+
version: artifact.version,
|
|
120
|
+
};
|
|
121
|
+
if ((0, is_it_type_1.isArray)(artifact.requires, is_it_type_1.isString)) {
|
|
122
|
+
normalized.requires = artifact.requires;
|
|
123
|
+
}
|
|
124
|
+
else if ((0, is_it_type_1.isArray)(artifact.provides, is_it_type_1.isString)) {
|
|
125
|
+
normalized.requires = artifact.provides;
|
|
126
|
+
}
|
|
127
|
+
artifacts[key] = normalized;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if ((0, is_it_type_1.isRecord)(data.constants, (_key, value) => (0, is_it_type_1.isString)(value))) {
|
|
132
|
+
constants = data.constants;
|
|
133
|
+
}
|
|
134
|
+
if (data.update === false) {
|
|
135
|
+
update = false;
|
|
136
|
+
}
|
|
137
|
+
else if ((0, is_it_type_1.isRecord)(data.update)) {
|
|
138
|
+
for (const [key, value] of Object.entries(data.update)) {
|
|
139
|
+
const normalized = (0, normalize_file_upsert_js_1.normalizeFileUpsert)(key, value, 'update');
|
|
140
|
+
if (normalized.fails) {
|
|
141
|
+
return normalized;
|
|
142
|
+
}
|
|
143
|
+
update[key] = normalized.value;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if ((0, is_it_type_1.isRecord)(data.variables, (_key, value) => (0, is_it_type_1.isString)(value))) {
|
|
147
|
+
variables = data.variables;
|
|
148
|
+
}
|
|
149
|
+
return (0, xtry_1.ok)({
|
|
150
|
+
config: {
|
|
151
|
+
artifacts,
|
|
152
|
+
constants,
|
|
153
|
+
install,
|
|
154
|
+
update,
|
|
155
|
+
variables,
|
|
156
|
+
},
|
|
157
|
+
configStats,
|
|
158
|
+
});
|
|
112
159
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type AsyncDResult } from '@zokugun/xtry';
|
|
2
|
+
import { type InstallConfig, type InstallConfigStats } from '../../types/config.js';
|
|
3
|
+
import { type Options } from '../../types/context.js';
|
|
4
|
+
import { type Format } from '../../types/format.js';
|
|
5
|
+
export declare function writeInstallConfig(config: InstallConfig, { name, finalNewLine, indent, type }: InstallConfigStats, formats: Format[], targetPath: string, options: Options): AsyncDResult;
|
|
@@ -5,30 +5,45 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.writeInstallConfig = writeInstallConfig;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const cli_utils_1 = require("@zokugun/cli-utils");
|
|
9
|
+
const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
|
|
10
|
+
const is_it_type_1 = require("@zokugun/is-it-type");
|
|
11
|
+
const xtry_1 = require("@zokugun/xtry");
|
|
10
12
|
const yaml_1 = __importDefault(require("yaml"));
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
13
|
+
const apply_formatting_js_1 = require("../../steps/apply-formatting.js");
|
|
14
|
+
const insert_final_new_line_js_1 = require("../../steps/insert-final-new-line.js");
|
|
15
|
+
const constants_js_1 = require("../utils/constants.js");
|
|
16
|
+
async function writeInstallConfig(config, { name, finalNewLine, indent, type }, formats, targetPath, options) {
|
|
14
17
|
const exported = {
|
|
18
|
+
$schema: `https://raw.githubusercontent.com/zokugun/artifact/v${constants_js_1.VERSION_RELEASE}/schemas/v${constants_js_1.MAX_VERSION}/install.json`,
|
|
15
19
|
artifacts: config.artifacts,
|
|
16
20
|
};
|
|
17
|
-
if (
|
|
21
|
+
if ((0, is_it_type_1.isNonEmptyRecord)(config.update)) {
|
|
18
22
|
exported.update = config.update;
|
|
19
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
|
+
}
|
|
20
30
|
const file = {
|
|
21
31
|
name,
|
|
22
32
|
data: type === 'yaml' ? yaml_1.default.stringify(exported) : JSON.stringify(exported, null, '\t'),
|
|
33
|
+
indent,
|
|
23
34
|
finalNewLine,
|
|
24
35
|
};
|
|
25
|
-
await (0,
|
|
26
|
-
await (0,
|
|
36
|
+
await (0, insert_final_new_line_js_1.insertFinalNewLine)({ mergedTextFiles: [file] });
|
|
37
|
+
await (0, apply_formatting_js_1.applyFormatting)({ mergedTextFiles: [file], formats });
|
|
27
38
|
if (!options.dryRun) {
|
|
28
39
|
const filePath = path_1.default.join(targetPath, name);
|
|
29
|
-
await
|
|
40
|
+
const result = await async_1.default.outputFile(filePath, file.data, 'utf8');
|
|
41
|
+
if (result.fails) {
|
|
42
|
+
return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
|
|
43
|
+
}
|
|
30
44
|
}
|
|
31
45
|
if (options.verbose) {
|
|
32
|
-
|
|
46
|
+
cli_utils_1.logger.debug(`${name} has been written`);
|
|
33
47
|
}
|
|
48
|
+
return xtry_1.OK;
|
|
34
49
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { readPackageConfig } from './read-package-config.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.readPackageConfig = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "readPackageConfig", { enumerable: true, get: function () { return
|
|
4
|
+
var read_package_config_js_1 = require("./read-package-config.js");
|
|
5
|
+
Object.defineProperty(exports, "readPackageConfig", { enumerable: true, get: function () { return read_package_config_js_1.readPackageConfig; } });
|