Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace defaultProject with environment variable #75

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading