-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
48 lines (45 loc) · 1.54 KB
/
app.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
'use strict';
/**
* Created by Adrian on 12-Apr-16.
*/
const thorin = require('thorin'),
path = require('path');
thorin
.addTransport(require('thorin-transport-http'))
//.addPlugin(require('thorin-plugin-sass'))
.addPlugin(require('thorin-plugin-render'));
let isCompiling = thorin.argv('compile');
if (isCompiling) {
thorin.addPlugin(require('thorin-plugin-static-html'));
thorin.version = thorin.version + thorin.util.randomString(8);
}
if (thorin.env === 'production') thorin.logger.disableConsole();
thorin.run((err) => {
if (err) {
log.error(err);
return process.exit(1);
}
if (isCompiling) {
// Since we're using dynamic routes, generate action codes based on the views folder.
let views = thorin.util.readDirectory(thorin.root + '/app/views/pages', 'swig'),
rootPath = path.normalize(thorin.root + '/app/views/pages'),
paths = ['/'];
views.forEach((viewPath) => {
let subPath = viewPath.replace(rootPath, '').replace(/\.swig/g,'');
if(subPath.substr(1) === 'layout') return;
paths.push(subPath);
});
const staticObj = thorin.plugin('static-html');
return staticObj.generatePaths(paths, (err) => {
thorin.logger.enableConsole();
if(err) {
log.fatal(`Failed to generate static HTML from paths`, err);
return process.exit(1);
}
log.info('HTML generated.');
return process.exit(0);
});
}
thorin.logger.enableConsole();
log.info(`Thorin.js documentation server listening on http://localhost:${thorin.config('transport.http.port')}`);
});