1
1
const path = require ( 'path' )
2
2
const { reporter, chalk } = require ( '@dhis2/cli-helpers-engine' )
3
3
const fs = require ( 'fs-extra' )
4
+ const bootstrapShell = require ( '../lib/bootstrapShell' )
4
5
const { compile } = require ( '../lib/compiler' )
6
+ const { loadEnvFiles, getEnv } = require ( '../lib/env' )
5
7
const exitOnCatch = require ( '../lib/exitOnCatch' )
6
8
const generateManifests = require ( '../lib/generateManifests' )
7
9
const i18n = require ( '../lib/i18n' )
8
- const loadEnvFiles = require ( '../lib/loadEnvFiles' )
9
10
const parseConfig = require ( '../lib/parseConfig' )
10
11
const { isApp } = require ( '../lib/parseConfig' )
11
12
const makePaths = require ( '../lib/paths' )
12
13
const { injectPrecacheManifest, compileServiceWorker } = require ( '../lib/pwa' )
13
- const makeShell = require ( '../lib/shell' )
14
14
const { validatePackage } = require ( '../lib/validatePackage' )
15
15
const { handler : pack } = require ( './pack.js' )
16
16
@@ -30,20 +30,22 @@ const getNodeEnv = () => {
30
30
const printBuildParam = ( key , value ) => {
31
31
reporter . print ( chalk . green ( ` - ${ key } :` ) , chalk . yellow ( value ) )
32
32
}
33
- const setAppParameters = ( standalone , config ) => {
34
- process . env . PUBLIC_URL = process . env . PUBLIC_URL || '.'
35
- printBuildParam ( 'PUBLIC_URL' , process . env . PUBLIC_URL )
33
+ const getAppParameters = ( standalone , config ) => {
34
+ const publicUrl = process . env . PUBLIC_URL || '.'
35
+ printBuildParam ( 'PUBLIC_URL' , publicUrl )
36
36
37
37
if (
38
38
standalone === false ||
39
39
( typeof standalone === 'undefined' && ! config . standalone )
40
40
) {
41
41
const defaultBase = config . coreApp ? `..` : `../../..`
42
- process . env . DHIS2_BASE_URL = process . env . DHIS2_BASE_URL || defaultBase
42
+ const baseUrl = process . env . DHIS2_BASE_URL || defaultBase
43
43
44
- printBuildParam ( 'DHIS2_BASE_URL' , process . env . DHIS2_BASE_URL )
44
+ printBuildParam ( 'DHIS2_BASE_URL' , baseUrl )
45
+ return { publicUrl, baseUrl }
45
46
} else {
46
47
printBuildParam ( 'DHIS2_BASE_URL' , '<standalone>' )
48
+ return { publicUrl }
47
49
}
48
50
}
49
51
@@ -68,11 +70,9 @@ const handler = async ({
68
70
printBuildParam ( 'Mode' , mode )
69
71
70
72
const config = parseConfig ( paths )
71
- const shell = makeShell ( { config, paths } )
72
-
73
- if ( isApp ( config . type ) ) {
74
- setAppParameters ( standalone , config )
75
- }
73
+ const appParameters = isApp ( config . type )
74
+ ? getAppParameters ( standalone , config )
75
+ : null
76
76
77
77
await fs . remove ( paths . buildOutput )
78
78
@@ -107,7 +107,7 @@ const handler = async ({
107
107
108
108
if ( isApp ( config . type ) ) {
109
109
reporter . info ( 'Bootstrapping local appShell...' )
110
- await shell . bootstrap ( { shell : shellSource , force } )
110
+ await bootstrapShell ( { paths , shell : shellSource , force } )
111
111
}
112
112
113
113
reporter . info (
@@ -135,16 +135,13 @@ const handler = async ({
135
135
const { default : createConfig } = await import (
136
136
'../../config/makeViteConfig.mjs'
137
137
)
138
- const viteConfig = createConfig ( {
139
- paths,
140
- config,
141
- env : shell . env ,
142
- } )
138
+ const env = getEnv ( { config, ...appParameters } )
139
+ const viteConfig = createConfig ( { paths, config, env } )
143
140
await build ( viteConfig )
144
141
145
142
if ( config . pwa . enabled ) {
146
143
reporter . info ( 'Compiling service worker...' )
147
- await compileServiceWorker ( { config , paths, mode } )
144
+ await compileServiceWorker ( { env , paths, mode } )
148
145
149
146
reporter . info (
150
147
'Injecting supplementary precache manifest...'
0 commit comments