diff --git a/cli/src/lib/generateManifests.js b/cli/src/lib/generateManifests.js index 212766e76..6ba6db624 100644 --- a/cli/src/lib/generateManifests.js +++ b/cli/src/lib/generateManifests.js @@ -1,6 +1,28 @@ const { reporter, chalk } = require('@dhis2/cli-helpers-engine') const fs = require('fs-extra') +/** + * Gets the original `entrypoints` property in d2.config.js + * without applying defaults. Used to detect if there is actually + * supposed to be an app entrypoint for this... app. Temporary until + * the build process is redesigned to allow building plugins without + * apps (LIBS-479) + */ +const getOriginalEntrypoints = (paths) => { + try { + if (fs.existsSync(paths.config)) { + reporter.debug('Loading d2 config at', paths.config) + // NB: this import can be confounded by previous object mutations + const originalConfig = require(paths.config) + reporter.debug('loaded', originalConfig) + return originalConfig.entryPoints // may be undefined + } + } catch (e) { + reporter.error('Failed to load d2 config!') + reporter.error(e) + process.exit(1) + } +} const parseCustomAuthorities = (authorities) => { if (!authorities) { return undefined @@ -93,11 +115,20 @@ module.exports = (paths, config, publicUrl) => { }, ], start_url: '.', - display: 'browser', + display: 'standalone', theme_color: '#ffffff', background_color: '#f4f6f8', } + const includesPlugin = Boolean(config.entryPoints.plugin) + // If there's a plugin, there might not be an app intended to be exposed, + // in which case omit the app launch path. Check the original d2.config + // without added defaults to see if an app is intended. + // If there's not a plugin, default to 'true' + const shouldIncludeAppLaunchPath = includesPlugin + ? Boolean(getOriginalEntrypoints(paths)?.app) + : true + // Legacy manifest const manifestWebapp = { app_hub_id: config.id, @@ -108,8 +139,8 @@ module.exports = (paths, config, publicUrl) => { version: config.version, core_app: config.coreApp, - launch_path: paths.launchPath, - plugin_launch_path: paths.pluginLaunchPath, + launch_path: shouldIncludeAppLaunchPath ? paths.launchPath : undefined, + plugin_launch_path: includesPlugin ? paths.pluginLaunchPath : undefined, default_locale: 'en', activities: { dhis: { @@ -148,8 +179,8 @@ module.exports = (paths, config, publicUrl) => { const appConfig = { ...config } delete appConfig['entryPoints'] appConfig.entryPoints = { - app: paths.launchPath, - plugin: config.entryPoints.plugin ? paths.pluginLaunchPath : undefined, + app: shouldIncludeAppLaunchPath ? paths.launchPath : undefined, + plugin: includesPlugin ? paths.pluginLaunchPath : undefined, } delete appConfig['pwa'] diff --git a/cli/src/lib/parseConfig.js b/cli/src/lib/parseConfig.js index 9d5f7c5cf..72cf0de6f 100644 --- a/cli/src/lib/parseConfig.js +++ b/cli/src/lib/parseConfig.js @@ -1,6 +1,6 @@ const { reporter, chalk } = require('@dhis2/cli-helpers-engine') const fs = require('fs-extra') -const { defaultsDeep, has, isPlainObject } = require('lodash') +const { defaultsDeep, cloneDeep, has, isPlainObject } = require('lodash') const parseAuthorString = require('parse-author') const requiredConfigFields = { @@ -83,7 +83,10 @@ const parseConfig = (paths) => { if (fs.existsSync(paths.config)) { reporter.debug('Loading d2 config at', paths.config) - config = require(paths.config) + const importedConfig = require(paths.config) + // Make sure not to overwrite imported object + // (need to use it later in generateManifest) + config = cloneDeep(importedConfig) reporter.debug('loaded', config) } if (fs.existsSync(paths.package)) {