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