-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathconfig.js
88 lines (68 loc) · 2.24 KB
/
config.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
80
81
82
83
84
85
86
87
88
const URL = require('url')
const path = require('path')
const os = require('os')
const fs = require('fs')
const embeddedGit = require('./embedded-git.json')
function getConfig() {
const config = {
outputPath: path.join(__dirname, '..', 'git', 'default'),
source: '',
checksum: '',
fileName: '',
tempFile: '',
}
// Possible values are ‘x64’, ‘arm’, ‘arm64’, ‘s390’, ‘s390x’, ‘mipsel’, ‘ia32’, ‘mips’, ‘ppc’ and ‘ppc64’
let arch = os.arch()
if (process.env.npm_config_arch) {
// If a specific npm_config_arch is set, we use that one instead of the OS arch (to support cross compilation)
console.log('npm_config_arch detected: ' + process.env.npm_config_arch)
arch = process.env.npm_config_arch
}
if (process.platform === 'win32' && arch === 'arm64') {
// Use the Dugite Native ia32 package for Windows arm64 (arm64 can run 32-bit code through emulation)
console.log('Downloading 32-bit Dugite Native for Windows arm64')
arch = 'ia32'
}
const key = `${process.platform}-${arch}`
const entry = embeddedGit[key]
if (entry != null) {
config.checksum = entry.checksum
config.source = entry.url
} else {
console.log(
`No embedded Git found for ${process.platform} and architecture ${arch}`
)
}
if (config.source !== '') {
processConfig(config)
}
if (process.platform === 'win32') {
const entry = embeddedGit['linux-x64']
const wslConfig = {
outputPath: path.join(__dirname, '..', 'git', 'linux-x64'),
source: entry.url,
checksum: entry.checksum,
fileName: '',
tempFile: '',
}
processConfig(wslConfig)
return [config, wslConfig]
}
return [config]
}
function processConfig(config) {
// compute the filename from the download source
const url = URL.parse(config.source)
const pathName = url.pathname
const index = pathName.lastIndexOf('/')
config.fileName = pathName.substr(index + 1)
const cacheDirEnv = process.env.DUGITE_CACHE_DIR
const cacheDir = cacheDirEnv ? path.resolve(cacheDirEnv) : os.tmpdir()
try {
fs.statSync(cacheDir)
} catch (e) {
fs.mkdirSync(cacheDir)
}
config.tempFile = path.join(cacheDir, config.fileName)
}
module.exports = getConfig