1 | 'use strict'
|
2 |
|
3 | const { resolve } = require('path')
|
4 |
|
5 | const findUp = require('find-up')
|
6 | const pLocate = require('p-locate')
|
7 | const pathExists = require('path-exists')
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | const getConfigPath = async function ({ configOpt, cwd, repositoryRoot, configBase }) {
|
15 | const configPath = await pLocate(
|
16 | [
|
17 | searchConfigOpt(cwd, configOpt),
|
18 | searchBaseConfigFile(repositoryRoot, configBase),
|
19 | searchConfigFile(repositoryRoot),
|
20 | findUp(FILENAME, { cwd }),
|
21 | ],
|
22 | Boolean,
|
23 | )
|
24 | return configPath
|
25 | }
|
26 |
|
27 |
|
28 | const searchConfigOpt = function (cwd, configOpt) {
|
29 | if (configOpt === undefined) {
|
30 | return
|
31 | }
|
32 |
|
33 | return resolve(cwd, configOpt)
|
34 | }
|
35 |
|
36 |
|
37 | const searchBaseConfigFile = function (repositoryRoot, configBase) {
|
38 | if (configBase === undefined) {
|
39 | return
|
40 | }
|
41 |
|
42 | return searchConfigFile(configBase)
|
43 | }
|
44 |
|
45 |
|
46 | const searchConfigFile = async function (cwd) {
|
47 | const path = resolve(cwd, FILENAME)
|
48 | if (!(await pathExists(path))) {
|
49 | return
|
50 | }
|
51 | return path
|
52 | }
|
53 |
|
54 | const FILENAME = 'netlify.toml'
|
55 |
|
56 | module.exports = { getConfigPath }
|