1 | var fs = require('fs'),
|
2 | path = require('path'),
|
3 | constants = require('./constants');
|
4 |
|
5 | var Theme = function (conf) {
|
6 | for (var i in conf) {
|
7 | if (conf.hasOwnProperty(i)) {
|
8 | this[i] = conf[i];
|
9 | }
|
10 | }
|
11 | };
|
12 | Theme.prototype.getBaseDir = function () {
|
13 | return this.baseDir;
|
14 | };
|
15 | Theme.prototype.getScriptsDir = function () {
|
16 | return path.resolve(this.getBaseDir(), "scripts");
|
17 | };
|
18 | Theme.prototype.getCompiledScriptsDir = function () {
|
19 | return path.resolve(this.getBaseDir(), "compiled/scripts");
|
20 | };
|
21 | Theme.prototype.getBuildConfig = function (cb) {
|
22 | var self = this;
|
23 | if (this.buildConfig) {
|
24 | process.nextTick(function() {
|
25 | cb(this.buildConfig);
|
26 | });
|
27 | }
|
28 | this.program.log(2, constants.LOG_SEV_INFO, "Getting build config for " + this.name);
|
29 | fs.readFile(path.resolve(this.getBaseDir(), "build.js"), { encoding: 'utf-8' }, function (err, data) {
|
30 | if (err) {
|
31 | self.program.log(1, constants.LOG_SEV_ERROR, "Error getting build.js from " + self.name);
|
32 | return cb(err);
|
33 | }
|
34 | try {
|
35 | self.buildConfig = eval(data);
|
36 | } catch (e) {
|
37 | self.program.log(1, constants.LOG_SEV_ERROR, "Error parsing build.js from " + self.name);
|
38 | return cb(e);
|
39 | }
|
40 | cb(null, self.buildConfig);
|
41 | });
|
42 | };
|
43 |
|
44 | module.exports = {
|
45 |
|
46 | getThemeFromPath: function (dir, program, cb) {
|
47 | var configPath = path.resolve(dir, "theme.json");
|
48 | program.log(2, constants.LOG_SEV_INFO, "Attempting to read " + configPath);
|
49 | fs.readFile(configPath, { encoding: 'utf-8' }, function (err, data) {
|
50 | if (err) {
|
51 | program.log(1, constants.LOG_SEV_ERROR, "Error reading " + configPath);
|
52 | return cb(err);
|
53 | }
|
54 | var config;
|
55 | try {
|
56 | config = eval('('+data+')');
|
57 | } catch (e) {
|
58 | program.log(1, constants.LOG_SEV_ERROR, "Error parsing " + configPath + ".");
|
59 | program.log(2, constants.LOG_SEV_ERROR, "\n\n" + data);
|
60 | return cb(e);
|
61 | }
|
62 | var themeConf = config.about;
|
63 | if (!themeConf) {
|
64 | var errorStr = "No about section found in " + configPath;
|
65 | program.log(1, constants.LOG_SEV_ERROR, errorStr);
|
66 | return cb(new Error(errorStr));
|
67 | }
|
68 | themeConf.baseDir = dir;
|
69 | themeConf.program = program;
|
70 | cb(null, new Theme(themeConf));
|
71 | });
|
72 | },
|
73 | getThemeFromId: function(id, program, cb) {
|
74 | program.log(0, constants.LOG_SEV_ERROR, "Theme inheritance without manual ancestry is not yet supported. Please specify manual ancestry at the command line using -m.");
|
75 | process.exit(1);
|
76 | }
|
77 | } |
\ | No newline at end of file |