-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.js
79 lines (65 loc) · 2.31 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
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
// Core dependencies
const path = require('path')
const fs = require('fs')
checkFiles()
// Local dependencies
const usageData = require('./lib/usage_data')
// Get usageDataConfig from file, if exists
const usageDataConfig = usageData.getUsageDataConfig()
if (usageDataConfig.collectUsageData === undefined) {
// No recorded answer, so ask for permission
const promptPromise = usageData.askForUsageDataPermission()
promptPromise.then(function (permissionGranted) {
usageDataConfig.collectUsageData = permissionGranted
usageData.setUsageDataConfig(usageDataConfig)
if (permissionGranted) {
usageData.startTracking(usageDataConfig)
}
runGulp()
})
} else if (usageDataConfig.collectUsageData === true) {
// Opted in
usageData.startTracking(usageDataConfig)
runGulp()
} else {
// Opted out
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
var 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())
})
}