This repository has been archived by the owner on Jul 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (51 loc) · 1.9 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
53
54
55
56
57
58
59
60
61
62
63
'use strict';
const fs = require('fs');
const path = require('path');
const parsePanels = require('./lib/panels');
const parseGraphics = require('./lib/graphics');
const parseManifest = require('./lib/manifest');
const parseAssets = require('./lib/assets');
const parseSounds = require('./lib/sounds');
const config = require('./lib/config');
const parseExtension = require('./lib/extension');
module.exports = function (bundlePath, bundleCfgPath) {
// Resolve the path to the bundle and its package.json
const pkgPath = path.join(bundlePath, 'package.json');
if (!fs.existsSync(pkgPath)) {
throw new Error(`Bundle at path ${bundlePath} does not contain a package.json!`);
}
// Read metadata from the package.json
let pkg;
try {
pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
} catch (e) {
throw new Error(`${pkgPath} is not valid JSON, ` +
'please check it against a validator such as jsonlint.com');
}
const bundle = parseManifest(pkg, bundlePath);
bundle.rawManifest = JSON.stringify(bundle);
bundle.dir = bundlePath;
// If there is a config file for this bundle, parse it.
// Else if there is only a configschema for this bundle, parse that and apply any defaults.
if (bundleCfgPath) {
bundle.config = config.parse(bundle, bundleCfgPath);
} else {
bundle.config = config.parseDefaults(bundle);
}
// Parse the dashboard panels
const dashboardDir = path.resolve(bundle.dir, 'dashboard');
bundle.dashboard = {
dir: dashboardDir,
panels: parsePanels(dashboardDir, bundle)
};
// Parse the graphics
const graphicsDir = path.resolve(bundle.dir, 'graphics');
bundle.graphics = parseGraphics(graphicsDir, bundle);
// Parse asset categories
bundle.assetCategories = parseAssets(pkg);
// Parse sound cues
parseSounds(bundle, pkg);
// Determine if this bundle has an extension that should be loaded by NodeCG
bundle.hasExtension = parseExtension(bundle.dir, bundle);
return bundle;
};