forked from bugsnag/bugsnag-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.js
116 lines (107 loc) · 4.8 KB
/
install.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
const prompts = require('prompts')
const { promisify } = require('util')
const { readFile } = require('fs')
const { join } = require('path')
const install = require('../lib/install')
const { onCancel } = require('../lib/utils')
const { blue } = require('kleur')
const semver = require('semver')
const detectInstalled = require('../lib/detect-installed')
module.exports = async (argv, globalOpts) => {
const projectRoot = globalOpts['project-root']
const alreadyInstalled = await detectInstalled(projectRoot)
const isWanted = await confirmWanted(alreadyInstalled, projectRoot)
if (isWanted) {
const version = await selectVersion(projectRoot)
const tool = await withTool(projectRoot)
console.log(blue(`> Installing @bugsnag/expo with ${tool}. This could take a while!`))
await install(tool, version, projectRoot)
}
}
const confirmWanted = async (alreadyInstalled, root) => {
return (await prompts({
type: 'confirm',
name: 'install',
message: alreadyInstalled
? '@bugsnag/expo already appears to be installed, do you want to install it anyway?'
: '@bugsnag/expo does not appear to be installed, do you want to install it?',
initial: !alreadyInstalled
}, { onCancel })).install
}
const withTool = async (root) => {
const cli = await npmOrYarn(root)
return (await prompts({
type: 'select',
name: 'tool',
message: 'Using yarn or npm?',
choices: [
{ title: 'npm', value: 'npm' },
{ title: 'yarn', value: 'yarn' }
],
initial: cli === 'npm' ? 0 : 1
}, { onCancel })).tool
}
const selectVersion = async (dir) => {
try {
const pkg = JSON.parse(await promisify(readFile)(join(dir, 'package.json'), 'utf8'))
const expoVersion = pkg.dependencies.expo
let message = 'If you want the latest version of @bugsnag/expo hit enter, otherwise type the version you want'
let defaultVersion = 'latest'
// help select compatible versions of @bugsnag/expo for older expo releases
const isPre33 = (expoVersion && !semver.gte(semver.minVersion(expoVersion), '33.0.0'))
const isPre36 = (expoVersion && !semver.gte(semver.minVersion(expoVersion), '36.0.0'))
const isPre37 = (expoVersion && !semver.gte(semver.minVersion(expoVersion), '37.0.0'))
const isPre38 = (expoVersion && !semver.gte(semver.minVersion(expoVersion), '38.0.0'))
const isPre39 = (expoVersion && !semver.gte(semver.minVersion(expoVersion), '39.0.0'))
const isPre40 = (expoVersion && !semver.gte(semver.minVersion(expoVersion), '40.0.0'))
const isPre42 = (expoVersion && !semver.gte(semver.minVersion(expoVersion), '42.0.0'))
const isPre43 = (expoVersion && !semver.gte(semver.minVersion(expoVersion), '43.0.0'))
if (isPre33) {
throw new Error('Expo SDK <33 is no longer supported')
} else if (isPre36) {
message = 'It looks like you’re using a version of Expo SDK <36. The last version of Bugsnag that supported your version of Expo is v6.4.4'
defaultVersion = '6.4.4'
} else if (isPre37) {
message = 'It looks like you’re using a version of Expo SDK <37. The last version of Bugsnag that supported your version of Expo is v6.5.3'
defaultVersion = '6.5.3'
} else if (isPre38) {
message = 'It looks like you’re using a version of Expo SDK <38. The last version of Bugsnag that supported your version of Expo is v7.1.1'
defaultVersion = '7.1.1'
} else if (isPre39) {
message = 'It looks like you’re using a version of Expo SDK <39. The last version of Bugsnag that supported your version of Expo is v7.3.5'
defaultVersion = '7.3.5'
} else if (isPre40) {
message = 'It looks like you’re using a version of Expo SDK <40. The last version of Bugsnag that supported your version of Expo is v7.5.5'
defaultVersion = '7.5.5'
} else if (isPre42) {
message = 'It looks like you’re using a version of Expo SDK <42. The last version of Bugsnag that supported your version of Expo is v7.11.0'
defaultVersion = '7.11.0'
} else if (isPre43) {
message = 'It looks like you’re using a version of Expo SDK <43. The last version of Bugsnag that supported your version of Expo is v7.13.2'
defaultVersion = '7.13.2'
}
const { version } = await prompts({
type: 'text',
name: 'version',
message: message,
initial: defaultVersion,
validate: str => {
if (str === 'latest') return true
if (semver.valid(str)) return true
if (semver.validRange(str)) return true
return 'Version must be: a valid semver version/range or "latest"'
}
}, { onCancel })
return version
} catch (e) {
throw new Error(`Could not detect Expo version in package.json: ${e.message}`)
}
}
const npmOrYarn = async (dir) => {
try {
await promisify(readFile)(join(dir, 'yarn.lock'))
return 'yarn'
} catch (e) {
return 'npm'
}
}