Skip to content

Commit

Permalink
fix: use isApp function
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzemp committed Sep 12, 2023
1 parent f6abdd0 commit 0df2188
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 19 deletions.
10 changes: 5 additions & 5 deletions cli/src/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 })
}
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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'
Expand Down
12 changes: 6 additions & 6 deletions cli/src/lib/compiler/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down Expand Up @@ -128,7 +128,7 @@ const compile = async ({
processFileCallback: compileFile,
watch,
}),
isApp &&
isAppType &&
watchFiles({
inputDir: paths.public,
outputDir: paths.shellPublic,
Expand Down
4 changes: 2 additions & 2 deletions cli/src/lib/compiler/entrypoints.js
Original file line number Diff line number Diff line change
@@ -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 }) => {
Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions cli/src/lib/parseConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const requiredConfigFields = {

const appTypes = ['app', 'login_app']

const isApp = (type) => appTypes.includes(type)

const parseAuthor = (author) => {
if (isPlainObject(author)) {
return {
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -114,4 +116,4 @@ module.exports = parseConfig
module.exports.parseConfigObjects = parseConfigObjects

module.exports.parseConfigObjects = parseConfigObjects
module.exports.appTypes = appTypes
module.exports.isApp = isApp
4 changes: 2 additions & 2 deletions cli/src/lib/pwa/getPWAEnvVars.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0df2188

Please sign in to comment.