forked from onivim/oni2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.js
74 lines (61 loc) · 2.21 KB
/
bootstrap.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
const cp = require("child_process")
const fs = require("fs")
const path = require("path")
const rootDir = path.join(__dirname, "..")
const configPath = path.join(rootDir, "assets", "configuration")
const vendorPath = path.join(rootDir, "vendor")
console.log("Bootstrap configuration: " + JSON.stringify(process.argv))
const outputFile = path.join(configPath, "setup.json")
const isMac = process.platform === "darwin"
const isWindows = process.platform === "win32"
const isLinux = !isMac && !isWindows
let nodePath
let nodeScriptPath = path.join(rootDir, "node")
let extensionsPath = path.join(rootDir, "extensions")
let developmentExtensionsPath = path.join(rootDir, "development_extensions")
let rgPath = path.join(vendorPath, "ripgrep-v0.10.0")
const getCygwinPath = (inputPath) => {
return inputPath.replace(/\\/g, "/")
}
if (isWindows) {
nodePath = getCygwinPath(path.join(vendorPath, "node-v14.15.4", "win-x64", "node.exe"))
nodeScriptPath = getCygwinPath(nodeScriptPath)
extensionsPath = getCygwinPath(extensionsPath)
developmentExtensionsPath = getCygwinPath(developmentExtensionsPath)
rgPath = getCygwinPath(path.join(rgPath, "windows", "rg.exe"))
} else if (isMac) {
nodePath = path.join(vendorPath, "node-v14.15.4", "osx", "node")
rgPath = path.join(rgPath, "mac", "rg")
} else if (isLinux) {
nodePath = path.join(vendorPath, "node-v14.15.4", "linux-x64", "node")
rgPath = path.join(rgPath, "linux", "rg")
} else {
console.error("Unknown OS...aborting.")
return 1
}
const config = {
node: nodePath,
nodeScript: nodeScriptPath,
bundledExtensions: extensionsPath,
developmentExtensions: developmentExtensionsPath,
rg: rgPath,
}
const oniConfig = JSON.stringify(config)
if (!fs.existsSync(configPath)) {
fs.mkdirSync(configPath)
if (!fs.existsSync(configPath)) {
console.error(`Config folder ${configPath} can not be made!`)
return 1
}
}
if (fs.existsSync(outputFile)) {
fs.unlinkSync(outputFile)
if (fs.existsSync(outputFile)) {
console.error(`Output file ${outputFile} can not be deleted!`)
return 1
}
}
console.log(`Writing to ${outputFile}...`)
fs.writeFileSync(outputFile, oniConfig)
console.log(`Done!`)
return 0