-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathconfig.ts
More file actions
44 lines (35 loc) · 988 Bytes
/
config.ts
File metadata and controls
44 lines (35 loc) · 988 Bytes
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
import fs from 'node:fs';
import path from 'node:path';
export interface BrownieConfig {
swift?: string;
kotlin?: string;
kotlinPackageName?: string;
}
interface PackageJson {
brownie?: BrownieConfig;
}
function validateConfig(config: BrownieConfig): void {
if (!config.swift && !config.kotlin) {
throw new Error(
'At least one output path is required: brownie.swift or brownie.kotlin'
);
}
}
/**
* Loads brownie config from package.json in the current working directory.
*/
export function loadConfig(): BrownieConfig {
const packageJsonPath = path.resolve(process.cwd(), 'package.json');
if (!fs.existsSync(packageJsonPath)) {
throw new Error('package.json not found');
}
const packageJson: PackageJson = JSON.parse(
fs.readFileSync(packageJsonPath, 'utf-8')
);
const config = packageJson.brownie;
if (!config) {
throw new Error('brownie config not found in package.json');
}
validateConfig(config);
return config;
}