1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.computeDefaultAppDirectory = exports.validateConfig = exports.getConfig = void 0;
|
7 |
|
8 | function _bluebirdLst() {
|
9 | const data = require("bluebird-lst");
|
10 |
|
11 | _bluebirdLst = function () {
|
12 | return data;
|
13 | };
|
14 |
|
15 | return data;
|
16 | }
|
17 |
|
18 | function _builderUtil() {
|
19 | const data = require("builder-util");
|
20 |
|
21 | _builderUtil = function () {
|
22 | return data;
|
23 | };
|
24 |
|
25 | return data;
|
26 | }
|
27 |
|
28 | function _fs() {
|
29 | const data = require("builder-util/out/fs");
|
30 |
|
31 | _fs = function () {
|
32 | return data;
|
33 | };
|
34 |
|
35 | return data;
|
36 | }
|
37 |
|
38 | function _fsExtraP() {
|
39 | const data = require("fs-extra-p");
|
40 |
|
41 | _fsExtraP = function () {
|
42 | return data;
|
43 | };
|
44 |
|
45 | return data;
|
46 | }
|
47 |
|
48 | function _lazyVal() {
|
49 | const data = require("lazy-val");
|
50 |
|
51 | _lazyVal = function () {
|
52 | return data;
|
53 | };
|
54 |
|
55 | return data;
|
56 | }
|
57 |
|
58 | var path = _interopRequireWildcard(require("path"));
|
59 |
|
60 | function _readConfigFile() {
|
61 | const data = require("read-config-file");
|
62 |
|
63 | _readConfigFile = function () {
|
64 | return data;
|
65 | };
|
66 |
|
67 | return data;
|
68 | }
|
69 |
|
70 | function _rectCra() {
|
71 | const data = require("../presets/rectCra");
|
72 |
|
73 | _rectCra = function () {
|
74 | return data;
|
75 | };
|
76 |
|
77 | return data;
|
78 | }
|
79 |
|
80 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
81 |
|
82 |
|
83 | function mergePublish(config, configFromOptions) {
|
84 |
|
85 | const publish = Array.isArray(config.publish) ? configFromOptions.publish : null;
|
86 |
|
87 | if (publish != null) {
|
88 | delete configFromOptions.publish;
|
89 | }
|
90 |
|
91 | (0, _builderUtil().deepAssign)(config, configFromOptions);
|
92 |
|
93 | if (publish == null) {
|
94 | return;
|
95 | }
|
96 |
|
97 | const listOnDisk = config.publish;
|
98 |
|
99 | if (listOnDisk.length === 0) {
|
100 | config.publish = publish;
|
101 | } else {
|
102 |
|
103 | Object.assign(listOnDisk[0], publish);
|
104 | }
|
105 | }
|
106 |
|
107 | let getConfig = (() => {
|
108 | var _ref = (0, _bluebirdLst().coroutine)(function* (projectDir, configPath, configFromOptions, packageMetadata = new (_lazyVal().Lazy)(() => (0, _readConfigFile().orNullIfFileNotExist)((0, _fsExtraP().readJson)(path.join(projectDir, "package.json"))))) {
|
109 | const configRequest = {
|
110 | packageKey: "build",
|
111 | configFilename: "electron-builder",
|
112 | projectDir,
|
113 | packageMetadata
|
114 | };
|
115 | const configAndEffectiveFile = yield (0, _readConfigFile().getConfig)(configRequest, configPath);
|
116 | const config = configAndEffectiveFile == null ? {} : configAndEffectiveFile.result;
|
117 |
|
118 | if (configFromOptions != null) {
|
119 | mergePublish(config, configFromOptions);
|
120 | }
|
121 |
|
122 | if (configAndEffectiveFile != null) {
|
123 | _builderUtil().log.info({
|
124 | file: configAndEffectiveFile.configFile == null ? 'package.json ("build" field)' : configAndEffectiveFile.configFile
|
125 | }, "loaded configuration");
|
126 | }
|
127 |
|
128 | let extendsSpec = config.extends;
|
129 |
|
130 | if (extendsSpec == null && extendsSpec !== null) {
|
131 | const metadata = (yield packageMetadata.value) || {};
|
132 | const devDependencies = metadata.devDependencies;
|
133 | const dependencies = metadata.dependencies;
|
134 |
|
135 | if (dependencies != null && "react-scripts" in dependencies || devDependencies != null && "react-scripts" in devDependencies) {
|
136 | extendsSpec = "react-cra";
|
137 | config.extends = extendsSpec;
|
138 | } else if (devDependencies != null && "electron-webpack" in devDependencies) {
|
139 | extendsSpec = "electron-webpack/electron-builder.yml";
|
140 | config.extends = extendsSpec;
|
141 | }
|
142 | }
|
143 |
|
144 | if (extendsSpec == null) {
|
145 | return (0, _builderUtil().deepAssign)(getDefaultConfig(), config);
|
146 | }
|
147 |
|
148 | let parentConfig;
|
149 |
|
150 | if (extendsSpec === "react-cra") {
|
151 | parentConfig = yield (0, _rectCra().reactCra)(projectDir);
|
152 |
|
153 | _builderUtil().log.info({
|
154 | preset: extendsSpec
|
155 | }, "loaded parent configuration");
|
156 | } else {
|
157 | const parentConfigAndEffectiveFile = yield (0, _readConfigFile().loadParentConfig)(configRequest, extendsSpec);
|
158 |
|
159 | _builderUtil().log.info({
|
160 | file: parentConfigAndEffectiveFile.configFile
|
161 | }, "loaded parent configuration");
|
162 |
|
163 | parentConfig = parentConfigAndEffectiveFile.result;
|
164 | }
|
165 |
|
166 |
|
167 |
|
168 | if (parentConfig.files != null && config.files != null && (Array.isArray(config.files) || typeof config.files === "string") && Array.isArray(parentConfig.files) && parentConfig.files.length > 0) {
|
169 | const mainFileSet = parentConfig.files[0];
|
170 |
|
171 | if (typeof mainFileSet === "object" && (mainFileSet.from == null || mainFileSet.from === ".")) {
|
172 | mainFileSet.filter = (0, _builderUtil().asArray)(mainFileSet.filter);
|
173 | mainFileSet.filter.push(...(0, _builderUtil().asArray)(config.files));
|
174 | delete config.files;
|
175 | }
|
176 | }
|
177 |
|
178 | return (0, _builderUtil().deepAssign)(getDefaultConfig(), parentConfig, config);
|
179 | });
|
180 |
|
181 | return function getConfig(_x, _x2, _x3) {
|
182 | return _ref.apply(this, arguments);
|
183 | };
|
184 | })();
|
185 |
|
186 | exports.getConfig = getConfig;
|
187 |
|
188 | function getDefaultConfig() {
|
189 | return {
|
190 | directories: {
|
191 | output: "dist",
|
192 | buildResources: "build"
|
193 | }
|
194 | };
|
195 | }
|
196 |
|
197 | const schemeDataPromise = new (_lazyVal().Lazy)(() => (0, _fsExtraP().readJson)(path.join(__dirname, "..", "..", "scheme.json")));
|
198 |
|
199 | let validateConfig = (() => {
|
200 | var _ref2 = (0, _bluebirdLst().coroutine)(function* (config, debugLogger) {
|
201 | const extraMetadata = config.extraMetadata;
|
202 |
|
203 | if (extraMetadata != null) {
|
204 | if (extraMetadata.build != null) {
|
205 | throw new (_builderUtil().InvalidConfigurationError)(`--em.build is deprecated, please specify as -c"`);
|
206 | }
|
207 |
|
208 | if (extraMetadata.directories != null) {
|
209 | throw new (_builderUtil().InvalidConfigurationError)(`--em.directories is deprecated, please specify as -c.directories"`);
|
210 | }
|
211 | }
|
212 |
|
213 |
|
214 | if (config.npmSkipBuildFromSource === false) {
|
215 | config.buildDependenciesFromSource = false;
|
216 | }
|
217 |
|
218 | yield (0, _readConfigFile().validateConfig)(config, schemeDataPromise, (message, errors) => {
|
219 | if (debugLogger.isEnabled) {
|
220 | debugLogger.add("invalidConfig", JSON.stringify(errors, null, 2));
|
221 | }
|
222 |
|
223 | return `${message}
|
224 |
|
225 | How to fix:
|
226 | 1. Open https://electron.build/configuration/configuration
|
227 | 2. Search the option name on the page.
|
228 | * Not found? The option was deprecated or not exists (check spelling).
|
229 | * Found? Check that the option in the appropriate place. e.g. "title" only in the "dmg", not in the root.
|
230 | `;
|
231 | });
|
232 | });
|
233 |
|
234 | return function validateConfig(_x4, _x5) {
|
235 | return _ref2.apply(this, arguments);
|
236 | };
|
237 | })();
|
238 |
|
239 | exports.validateConfig = validateConfig;
|
240 | const DEFAULT_APP_DIR_NAMES = ["app", "www"];
|
241 |
|
242 | let computeDefaultAppDirectory = (() => {
|
243 | var _ref3 = (0, _bluebirdLst().coroutine)(function* (projectDir, userAppDir) {
|
244 | if (userAppDir != null) {
|
245 | const absolutePath = path.resolve(projectDir, userAppDir);
|
246 | const stat = yield (0, _fs().statOrNull)(absolutePath);
|
247 |
|
248 | if (stat == null) {
|
249 | throw new (_builderUtil().InvalidConfigurationError)(`Application directory ${userAppDir} doesn't exists`);
|
250 | } else if (!stat.isDirectory()) {
|
251 | throw new (_builderUtil().InvalidConfigurationError)(`Application directory ${userAppDir} is not a directory`);
|
252 | } else if (projectDir === absolutePath) {
|
253 | _builderUtil().log.warn({
|
254 | appDirectory: userAppDir
|
255 | }, `Specified application directory equals to project dir — superfluous or wrong configuration`);
|
256 | }
|
257 |
|
258 | return absolutePath;
|
259 | }
|
260 |
|
261 | for (const dir of DEFAULT_APP_DIR_NAMES) {
|
262 | const absolutePath = path.join(projectDir, dir);
|
263 | const packageJson = path.join(absolutePath, "package.json");
|
264 | const stat = yield (0, _fs().statOrNull)(packageJson);
|
265 |
|
266 | if (stat != null && stat.isFile()) {
|
267 | return absolutePath;
|
268 | }
|
269 | }
|
270 |
|
271 | return projectDir;
|
272 | });
|
273 |
|
274 | return function computeDefaultAppDirectory(_x6, _x7) {
|
275 | return _ref3.apply(this, arguments);
|
276 | };
|
277 | })(); exports.computeDefaultAppDirectory = computeDefaultAppDirectory;
|
278 |
|
\ | No newline at end of file |