-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (52 loc) · 1.53 KB
/
index.js
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
"use strict";
// loads processor list and can build namespace object for items on list
Object.defineProperty(exports, "__esModule", { value: true });
exports.library = exports.profiles = void 0;
var fs_1 = require("fs");
// cache last used
var lastName = "";
var lastNS = {};
function library(name) {
if (lastName === name) {
return lastNS;
}
var profile = loadjson("./profiles.json").find(function (e) { return e.id === name; });
var ns = {};
if (profile) {
//console.time("namespaces: "+name)
var mods = profile.modules;
mods.forEach(function (uri) {
var mod = loadjson(uri);
//console.log("procmod: ",uri)
loadpackage(ns, mod);
});
//console.timeEnd("namespaces: "+name)
}
;
lastNS = ns;
lastName = name;
return ns;
}
exports.library = library;
;
function profiles() {
return loadjson("./profiles.json");
}
exports.profiles = profiles;
;
// for every namespace key in package create module entry in namespaces
function loadpackage(namespaces, pkg) {
for (var _i = 0, _a = Object.entries(pkg); _i < _a.length; _i++) {
var _b = _a[_i], ns = _b[0], value = _b[1];
// if (namespaces.hasOwnProperty(ns)) console.log("existing: " + ns);
namespaces[ns] = value;
}
}
;
// path relative to run location
// https://github.com/eslint/eslint/discussions/15305#discussioncomment-2400923
function loadjson(path) {
var p = __dirname + "/" + path;
return JSON.parse((0, fs_1.readFileSync)(p, 'utf8'));
}
;