1 | 'use strict'
|
2 |
|
3 | const { isDirectory } = require('path-type')
|
4 |
|
5 | const { throwUserError } = require('./error')
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | const getBuildDir = async function (repositoryRoot, base) {
|
13 | const buildDir = base === undefined ? repositoryRoot : base
|
14 | await checkBuildDir(buildDir, repositoryRoot)
|
15 | return buildDir
|
16 | }
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | const checkBuildDir = async function (buildDir, repositoryRoot) {
|
23 | if (buildDir === repositoryRoot || (await isDirectory(buildDir))) {
|
24 | return
|
25 | }
|
26 |
|
27 | throwUserError(`Base directory does not exist: ${buildDir}`)
|
28 | }
|
29 |
|
30 | module.exports = { getBuildDir }
|