Skip to content

Commit 13da182

Browse files
committed
feat: add package.json parsing capability
1 parent 80f9789 commit 13da182

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
],
1818
"author": "leoweyr <[email protected]>",
1919
"license": "MIT",
20+
"devDependencies": {
21+
"@types/node": "^22.10.7"
22+
},
2023
"dependencies": {
2124
"typescript": "^5.7.3"
2225
},

src/nodejs/PackageConfiguration.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import * as Path from "path";
2+
import * as File from "fs";
3+
4+
import { Project } from "../project/Project";
5+
6+
7+
export class PackageConfiguration {
8+
private readonly filePath: string;
9+
10+
public constructor(project: Project) {
11+
this.filePath = Path.join(project.getPath(), "package.json");
12+
}
13+
14+
public getPath(): string {
15+
return this.filePath;
16+
}
17+
18+
public getName(): string {
19+
const packageJson: any = JSON.parse(File.readFileSync(this.filePath, "utf-8"));
20+
21+
return packageJson.name;
22+
}
23+
24+
public getVersion(): string {
25+
const packageJson: any = JSON.parse(File.readFileSync(this.filePath, "utf-8"));
26+
27+
return packageJson.version;
28+
}
29+
30+
public getMainEntry(): string {
31+
const packageJson: any = JSON.parse(File.readFileSync(this.filePath, "utf-8"));
32+
33+
return packageJson.main;
34+
}
35+
}

src/project/Project.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface Project {
2+
getPath(): string;
3+
}

0 commit comments

Comments
 (0)