-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathboot.js
More file actions
46 lines (40 loc) · 1.05 KB
/
Copy pathboot.js
File metadata and controls
46 lines (40 loc) · 1.05 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
/** @typedef {import('pear-interface')} */
'use strict'
const fs = require('bare-fs')
const os = require('bare-os')
const { isWindows } = require('which-runtime')
const { PLATFORM_DIR } = require('./constants.js')
const Logger = require('./lib/logger.js')
const { cmdArgs } = require('./argv')
if (fs.existsSync(PLATFORM_DIR) === false) {
fs.mkdirSync(PLATFORM_DIR, { recursive: true })
}
if (isWindows === false) {
const stat = fs.statSync(PLATFORM_DIR)
const user = os.userInfo()
if (stat.uid !== user.uid) {
const err = new Error(`Current user does not own ${PLATFORM_DIR}`)
err.name = 'User Permissions Error'
throw err
}
}
global.LOG = new Logger({
labels: Logger.switches.log ? ['internal', 'sidecar'] : ['internal'],
pretty: Logger.switches.log
})
const BOOT_SIDECAR = 1
const BOOT_CLI = 2
switch (getBootType()) {
case BOOT_SIDECAR: {
require('./sidecar.js')
break
}
case BOOT_CLI: {
require('./cli.js')
break
}
}
function getBootType() {
if (cmdArgs[0] === '--sidecar') return BOOT_SIDECAR
return BOOT_CLI
}