1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const cosmiconfig_1 = require("cosmiconfig");
|
5 | const deepmerge_1 = tslib_1.__importDefault(require("deepmerge"));
|
6 | const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
|
7 | const path = tslib_1.__importStar(require("path"));
|
8 | const release_1 = require("./release");
|
9 | const try_require_1 = tslib_1.__importDefault(require("./utils/try-require"));
|
10 | const endent_1 = tslib_1.__importDefault(require("endent"));
|
11 |
|
12 | function normalizeLabel(label) {
|
13 | const baseLabel = release_1.defaultLabels.find((l) => {
|
14 | let isBase = false;
|
15 | if (label.releaseType !== "none") {
|
16 | isBase = l.releaseType === label.releaseType;
|
17 | }
|
18 | return isBase || (label.name && l.name === label.name);
|
19 | }) || {};
|
20 | return Object.assign(Object.assign({}, baseLabel), label);
|
21 | }
|
22 | exports.normalizeLabel = normalizeLabel;
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | function normalizeLabels(config) {
|
28 | if (config.labels) {
|
29 | const userLabels = config.labels.map(normalizeLabel);
|
30 | const baseLabels = release_1.defaultLabels.filter((d) => !userLabels.some((u) => u.releaseType && u.releaseType === d.releaseType && u.overwrite));
|
31 | return [...userLabels, ...baseLabels];
|
32 | }
|
33 | return release_1.defaultLabels;
|
34 | }
|
35 | exports.normalizeLabels = normalizeLabels;
|
36 |
|
37 | class Config {
|
38 |
|
39 | constructor(logger) {
|
40 | this.logger = logger;
|
41 | }
|
42 | |
43 |
|
44 |
|
45 |
|
46 | async loadConfig() {
|
47 | const explorer = cosmiconfig_1.cosmiconfig("auto");
|
48 | const result = await explorer.search();
|
49 | let rawConfig = {};
|
50 | if (result === null || result === void 0 ? void 0 : result.config) {
|
51 | rawConfig = result.config;
|
52 | }
|
53 | if (rawConfig.extends) {
|
54 | rawConfig = deepmerge_1.default(rawConfig, await this.loadExtendConfig(rawConfig.extends));
|
55 | }
|
56 | this.checkDeprecated(rawConfig);
|
57 | const labels = normalizeLabels(rawConfig);
|
58 | const semVerLabels = release_1.getVersionMap(labels);
|
59 | this.logger.verbose.success("Using SEMVER labels:", "\n", semVerLabels);
|
60 | return Object.assign(Object.assign({}, rawConfig), { labels, prereleaseBranches: rawConfig.prereleaseBranches || ["next"], versionBranches: typeof rawConfig.versionBranches === "boolean"
|
61 | ? "version-"
|
62 | : rawConfig.versionBranches });
|
63 | }
|
64 | |
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | async loadExtendConfig(extend) {
|
73 | var _a;
|
74 | let config;
|
75 | if (extend.endsWith(".js") || extend.endsWith(".mjs")) {
|
76 | throw new Error("Extended config cannot be a JavaScript file");
|
77 | }
|
78 | if (extend.startsWith("http")) {
|
79 | try {
|
80 | config = (await node_fetch_1.default(extend)).json();
|
81 | this.logger.verbose.note(`${extend} found: ${config}`);
|
82 | }
|
83 | catch (error) {
|
84 | error.message = `Failed to get extended config from ${extend} -- ${error.message}`;
|
85 | throw error;
|
86 | }
|
87 | }
|
88 | else if (extend.startsWith(".")) {
|
89 | config = try_require_1.default(extend);
|
90 | if (extend.endsWith("package.json")) {
|
91 | config = config === null || config === void 0 ? void 0 : config.auto;
|
92 | }
|
93 | this.logger.verbose.note(`${extend} found: ${config}`);
|
94 | }
|
95 | else {
|
96 | config = (_a = try_require_1.default(`${extend}/package.json`)) === null || _a === void 0 ? void 0 : _a.auto;
|
97 | this.logger.verbose.note(`${extend} found: ${config}`);
|
98 | }
|
99 | if (!config) {
|
100 | const scope = `${extend}/auto-config/package.json`;
|
101 | config = try_require_1.default(scope);
|
102 | config = config === null || config === void 0 ? void 0 : config.auto;
|
103 | this.logger.verbose.note(`${scope} found: ${config}`);
|
104 | if (config) {
|
105 | config.extends = scope;
|
106 | }
|
107 | }
|
108 | if (!config) {
|
109 | const scope = `auto-config-${extend}/package.json`;
|
110 | config = try_require_1.default(scope);
|
111 | config = config === null || config === void 0 ? void 0 : config.auto;
|
112 | this.logger.verbose.note(`${scope} found: ${config}`);
|
113 | if (config) {
|
114 | config.extends = scope;
|
115 | }
|
116 | }
|
117 | if (!config) {
|
118 | const localPath = path.join(process.cwd(), extend);
|
119 | config = try_require_1.default(localPath);
|
120 | if (config) {
|
121 | config.extends = localPath;
|
122 | }
|
123 | }
|
124 | if (!config) {
|
125 | throw new Error(`Unable to load extended config ${extend}`);
|
126 | }
|
127 | return config;
|
128 | }
|
129 |
|
130 |
|
131 | checkDeprecated(config) {
|
132 | if (config.labels && !Array.isArray(config.labels)) {
|
133 | this.logger.log.error(endent_1.default `
|
134 | You're using a deprecated configuration option!
|
135 |
|
136 | The "labels" option no longer supports configuration with an object.
|
137 | Instead supply your labels as an array of label objects.
|
138 |
|
139 | ex:
|
140 |
|
141 | | {
|
142 | | "labels": [
|
143 | | {
|
144 | | "name": "my-label",
|
145 | | "description": "Really big stuff",
|
146 | | "type": "major"
|
147 | | }
|
148 | | ]
|
149 | | }
|
150 | `);
|
151 | process.exit(1);
|
152 | }
|
153 | if (config.skipReleaseLabels) {
|
154 | this.logger.log.error(endent_1.default `
|
155 | You're using a deprecated configuration option!
|
156 |
|
157 | The "skipReleaseLabels" option no longer exists.
|
158 | Instead set "type" to "skip" in your label configuration.
|
159 |
|
160 | ex:
|
161 |
|
162 | | {
|
163 | | "labels": [
|
164 | | {
|
165 | | "name": "my-label",
|
166 | | "description": "Really big stuff",
|
167 | | "type": "skip"
|
168 | | }
|
169 | | ]
|
170 | | }
|
171 | `);
|
172 | process.exit(1);
|
173 | }
|
174 | }
|
175 | }
|
176 | exports.default = Config;
|
177 |
|
\ | No newline at end of file |