1 | import findUp from "find-up";
|
2 | import fsExtra from "fs-extra";
|
3 | import path from "path";
|
4 |
|
5 | import { getPackageRoot } from "../util/packageInfo";
|
6 |
|
7 | import { BuidlerError } from "./errors";
|
8 | import { ERRORS } from "./errors-list";
|
9 | import { isTypescriptSupported } from "./typescript-support";
|
10 | const JS_CONFIG_FILENAME = "buidler.config.js";
|
11 | const TS_CONFIG_FILENAME = "buidler.config.ts";
|
12 |
|
13 | export function isCwdInsideProject() {
|
14 | return (
|
15 | findUp.sync(JS_CONFIG_FILENAME) !== null ||
|
16 | (isTypescriptSupported() && findUp.sync(TS_CONFIG_FILENAME) !== null)
|
17 | );
|
18 | }
|
19 |
|
20 | export function getUserConfigPath() {
|
21 | if (isTypescriptSupported()) {
|
22 | const tsConfigPath = findUp.sync(TS_CONFIG_FILENAME);
|
23 | if (tsConfigPath !== null) {
|
24 | return tsConfigPath;
|
25 | }
|
26 | }
|
27 |
|
28 | const pathToConfigFile = findUp.sync(JS_CONFIG_FILENAME);
|
29 | if (pathToConfigFile === null) {
|
30 | throw new BuidlerError(ERRORS.GENERAL.NOT_INSIDE_PROJECT);
|
31 | }
|
32 |
|
33 | return pathToConfigFile;
|
34 | }
|
35 |
|
36 | export async function getRecommendedGitIgnore() {
|
37 | const packageRoot = await getPackageRoot();
|
38 | const gitIgnorePath = path.join(packageRoot, "recommended-gitignore.txt");
|
39 |
|
40 | return fsExtra.readFile(gitIgnorePath, "utf-8");
|
41 | }
|