@@ -22,21 +22,17 @@ const getAllFilesIn = (dir) =>
22
22
23
23
const toPosix = ( path ) => path . split ( sep ) . join ( posix . sep )
24
24
25
- const getProject = ( angularJson , failBuild , isNxWorkspace = false ) => {
25
+ const getProjectName = ( angularJson , failBuild ) => {
26
26
const selectedProject = process . env . ANGULAR_PROJECT
27
27
28
- if ( isNxWorkspace ) {
29
- return angularJson
30
- }
31
-
32
28
if ( selectedProject ) {
33
29
const project = angularJson . projects [ selectedProject ]
34
30
if ( ! project ) {
35
31
return failBuild (
36
32
`Could not find project selected project "${ selectedProject } " in angular.json. Please update the ANGULAR_PROJECT environment variable.` ,
37
33
)
38
34
}
39
- return project
35
+ return selectedProject
40
36
}
41
37
42
38
const projectNames = Object . keys ( angularJson . projects )
@@ -47,14 +43,47 @@ const getProject = (angularJson, failBuild, isNxWorkspace = false) => {
47
43
)
48
44
}
49
45
46
+ return projectName
47
+ }
48
+
49
+ const getProject = ( angularJson , failBuild , isNxWorkspace = false , projectName = null ) => {
50
+ if ( isNxWorkspace ) {
51
+ return angularJson
52
+ }
53
+ if ( ! projectName ) {
54
+ projectName = getProjectName ( angularJson , failBuild )
55
+ }
56
+
50
57
return angularJson . projects [ projectName ]
51
58
}
52
59
53
60
module . exports . getProject = getProject
54
61
62
+ const getBuildInformation = ( angularJson , failBuild , workspaceType ) => {
63
+ const projectName = getProjectName ( angularJson , failBuild )
64
+ const project = getProject ( angularJson , failBuild , workspaceType === 'nx' , projectName )
65
+
66
+ let { outputPath } = workspaceType === 'nx' ? project . targets . build . options : project . architect . build . options
67
+
68
+ if ( ! outputPath && workspaceType === 'default' ) {
69
+ // outputPath might not be explicitly defined in angular.json
70
+ // so we will try default which is dist/<project-name>
71
+ outputPath = join ( 'dist' , projectName )
72
+ }
73
+
74
+ const isApplicationBuilder =
75
+ workspaceType === 'nx'
76
+ ? project . targets . build . executor . endsWith ( ':application' )
77
+ : project . architect . build . builder . endsWith ( ':application' )
78
+
79
+ return { outputPath, isApplicationBuilder }
80
+ }
81
+
82
+ module . exports . getBuildInformation = getBuildInformation
83
+
55
84
// eslint-disable-next-line max-lines-per-function
56
- const setUpEdgeFunction = async ( { outputDir , constants, failBuild, usedEngine } ) => {
57
- const serverDistRoot = join ( outputDir , 'server' )
85
+ const setUpEdgeFunction = async ( { outputPath , constants, failBuild, usedEngine } ) => {
86
+ const serverDistRoot = join ( outputPath , 'server' )
58
87
if ( ! existsSync ( serverDistRoot ) ) {
59
88
console . log ( 'No server output generated, skipping SSR setup.' )
60
89
return
@@ -66,11 +95,11 @@ const setUpEdgeFunction = async ({ outputDir, constants, failBuild, usedEngine }
66
95
await mkdir ( edgeFunctionDir , { recursive : true } )
67
96
68
97
const html = await readFile ( join ( serverDistRoot , 'index.server.html' ) , 'utf-8' )
69
- const staticFiles = getAllFilesIn ( join ( outputDir , 'browser' ) ) . map (
70
- ( path ) => `/${ relative ( join ( outputDir , 'browser' ) , path ) } ` ,
98
+ const staticFiles = getAllFilesIn ( join ( outputPath , 'browser' ) ) . map (
99
+ ( path ) => `/${ relative ( join ( outputPath , 'browser' ) , path ) } ` ,
71
100
)
72
101
73
- const excludedPaths = [ '/.netlify/*' , ...staticFiles , ...Object . keys ( await getPrerenderedRoutes ( outputDir ) ) ] . map (
102
+ const excludedPaths = [ '/.netlify/*' , ...staticFiles , ...Object . keys ( await getPrerenderedRoutes ( outputPath ) ) ] . map (
74
103
toPosix ,
75
104
)
76
105
@@ -115,7 +144,7 @@ const setUpEdgeFunction = async ({ outputDir, constants, failBuild, usedEngine }
115
144
`
116
145
} else if ( usedEngine === 'CommonEngine' ) {
117
146
const cssAssetsManifest = { }
118
- const outputBrowserDir = join ( outputDir , 'browser' )
147
+ const outputBrowserDir = join ( outputPath , 'browser' )
119
148
const cssFiles = getAllFilesIn ( outputBrowserDir ) . filter ( ( file ) => file . endsWith ( '.css' ) )
120
149
121
150
for ( const cssFile of cssFiles ) {
0 commit comments