-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
185 lines (164 loc) · 6.4 KB
/
index.js
File metadata and controls
185 lines (164 loc) · 6.4 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/env node
const fs = require('fs')
const os = require('os')
const path = require('path')
const axios = require('axios')
const netrc = require('netrc')()
const { execSync } = require('child_process')
const { TIP, ERROR, ISSUE, WARNING, SUCCESS_MESSAGE } = require('./colorStrings')
const [, , privateRepo = 'zion'] = process.argv
const rawDataGitHubUrl = `https://raw.githubusercontent.com/fs-webdev/${privateRepo}/master/package.json`
const MINIMUM_RECOMMENDED_NODE_VERSION = 24
const MINIMUM_RECOMMENDED_NPM_VERSION = 11
const artifactoryUrl = '@fs:registry=https://familysearch.jfrog.io/artifactory/api/npm/fs-npm-prod-virtual/'
const isMacOS = process.platform === 'darwin'
performAllChecks()
async function performAllChecks() {
let errorMessage = ''
errorMessage += checkNodeVersion()
errorMessage += checkNpmVersion()
errorMessage += checkNvmVersion()
errorMessage += checkArtifactoryAccess()
errorMessage += await checkNetrcConfig()
errorMessage += checkHomebrew()
errorMessage += checkGitHubCli()
if (errorMessage === '') {
console.log('\n', SUCCESS_MESSAGE)
} else {
console.log(errorMessage)
}
}
function checkArtifactoryAccess() {
const artifactoryErrorMessage = `${ISSUE}
Unable to access a module published to artifactory.
Follow the instructions here for more info https://www.familysearch.org/frontier/docs/getting-started/setup#setting-up-artifactory`
console.log('Checking ~/.npmrc file and npm access for @fs scoped modules')
try {
const npmrcFile = fs.readFileSync(path.join(os.homedir(), '.npmrc'), 'utf8')
if (!npmrcFile.includes(artifactoryUrl)) {
return `\n${ISSUE}
Your npmrc file needs to be setup with the FamilySearch artifactory instance.\n${artifactoryErrorMessage}`
}
const checkMySetupOutput = execSync('npx @fs/check-my-setup --npm-check', { encoding: 'utf8' })
if (!checkMySetupOutput.includes('is working great!')) {
return artifactoryErrorMessage
}
} catch (err) {
return artifactoryErrorMessage
}
console.log(`Access to artifactory works well\n`)
return ''
}
function checkNvmVersion() {
console.log('Checking for nvm usage')
try {
execSync('fnm --version', { encoding: 'utf8' })
console.log('Using fnm, good work\n')
return ''
} catch (_) {}
if (!process.execPath.includes('/.nvm/')) {
return `\n${TIP}
We highly recommend using nvm to install and switch between versions of node. More info here https://github.com/creationix/nvm`
}
console.log('Using nvm, good work\n')
return ''
}
async function checkNetrcConfig() {
console.log('Checking ~/.netrc file and github access to fs-webdev')
if (Object.keys(netrc).length === 0) {
return `\n${ISSUE}
You don't appear to have a ~/.netrc file. In order to install private github dependencies, it is
necessary to have a correct entry in your ~/.netrc file.`
}
const githubData = netrc['github.com']
if (githubData === undefined) {
return `\n${ISSUE}
You don't appear to have a github.com entry in your ~/.netrc file. In order to install private github dependencies, it is
necessary to have a correct github.com entry in your ~/.netrc file.`
}
try {
const data = await axios.get(rawDataGitHubUrl, {
headers: {
Authorization: `token ${githubData.login}`,
Accept: 'application/vnd.github.v3+json',
},
})
if (data.status !== 200) {
return `\n${WARNING}
A call to a private repo on github.com/fs-webdev did not return a status of 200. Your ~/.netrc file may not be setup correctly`
}
if (netrc['api.github.com'] === undefined) {
console.log(`\n${TIP} if you ever want to use curl or similar terminal commands to hit github's API, you can add an entry into your ~/.netrc file
that has the same data as your github.com entry, but change the machine name to "api.github.com". Then you won't have to worry about
setting authentication headers or tokens in curl`)
}
} catch (err) {
return `\n${ERROR}
An error occurred when trying to get data from the private repo "fs-webdev/${privateRepo}" on github.com.
Check the following error message, and contact frontier core if necessary:
${err.message}`
}
console.log('~/.netrc file appears valid\n')
return ''
}
function checkNpmVersion() {
console.log('Checking npm version')
const command = 'npm --version'
try {
const npmVersion = execSync(command, { encoding: 'utf8' })
console.log('npm version: ', npmVersion)
const [major] = npmVersion.split('.').map(Number)
if (major < MINIMUM_RECOMMENDED_NPM_VERSION) {
return `\n${ISSUE}
You are using npm version ${major}, but ${MINIMUM_RECOMMENDED_NPM_VERSION} is the minimum version we support\n`
}
} catch (err) {
return `\n${ERROR}
There was an issue trying to check your version of npm. Try running "npm --version" in your terminal.
Please reach out to a member of the frontier core team for assistance`
}
return ''
}
function checkNodeVersion() {
console.log('Checking node version')
const { node: nodeVersion } = process.versions
const [major] = nodeVersion.split('.')
if (Number(major) < MINIMUM_RECOMMENDED_NODE_VERSION) {
return `\n${ISSUE}
You are using node version ${major}, but ${MINIMUM_RECOMMENDED_NODE_VERSION} is the minimum version we support\n`
}
console.log('node version: ', nodeVersion, '\n')
return ''
}
function checkHomebrew() {
if (!isMacOS) {
console.log('Skipping homebrew check (macOS only)\n')
return ''
}
console.log('Checking for homebrew')
const command = 'brew --version'
try {
const brewVersion = execSync(command, { encoding: 'utf8' })
console.log('homebrew version: ', brewVersion, '\n')
} catch (err) {
return `\n${ISSUE}
Homebrew is required for managing packages on Mac. You can install it by running: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`
}
return ''
}
function checkGitHubCli() {
if (!isMacOS) {
console.log('Skipping GitHub CLI check (macOS only)\n')
return ''
}
console.log('Checking for GitHub CLI')
const command = 'gh --version'
try {
const ghVersion = execSync(command, { encoding: 'utf8' })
console.log('GitHub CLI version: ', ghVersion, '\n')
} catch (err) {
return `\n${ISSUE}
GitHub CLI is required to interact with GitHub from your terminal. You can install it with homebrew using "brew install gh"`
}
return ''
}