forked from NomicFoundation/hardhat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject-structure.ts
53 lines (42 loc) · 1.43 KB
/
project-structure.ts
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import findUp from "find-up";
import fsExtra from "fs-extra";
import path from "path";
import { getPackageRoot } from "../util/packageInfo";
import { HardhatError } from "./errors";
import { ERRORS } from "./errors-list";
const JS_CONFIG_FILENAME = "hardhat.config.js";
const CJS_CONFIG_FILENAME = "hardhat.config.cjs";
const TS_CONFIG_FILENAME = "hardhat.config.ts";
const CTS_CONFIG_FILENAME = "hardhat.config.cts";
export function isCwdInsideProject() {
return (
findUp.sync(TS_CONFIG_FILENAME) !== undefined ||
findUp.sync(CTS_CONFIG_FILENAME) !== undefined ||
findUp.sync(CJS_CONFIG_FILENAME) !== undefined ||
findUp.sync(JS_CONFIG_FILENAME) !== undefined
);
}
export function getUserConfigPath() {
const tsConfigPath = findUp.sync(TS_CONFIG_FILENAME);
if (tsConfigPath) {
return tsConfigPath;
}
const ctsConfigPath = findUp.sync(CTS_CONFIG_FILENAME);
if (ctsConfigPath) {
return ctsConfigPath;
}
const cjsConfigPath = findUp.sync(CJS_CONFIG_FILENAME);
if (cjsConfigPath) {
return cjsConfigPath;
}
const pathToConfigFile = findUp.sync(JS_CONFIG_FILENAME);
if (!pathToConfigFile) {
throw new HardhatError(ERRORS.GENERAL.NOT_INSIDE_PROJECT);
}
return pathToConfigFile;
}
export async function getRecommendedGitIgnore() {
const packageRoot = getPackageRoot();
const gitIgnorePath = path.join(packageRoot, "recommended-gitignore.txt");
return fsExtra.readFile(gitIgnorePath, "utf-8");
}