-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
39 lines (35 loc) · 1020 Bytes
/
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
var fs = require('fs-extra'),
path = require('path'),
ghost = require('ghost'),
contentPath = path.join(__dirname, 'content'),
contentFolders = ['apps', 'data', 'images', 'themes'],
ghostContentPath = path.join(__dirname, 'node_modules/ghost/content'),
configFile = path.join(__dirname, 'config.js');
function copy () {
fs.copy(ghostContentPath, contentPath, function (err) {
if (err) throw new Error('Failed to copy ghost content folder. ' + err);
start();
});
}
function contains (arr, items) {
return items.every(function (item) {
return arr.indexOf(item) !== -1;
});
}
function start () {
ghost({
config: configFile
}).then(function (server) {
server.start();
});
}
fs.stat(contentPath, function (err) {
if (err) {
copy();
} else {
fs.readdir(contentPath, function (err, files) {
if (files && contains(files, contentFolders)) return start();
copy();
});
}
});