From 0df2188d6c0dce80fba9237690eb7249f5cbd485 Mon Sep 17 00:00:00 2001 From: Thomas Zemp Date: Tue, 12 Sep 2023 14:17:48 +0200 Subject: [PATCH] fix: use isApp function --- cli/src/commands/build.js | 10 +++++----- cli/src/commands/start.js | 4 ++-- cli/src/lib/compiler/compile.js | 12 ++++++------ cli/src/lib/compiler/entrypoints.js | 4 ++-- cli/src/lib/parseConfig.js | 6 ++++-- cli/src/lib/pwa/getPWAEnvVars.js | 4 ++-- 6 files changed, 21 insertions(+), 19 deletions(-) diff --git a/cli/src/commands/build.js b/cli/src/commands/build.js index 313d881b5..609140076 100644 --- a/cli/src/commands/build.js +++ b/cli/src/commands/build.js @@ -7,7 +7,7 @@ const generateManifests = require('../lib/generateManifests') const i18n = require('../lib/i18n') const loadEnvFiles = require('../lib/loadEnvFiles') const parseConfig = require('../lib/parseConfig') -const { appTypes } = require('../lib/parseConfig') +const { isApp } = require('../lib/parseConfig') const makePaths = require('../lib/paths') const makePlugin = require('../lib/plugin') const { injectPrecacheManifest } = require('../lib/pwa') @@ -71,7 +71,7 @@ const handler = async ({ const shell = makeShell({ config, paths }) const plugin = makePlugin({ config, paths }) - if (appTypes.includes(config.type)) { + if (isApp(config.type)) { setAppParameters(standalone, config) } @@ -106,7 +106,7 @@ const handler = async ({ paths, }) - if (appTypes.includes(config.type)) { + if (isApp(config.type)) { reporter.info('Bootstrapping local appShell...') await shell.bootstrap({ shell: shellSource, force }) } @@ -115,7 +115,7 @@ const handler = async ({ `Building ${config.type} ${chalk.bold(config.name)}...` ) - if (appTypes.includes(config.type)) { + if (isApp(config.type)) { await compile({ config, paths, @@ -168,7 +168,7 @@ const handler = async ({ } ) - if (appTypes.includes(config.type)) { + if (isApp(config.type)) { if (!fs.pathExistsSync(paths.shellBuildOutput)) { reporter.error('No build output found') process.exit(1) diff --git a/cli/src/commands/start.js b/cli/src/commands/start.js index 501309498..c08cd3440 100644 --- a/cli/src/commands/start.js +++ b/cli/src/commands/start.js @@ -6,7 +6,7 @@ const generateManifests = require('../lib/generateManifests') const i18n = require('../lib/i18n') const loadEnvFiles = require('../lib/loadEnvFiles') const parseConfig = require('../lib/parseConfig') -const { appTypes } = require('../lib/parseConfig') +const { isApp } = require('../lib/parseConfig') const makePaths = require('../lib/paths') const makePlugin = require('../lib/plugin') const createProxyServer = require('../lib/proxy') @@ -33,7 +33,7 @@ const handler = async ({ const shell = makeShell({ config, paths }) const plugin = makePlugin({ config, paths }) - if (!appTypes.includes(config.type)) { + if (!isApp(config.type)) { reporter.error( `The command ${chalk.bold( 'd2-app-scripts start' diff --git a/cli/src/lib/compiler/compile.js b/cli/src/lib/compiler/compile.js index 213a47358..94842eae1 100644 --- a/cli/src/lib/compiler/compile.js +++ b/cli/src/lib/compiler/compile.js @@ -4,7 +4,7 @@ const { reporter, prettyPrint } = require('@dhis2/cli-helpers-engine') const chokidar = require('chokidar') const fs = require('fs-extra') const makeBabelConfig = require('../../../config/makeBabelConfig.js') -const { appTypes } = require('../parseConfig') +const { isApp } = require('../parseConfig') const { verifyEntrypoints, createAppEntrypointWrapper, @@ -68,10 +68,10 @@ const compile = async ({ mode = 'development', watch = false, }) => { - const isApp = appTypes.includes(config.type) + const isAppType = isApp(config.type) verifyEntrypoints({ config, paths }) - if (isApp) { + if (isAppType) { await createAppEntrypointWrapper({ entrypoint: config.entryPoints.app, paths, @@ -84,13 +84,13 @@ const compile = async ({ } } - const outDir = isApp + const outDir = isAppType ? paths.shellApp : path.join(paths.buildOutput, moduleType) fs.removeSync(outDir) fs.ensureDirSync(outDir) - if (isApp) { + if (isAppType) { fs.removeSync(paths.shellPublic) fs.copySync(paths.shellSourcePublic, paths.shellPublic) } @@ -128,7 +128,7 @@ const compile = async ({ processFileCallback: compileFile, watch, }), - isApp && + isAppType && watchFiles({ inputDir: paths.public, outputDir: paths.shellPublic, diff --git a/cli/src/lib/compiler/entrypoints.js b/cli/src/lib/compiler/entrypoints.js index e0d9377d9..943d548b0 100644 --- a/cli/src/lib/compiler/entrypoints.js +++ b/cli/src/lib/compiler/entrypoints.js @@ -1,7 +1,7 @@ const path = require('path') const { reporter, chalk } = require('@dhis2/cli-helpers-engine') const fs = require('fs-extra') -const { appTypes } = require('../parseConfig') +const { isApp } = require('../parseConfig') const { normalizeExtension } = require('./extensionHelpers.js') const verifyEntrypoint = ({ entrypoint, basePath, resolveModule }) => { @@ -27,7 +27,7 @@ exports.verifyEntrypoints = ({ paths, resolveModule = require.resolve, }) => { - if (appTypes.includes(config.type)) { + if (isApp(config.type)) { if ( !config.entryPoints || (!config.entryPoints.app && !config.entryPoints.plugin) diff --git a/cli/src/lib/parseConfig.js b/cli/src/lib/parseConfig.js index cb93b01e7..a154554b9 100644 --- a/cli/src/lib/parseConfig.js +++ b/cli/src/lib/parseConfig.js @@ -11,6 +11,8 @@ const requiredConfigFields = { const appTypes = ['app', 'login_app'] +const isApp = (type) => appTypes.includes(type) + const parseAuthor = (author) => { if (isPlainObject(author)) { return { @@ -61,7 +63,7 @@ const parseConfigObjects = ( config = defaultsDeep(config, defaults) // Add PWA defaults to apps - if (appTypes.includes(type)) { + if (isApp(type)) { config = defaultsDeep(config, defaultsPWA) } @@ -114,4 +116,4 @@ module.exports = parseConfig module.exports.parseConfigObjects = parseConfigObjects module.exports.parseConfigObjects = parseConfigObjects -module.exports.appTypes = appTypes +module.exports.isApp = isApp diff --git a/cli/src/lib/pwa/getPWAEnvVars.js b/cli/src/lib/pwa/getPWAEnvVars.js index f7577c601..eb6e39a03 100644 --- a/cli/src/lib/pwa/getPWAEnvVars.js +++ b/cli/src/lib/pwa/getPWAEnvVars.js @@ -1,4 +1,4 @@ -const { appTypes } = require('../parseConfig') +const { isApp } = require('../parseConfig') /** Preps string literals for regex conversion by escaping special chars */ function escapeForRegex(string) { @@ -33,7 +33,7 @@ function stringifyPatterns(patternsList) { * @param {Object} config */ function getPWAEnvVars(config) { - if (!appTypes.includes(config.type) || !config.pwa.enabled) { + if (!isApp(config.type) || !config.pwa.enabled) { return null } return {