-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
204 lines (177 loc) · 6.86 KB
/
Copy pathindex.js
File metadata and controls
204 lines (177 loc) · 6.86 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/usr/bin/env node
const { execSync } = require('child_process')
const { TIP, ERROR, ISSUE, SUCCESS_MESSAGE } = require('./colorStrings')
const [, , privateRepo = 'zion'] = process.argv
const MINIMUM_RECOMMENDED_NODE_VERSION = 24
const MINIMUM_RECOMMENDED_NPM_VERSION = 11
const artifactoryRegistry = '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 checkGitHubAccess()
errorMessage += checkHomebrew()
errorMessage += checkGitHubCli()
if (errorMessage === '') {
console.log('\n', SUCCESS_MESSAGE)
} else {
console.log(errorMessage)
}
}
function checkArtifactoryAccess() {
const artifactoryErrorMessage = `${ISSUE}
Unable to access npm modules through artifactory.
Follow the instructions here for more info https://www.familysearch.org/frontier/docs/getting-started/setup#setting-up-artifactory`
console.log('Checking npm access through the Artifactory registry')
try {
const registry = execSync('npm config get registry', { encoding: 'utf8' }).trim().replace(/\/$/, '')
const normalizedArtifactoryRegistry = artifactoryRegistry.replace(/\/$/, '')
if (registry !== normalizedArtifactoryRegistry) {
return `\n${ISSUE}
Your npm default registry must be set to the FamilySearch artifactory instance.\n${artifactoryErrorMessage}`
}
const scopedAccessCheckOutput = execSync('npx @fs/check-my-setup --npm-check', { encoding: 'utf8' })
if (!scopedAccessCheckOutput.includes('is working great!')) {
return artifactoryErrorMessage
}
const npmAccessCheckOutput = execSync(`npm view axios version --registry=${artifactoryRegistry}`, {
encoding: 'utf8',
})
if (!npmAccessCheckOutput.trim()) {
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 checkGitHubAccess() {
console.log('Checking github access to fs-webdev')
try {
execSync(`git ls-remote https://github.com/fs-webdev/${privateRepo}.git HEAD`, {
encoding: 'utf8',
stdio: ['pipe', 'pipe', 'pipe']
})
} catch (err) {
// If git ls-remote fails, diagnose which credential sources are available
let diagnostics = []
// Check the gh CLI — the recommended authentication path
try {
execSync('gh --version', { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] })
try {
execSync('gh auth status', { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] })
diagnostics.push('- gh CLI is installed and authenticated')
} catch (_) {
diagnostics.push('- gh CLI is installed but not authenticated (run "gh auth login")')
}
} catch (_) {
diagnostics.push('- gh CLI not found (install it, then run "gh auth login")')
}
// Check git credential helper (gh configures this via "gh auth setup-git")
try {
const credentialOutput = execSync('git credential fill', {
encoding: 'utf8',
input: 'host=github.com\nprotocol=https\n',
stdio: ['pipe', 'pipe', 'pipe']
})
if (credentialOutput.includes('password=')) {
diagnostics.push('- git credential helper has github.com credentials')
} else {
diagnostics.push('- git credential helper found but no credentials')
}
} catch (_) {
diagnostics.push('- git credential helper not available or no credentials')
}
return `\n${ERROR}
Unable to access private GitHub repository "fs-webdev/${privateRepo}".
Current credential sources:
${diagnostics.join('\n ')}
To fix this, authenticate with the GitHub CLI:
1. Install the gh CLI if needed (macOS: "brew install gh")
2. Run "gh auth login" and choose: GitHub.com → HTTPS → authenticate Git → login with a web browser
3. Run "gh auth setup-git" so git uses gh for credentials
Full instructions: https://icseng.atlassian.net/wiki/spaces/DPT/pages/2352611334`
}
console.log('GitHub access works\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 ''
}