-
Notifications
You must be signed in to change notification settings - Fork 4
/
start.js
58 lines (48 loc) · 1.78 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
// Core dependencies
const path = require('path')
const fs = require('fs')
// Check for node_modules before running
const checkFiles = require('./lib/build/check-files').checkFiles
checkFiles()
// Local dependencies
const { buildWatchAndServe } = require('./lib/build/tasks')
const { projectDir } = require('./lib/utils')
async function collectDataUsage () {
// 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 permissionGranted = await usageData.askForUsageDataPermission()
usageDataConfig.collectUsageData = permissionGranted
usageData.setUsageDataConfig(usageDataConfig)
if (permissionGranted) {
usageData.startTracking(usageDataConfig)
}
} else {
if (usageDataConfig.collectUsageData === true) {
// Opted in
usageData.startTracking(usageDataConfig)
}
}
}
function createSessionDataDefaults () {
// Create template session data defaults file if it doesn't exist
const dataDirectory = path.join(projectDir, '/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))
}
}
(async () => {
createSessionDataDefaults()
await collectDataUsage()
await buildWatchAndServe()
})()