This repository has been archived by the owner on Feb 7, 2019. It is now read-only.
forked from prebuild/prebuild-install
/
bin.js
executable file
·61 lines (49 loc) · 1.66 KB
/
bin.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
#!/usr/bin/env node
var path = require('path')
var log = require('npmlog')
var fs = require('fs')
var extend = require('xtend')
var pkg = require(path.resolve('package.json'))
var rc = require('./rc')(pkg)
var download = require('./download')
var util = require('./util')
var prebuildClientVersion = require('./package.json').version
if (rc.version) {
console.log(prebuildClientVersion)
process.exit(0)
}
if (rc.path) process.chdir(rc.path)
log.heading = 'prebuild-install'
if (rc.verbose) {
log.level = 'verbose'
}
if (!fs.existsSync('package.json')) {
log.error('setup', 'No package.json found. Aborting...')
process.exit(1)
}
if (rc.help) {
console.error(fs.readFileSync(path.join(__dirname, 'help.txt'), 'utf-8'))
process.exit(0)
}
log.info('begin', 'Prebuild-install version', prebuildClientVersion)
var opts = extend(rc, {pkg: pkg, log: log})
var execPath = process.env.npm_execpath || process.env.NPM_CLI_JS
if (util.isYarnPath(execPath) && /node_modules/.test(process.cwd())) {
// From yarn repository
} else if (!(typeof pkg._from === 'string')) {
// log.info('install', 'installing inside prebuild-install directory, skipping download.')
// process.exit(1)
} else if (pkg._from.length > 4 && pkg._from.substr(0, 4) === 'git+') {
log.info('install', 'installing from git repository, skipping download.')
process.exit(1)
} else if (opts.compile === true || opts.prebuild === false) {
log.info('install', '--build-from-source specified, not attempting download.')
process.exit(1)
}
download(opts, function (err) {
if (err) {
log.warn('install', err.message)
return process.exit(1)
}
log.info('install', 'Prebuild successfully installed!')
})