Skip to content

Commit ee4f818

Browse files
authored
fix: replace defaultProject with environment variable (#75)
1 parent cd03728 commit ee4f818

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/helpers/setUpEdgeFunction.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const { Buffer } = require('node:buffer')
22
const { existsSync, readdirSync } = require('node:fs')
33
const { writeFile, mkdir, readFile } = require('node:fs/promises')
44
const { join, relative, sep, posix } = require('node:path')
5+
const process = require('node:process')
56

67
const { readJson } = require('fs-extra')
78

@@ -20,8 +21,26 @@ const getAllFilesIn = (dir) =>
2021

2122
const toPosix = (path) => path.split(sep).join(posix.sep)
2223

23-
const getProject = (angularJson) => {
24-
const projectName = angularJson.defaultProject ?? Object.keys(angularJson.projects)[0]
24+
const getProject = (angularJson, failBuild) => {
25+
const selectedProject = process.env.ANGULAR_PROJECT
26+
if (selectedProject) {
27+
const project = angularJson.projects[selectedProject]
28+
if (!project) {
29+
return failBuild(
30+
`Could not find project selected project "${selectedProject}" in angular.json. Please update the ANGULAR_PROJECT environment variable.`,
31+
)
32+
}
33+
return project
34+
}
35+
36+
const projectNames = Object.keys(angularJson.projects)
37+
const [projectName] = projectNames
38+
if (projectNames.length > 1) {
39+
console.warn(
40+
`Found multiple projects in angular.json, deploying "${projectName}". To deploy a different one, set the ANGULAR_PROJECT environment variable to the project name.`,
41+
)
42+
}
43+
2544
return angularJson.projects[projectName]
2645
}
2746

0 commit comments

Comments
 (0)