-
Notifications
You must be signed in to change notification settings - Fork 7
/
start.js
executable file
·53 lines (43 loc) · 1.58 KB
/
start.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
// Core dependencies
const path = require('path')
const fs = require('fs')
checkFiles()
runGulp()
// Warn if node_modules folder doesn't exist
function checkFiles () {
const nodeModulesExists = fs.existsSync(path.join(__dirname, '/node_modules'))
if (!nodeModulesExists) {
console.error('ERROR: Node module folder missing. Try running `npm install`')
process.exit(0)
}
// Create template .env file if it doesn't exist
const envExists = fs.existsSync(path.join(__dirname, '/.env'))
if (!envExists) {
fs.createReadStream(path.join(__dirname, '/lib/template.env'))
.pipe(fs.createWriteStream(path.join(__dirname, '/.env')))
}
}
// Create template session data defaults file if it doesn't exist
const dataDirectory = path.join(__dirname, '/app/data')
const sessionDataDefaultsFile = path.join(dataDirectory, '/session-data-defaults.js')
const sessionDataDefaultsFileExists = fs.existsSync(sessionDataDefaultsFile)
if (!sessionDataDefaultsFileExists) {
console.log('Creating session data defaults file')
if (!fs.existsSync(dataDirectory)) {
fs.mkdirSync(dataDirectory)
}
fs.createReadStream(path.join(__dirname, '/lib/template.session-data-defaults.js'))
.pipe(fs.createWriteStream(sessionDataDefaultsFile))
}
// Run gulp
function runGulp () {
const spawn = require('cross-spawn')
process.env.FORCE_COLOR = 1
const gulp = spawn('./node_modules/.bin/gulp')
gulp.stdout.pipe(process.stdout)
gulp.stderr.pipe(process.stderr)
process.stdin.pipe(gulp.stdin)
gulp.on('exit', function (code) {
console.log('gulp exited with code ' + code.toString())
})
}