forked from mixi-inc/JavaScriptTraining
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver-cli.js
More file actions
executable file
·111 lines (86 loc) · 2.77 KB
/
server-cli.js
File metadata and controls
executable file
·111 lines (86 loc) · 2.77 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
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env node
var fs = require('fs'),
path = require('path'),
glob = require('glob'),
program = require('commander'),
server = require('./server'),
pkg = require('../package.json');
var basePath = process.cwd(),
baseName,
filePath,
revealPath = __dirname + '/../node_modules/reveal.js',
theme = 'black',
highlightTheme = 'zenburn';
program
.version(pkg.version)
.usage('<slides.md> [options]')
.option('-h, --host [host]', 'Host')
.option('-p, --port [port]', 'Port')
.option('-t, --theme [theme]', 'Theme')
.option('-H, --highlightTheme [highlight theme]', 'Highlight theme')
.option('-r, --print [filename]', 'Print')
.option('-s, --separator [separator]', 'Slide separator')
.option('-v, --verticalSeparator [vertical separator]', 'Vertical slide separator')
.parse(process.argv);
if(program.args.length > 2) {
program.help();
}
var pathArg = program.args[0];
// TODO: fix user can have own demo file/directory
if(pathArg === 'demo') {
basePath = __dirname + '/../demo';
} else if(pathArg) {
filePath = path.resolve(pathArg);
if(fs.existsSync(filePath)) {
var stat = fs.statSync(filePath);
if(stat.isFile()) {
basePath = path.dirname(filePath);
baseName = path.basename(filePath);
} else if(stat.isDirectory()) {
basePath = filePath;
}
} else {
basePath = baseName = pathArg;
}
}
theme = glob.sync('css/theme/*.css', {
cwd: revealPath
}).concat(glob.sync('theme/*.css', {
cwd: path.resolve(basePath)
})).filter(function(themePath) {
return path.basename(themePath).replace(path.extname(themePath), '') === program.theme;
}).pop() || 'css/theme/' + theme + '.css';
highlightTheme = program.highlightTheme || highlightTheme;
// load custom reveal.js options from reveal.json
var revealOptions = {};
var manifestPath = path.join(basePath, 'reveal.json');
if (fs.existsSync(manifestPath) && fs.statSync(manifestPath).isFile(manifestPath)) {
try {
var options = require(manifestPath);
if (typeof options === "object") {
revealOptions = options;
}
} catch (err) {
console.log(err);
}
}
// overide default theme from manifest options
if (!program.theme && revealOptions.theme) {
theme = revealOptions.theme;
}
// overide default highlight theme from manifest options
if (!program.highlightTheme && revealOptions.highlightTheme) {
highlightTheme = revealOptions.highlightTheme;
}
server.start({
basePath: basePath,
initialMarkdownPath: baseName,
host: program.host,
port: program.port,
theme: theme,
highlightTheme: highlightTheme,
separator: program.separator,
verticalSeparator: program.verticalSeparator,
printFile: program.print,
revealOptions: revealOptions
});