Skip to content

Commit

Permalink
fix: replace defaultProject with environment variable (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skn0tt committed Nov 9, 2023
1 parent cd03728 commit ee4f818
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/helpers/setUpEdgeFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { Buffer } = require('node:buffer')
const { existsSync, readdirSync } = require('node:fs')
const { writeFile, mkdir, readFile } = require('node:fs/promises')
const { join, relative, sep, posix } = require('node:path')
const process = require('node:process')

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

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

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

const getProject = (angularJson) => {
const projectName = angularJson.defaultProject ?? Object.keys(angularJson.projects)[0]
const getProject = (angularJson, failBuild) => {
const selectedProject = process.env.ANGULAR_PROJECT
if (selectedProject) {
const project = angularJson.projects[selectedProject]
if (!project) {
return failBuild(
`Could not find project selected project "${selectedProject}" in angular.json. Please update the ANGULAR_PROJECT environment variable.`,
)
}
return project
}

const projectNames = Object.keys(angularJson.projects)
const [projectName] = projectNames
if (projectNames.length > 1) {
console.warn(
`Found multiple projects in angular.json, deploying "${projectName}". To deploy a different one, set the ANGULAR_PROJECT environment variable to the project name.`,
)
}

return angularJson.projects[projectName]
}

Expand Down

0 comments on commit ee4f818

Please sign in to comment.