@@ -26,19 +26,26 @@ function hasPackageJson(dir) {
26
26
}
27
27
28
28
async function packageManagerPack ( dir , destinationDir ) {
29
- const resultFilename = path . join ( destinationDir , `${ path . basename ( dir ) } .tgz` ) ;
30
- const packageJsonPath = path . join ( dir , 'package.json' ) ;
29
+ const component = path . basename ( dir ) ;
30
+ const resultFilename = path . join ( destinationDir , `${ component } .tgz` ) ;
31
+ const isWeb = component === 'web' ;
32
+ const appDir = isWeb ? dir . replace ( 'web' , 'app' ) : dir ;
33
+
34
+ const packageJsonPath = path . join ( appDir , 'package.json' ) ;
31
35
32
36
const originalFileContent = await fs . readFile ( packageJsonPath ) ;
33
37
const packageJson = await readJsonFile ( packageJsonPath ) ;
34
38
35
39
const timestamp = new Date ( ) . getTime ( ) ;
36
40
packageJson . version = `${ packageJson . version } -build${ timestamp } ` ;
41
+ packageJson . dependencies = isWeb
42
+ ? packageJson . webDependencies
43
+ : packageJson . dependencies ;
37
44
38
45
await writeJsonFile ( packageJson , packageJsonPath ) ;
39
- const { stdout } = await exec ( `${ packageManager } pack` , { cwd : dir } ) ;
46
+ const { stdout } = await exec ( `${ packageManager } pack` , { cwd : appDir } ) ;
40
47
const packageFilename = stdout . replace ( / \n $ / , '' ) ;
41
- const packagePath = path . join ( dir , packageFilename ) ;
48
+ const packagePath = path . join ( appDir , packageFilename ) ;
42
49
43
50
await mv ( packagePath , resultFilename ) ;
44
51
@@ -104,6 +111,18 @@ function hasExtensionsJson(dir) {
104
111
return pathExists ( path . join ( dir , 'extension.json' ) ) ;
105
112
}
106
113
114
+ async function hasWebDependencies ( dir ) {
115
+ const packageJsonPath = path . join ( dir , 'app' , 'package.json' ) ;
116
+
117
+ const packageJson = await readJsonFile ( packageJsonPath ) ;
118
+
119
+ if ( ! packageJson . webDependencies ) {
120
+ return false ;
121
+ }
122
+
123
+ return true ;
124
+ }
125
+
107
126
function hasCloudComponent ( dir ) {
108
127
return hasPackageJson ( path . join ( dir , 'cloud' ) ) ;
109
128
}
@@ -163,6 +182,12 @@ export default async function shoutemPack(dir, options) {
163
182
components . push ( 'cloud' ) ;
164
183
}
165
184
185
+ const hasWeb = await hasWebDependencies ( dir ) ;
186
+
187
+ if ( hasWeb ) {
188
+ components . push ( 'web' ) ;
189
+ }
190
+
166
191
const packedDirectories = components . map ( d => path . join ( dir , d ) ) ;
167
192
168
193
if ( ! ( await hasExtensionsJson ( dir ) ) ) {
@@ -177,7 +202,15 @@ export default async function shoutemPack(dir, options) {
177
202
const packageDir = path . join ( tmpDir , 'package' ) ;
178
203
await fs . mkdir ( packageDir ) ;
179
204
180
- const dirsToPack = await Promise . filter ( packedDirectories , hasPackageJson ) ;
205
+ const filteredDirsToPack = await Promise . filter (
206
+ packedDirectories ,
207
+ hasPackageJson ,
208
+ ) ;
209
+ // We still want to pack the web segment even though it uses package.json
210
+ // from the app segment
211
+ const dirsToPack = hasWeb
212
+ ? [ ...filteredDirsToPack , path . join ( dir , 'web' ) ]
213
+ : filteredDirsToPack ;
181
214
182
215
if ( options . nobuild ) {
183
216
console . error ( 'Skipping build step due to --nobuild flag.' ) ;
0 commit comments