-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModuleAutoDiscoverEngine.ts
More file actions
34 lines (30 loc) · 1.08 KB
/
Copy pathModuleAutoDiscoverEngine.ts
File metadata and controls
34 lines (30 loc) · 1.08 KB
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
import fs = require("fs");
import path = require("path");
import { FileSearch } from "./FileSearch"
export class ModuleAutoDiscoverEngine {
private packages: string[];
private bindingFiles: string[];
constructor(searchRoot: string = "./") {
let fileSearch = new FileSearch();
this.packages = fileSearch.searchFiles(searchRoot, "package.json", ["node_modules"]);
this.bindingFiles = fileSearch.searchFiles(searchRoot, "binding.gyp", ["node_modules"]);
}
findModuleByPackageName(name: string): string {
for(let pkg of this.packages) {
if(JSON.parse(fs.readFileSync(pkg).toString()).name == name)
return pkg;
}
return null;
}
findModuleByDirectoryName(name: string) {
for(let file of this.bindingFiles) {
let dir = path.dirname(file);
let directories = dir.split(/[\/\\]/);
if(directories.length > 0) {
if(directories[directories.length - 1] == name)
return file;
}
}
return null;
}
}