|
| 1 | +/** |
| 2 | + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +const path = require('node:path') |
| 7 | +const fs = require('node:fs') |
| 8 | +const defaultConfig = require('./config.json') |
| 9 | + |
| 10 | +/** |
| 11 | + * Resolve the build configuration |
| 12 | + * |
| 13 | + * @param {string} [customConfigPath] - Path to the custom configuration file |
| 14 | + * @return {import('./BuildConfig.types.ts').BuildConfig} - Resolved configuration object |
| 15 | + */ |
| 16 | +function resolveBuildConfig(customConfigPath = process.env.CUSTOM_CONFIG) { |
| 17 | + /** @type {Partial<import('./BuildConfig.types.ts').BuildConfigFile>} */ |
| 18 | + const customConfig = customConfigPath ? JSON.parse(fs.readFileSync(customConfigPath, 'utf-8')) : {} |
| 19 | + |
| 20 | + // Remove all undefined values |
| 21 | + // TODO: check if undefiend values can be empty strings or only null |
| 22 | + for (const key in customConfig) { |
| 23 | + if (customConfig[key] === null) { |
| 24 | + delete customConfig[key] |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + /** @type {import('./BuildConfig.types.ts').BuildConfigFile} */ |
| 29 | + const config = { |
| 30 | + ...defaultConfig, |
| 31 | + ...customConfig, |
| 32 | + } |
| 33 | + |
| 34 | + // Sanitized name - application name without non-alphanumeral characters |
| 35 | + const applicationNameSanitized = config.applicationName.replace(/[^a-z0-9]/gi, '') |
| 36 | + |
| 37 | + // Generate appId in DNS notation from domain |
| 38 | + const appIdHost = config.domain |
| 39 | + ? new URL(config.domain).host.split('.').reverse().join('.') |
| 40 | + : 'com.nextcloud' |
| 41 | + |
| 42 | + return { |
| 43 | + // Default inferred values - can be overridden by the custom config |
| 44 | + appleAppBundleId: `${appIdHost}.talk.mac`, |
| 45 | + linuxAppId: `${appIdHost}.talk`, |
| 46 | + winAppId: `${appIdHost}.talk`, |
| 47 | + description: `Official desktop client for ${config.applicationName}`, |
| 48 | + |
| 49 | + // Custom config with defaults |
| 50 | + ...config, |
| 51 | + |
| 52 | + // Inferred values, cannot be overridden by the custom config |
| 53 | + isBranded: Boolean(customConfigPath), |
| 54 | + companyName: 'Nextcloud GmbH', |
| 55 | + copyright: 'Copyright (c) {year} Nextcloud GmbH'.replace('{year}', new Date().getFullYear()), |
| 56 | + applicationNameSanitized, |
| 57 | + winSquirrelAppId: applicationNameSanitized, // Special case for Squirrel.Windows |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +module.exports = { |
| 62 | + resolveConfig: resolveBuildConfig, |
| 63 | +} |
0 commit comments