forked from netlify/angular-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetAngularRoot.js
27 lines (24 loc) · 1.06 KB
/
getAngularRoot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const { existsSync } = require('fs')
const path = require('path')
const process = require('process')
/**
* If we're in a monorepo then the site root may not be the same as the base directory
* If there's no angular.json in the root, we instead look for it 2 levels up from the publish dir
*/
const getAngularRoot = ({ failBuild, netlifyConfig }) => {
let angularRoot = process.cwd()
if (
!existsSync(path.join(angularRoot, 'angular.json')) &&
netlifyConfig.build.publish &&
netlifyConfig.build.publish !== angularRoot
) {
angularRoot = path.dirname(path.resolve(path.join(netlifyConfig.build.publish, '..', '..')))
if (!existsSync(path.join(angularRoot, 'angular.json'))) {
return failBuild(
`Could not locate your angular.json at your project root or two levels above your publish directory. Make sure your publish directory is set to "{PATH_TO_YOUR_SITE}/dist/{YOUR_PROJECT_NAME}/browser", where {YOUR_PROJECT_NAME} is 'defaultProject' in your angular.json.`,
)
}
}
return angularRoot
}
module.exports = getAngularRoot