Skip to content

Commit e626eec

Browse files
committed
Merge branch 'upgrade-mkcert'
2 parents 2795b18 + 3882cb6 commit e626eec

13 files changed

+175
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [6.1.0] - 2020-11-04
9+
10+
### Changed
11+
12+
- Upgrade mkcert to version 1.4.2.
13+
- Include separate mkcert arm64 build.
14+
815
## [6.0.0] - 2020-11-03
916

1017
### Changed

bin/update-mkcert-bin.js

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
#!/usr/bin/env node
2+
3+
const https = require('https')
4+
const fs = require('fs-extra')
5+
const childProcess = require('child_process')
6+
const path = require('path')
7+
const assert = require('assert')
8+
9+
async function secureGet (url) {
10+
return new Promise((resolve, reject) => {
11+
https.get(url, response => {
12+
const statusCode = response.statusCode
13+
const location = response.headers.location
14+
15+
// Reject if it’s not one of the status codes we are testing.
16+
if (statusCode !== 200 && statusCode !== 302) {
17+
reject({statusCode})
18+
}
19+
20+
let body = ''
21+
response.on('data', _ => body += _)
22+
response.on('end', () => {
23+
resolve({statusCode, location, body})
24+
})
25+
})
26+
})
27+
}
28+
29+
async function secureStreamToFile (url, filePath) {
30+
return new Promise((resolve, reject) => {
31+
const fileStream = fs.createWriteStream(filePath)
32+
https.get(url, response => {
33+
response.pipe(fileStream)
34+
fileStream.on('finish', () => {
35+
fileStream.close()
36+
resolve()
37+
})
38+
fileStream.on('error', error => {
39+
fs.unlinkSync(filePath)
40+
reject(error)
41+
})
42+
})
43+
})
44+
}
45+
46+
// Compare two semver strings (nn.nn.nn) and return 0 if they’re equal,
47+
// 1 if a > b and -1 if a < b.
48+
function semverCompare (a, b) {
49+
const [aMajor, aMinor, aPatch] = a.split('.').map(string => parseInt(string))
50+
const [bMajor, bMinor, bPatch] = b.split('.').map(string => parseInt(string))
51+
52+
const aIsGreaterThanB =
53+
(aMajor > bMajor)
54+
|| (aMajor === bMajor && aMinor > bMinor)
55+
|| (aMajor === bMajor && aMinor === bMinor && aPatch > bPatch)
56+
57+
return (a === b) ? 0 : aIsGreaterThanB ? 1 : -1
58+
}
59+
60+
;(async ()=> {
61+
console.log('')
62+
console.log(' Update mkcert-bin script')
63+
console.log(' ════════════════════════')
64+
console.log('')
65+
66+
// Get the version of the current release.
67+
const mkcertBinariesDirectory = path.resolve(path.join(__dirname, '..', 'mkcert-bin'))
68+
69+
if (!fs.existsSync(mkcertBinariesDirectory)) {
70+
console.log(' Error: No mkcert-bin folder found. Exiting.\n')
71+
process.exit(1)
72+
}
73+
74+
const currentMkcertBinaries = fs.readdirSync(mkcertBinariesDirectory)
75+
76+
const currentMkcertVersionMatch = currentMkcertBinaries[0].match(/^mkcert-v(\d+\.\d+\.\d+)-/)
77+
if (currentMkcertVersionMatch === null) {
78+
console.log(' Error: Unable to ascertain current mkcert version. Exiting.\n')
79+
process.exit(1)
80+
}
81+
82+
const currentMkcertVersion = currentMkcertVersionMatch[1]
83+
84+
console.log(` Current mkcert version: ${currentMkcertVersion}`)
85+
86+
// Get the location of the latest release page.
87+
const latestMkcertReleasesPage = await secureGet('https://github.com/FiloSottile/mkcert/releases/latest')
88+
89+
assert (latestMkcertReleasesPage.location !== undefined, 'Location must exist (302 redirect).')
90+
91+
// Get the latest release page.
92+
const actualLatestReleasePage = await secureGet(latestMkcertReleasesPage.location)
93+
94+
assert(actualLatestReleasePage.location === undefined, 'Actual page should not be a redirect.')
95+
96+
const page = actualLatestReleasePage.body
97+
98+
const versionMatch = page.match(/href=\"\/FiloSottile\/mkcert\/releases\/tag\/v(\d+\.\d+\.\d+)\"/)
99+
100+
assert(versionMatch !== null, 'Version should be found on page.')
101+
102+
const latestMkcertVersion = versionMatch[1]
103+
104+
assert(latestMkcertVersion !== undefined, 'Version capturing group should exist.')
105+
106+
console.log(` Latest mkcert version : ${latestMkcertVersion}\n`)
107+
108+
switch(semverCompare(currentMkcertVersion, latestMkcertVersion)) {
109+
case 0:
110+
console.log('You already have the latest release version of mkcert included in auto-encrypt-localhost. Exiting.')
111+
process.exit()
112+
113+
case 1:
114+
console.log('Warning: It appears you have a later version than the release version included. Exiting.')
115+
process.exit()
116+
}
117+
118+
console.log(' Upgrading the binaries to the latest version…\n')
119+
120+
// Delete and recreate the mkcert-bin folder.
121+
fs.removeSync(mkcertBinariesDirectory)
122+
fs.mkdirpSync(mkcertBinariesDirectory)
123+
124+
const mkcertReleaseUrlPrefix = `https://github.com/FiloSottile/mkcert/releases/download/v${latestMkcertVersion}`
125+
126+
const latestMkcertBinaries = [
127+
{
128+
platform: 'Linux AMD 64-bit',
129+
binaryName: `mkcert-v${latestMkcertVersion}-linux-amd64`
130+
},
131+
{
132+
platform: 'Linux ARM',
133+
binaryName: `mkcert-v${latestMkcertVersion}-linux-arm`
134+
},
135+
{
136+
platform: 'Linux ARM64',
137+
binaryName: `mkcert-v${latestMkcertVersion}-linux-arm64`
138+
},
139+
{
140+
platform: 'Darwin (masOS) AMD 64-bit',
141+
binaryName: `mkcert-v${latestMkcertVersion}-darwin-amd64`
142+
},
143+
{
144+
platform: 'Windows AMD 64-bit',
145+
binaryName: `mkcert-v${latestMkcertVersion}-windows-amd64.exe`
146+
}
147+
]
148+
149+
for (mkcertBinary of latestMkcertBinaries) {
150+
const mkcertBinaryUrl = `${mkcertReleaseUrlPrefix}/${mkcertBinary.binaryName}`
151+
152+
console.log(` ${mkcertBinary.platform}`)
153+
console.log(` ${'─'.repeat(mkcertBinary.platform.length)}`)
154+
155+
console.log(' ├ Downloading binary…')
156+
157+
const binaryRedirectUrl = (await secureGet(mkcertBinaryUrl)).location
158+
const binaryPath = path.join(mkcertBinariesDirectory, mkcertBinary.binaryName)
159+
await secureStreamToFile(binaryRedirectUrl, binaryPath)
160+
161+
console.log(` ╰ Upgraded to ${mkcertBinary.binaryName}\n`)
162+
}
163+
164+
console.log(' Done.\n')
165+
})()

lib/mkcertBinaryForThisMachine.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function mkcertBinaryForThisMachine (settingsPath) {
2020

2121
const architectureMap = {
2222
arm: 'arm',
23-
arm64: 'arm',
23+
arm64: 'arm64',
2424
x64: 'amd64'
2525
}
2626

@@ -30,7 +30,7 @@ function mkcertBinaryForThisMachine (settingsPath) {
3030
if (platform === undefined) throw new Error('Unsupported platform', os.platform())
3131
if (architecture === undefined) throw new Error('Unsupported architecture', os.arch())
3232

33-
const mkcertVersion = '1.4.1'
33+
const mkcertVersion = '1.4.2'
3434

3535
const mkcertBinaryName = `mkcert-v${mkcertVersion}-${platform}-${architecture}`
3636
const mkcertBinaryRelativePath = path.join('..', 'mkcert-bin', mkcertBinaryName)
-5.29 MB
Binary file not shown.
-4.7 MB
Binary file not shown.

mkcert-bin/mkcert-v1.4.1-linux-arm

-4.21 MB
Binary file not shown.
-4.8 MB
Binary file not shown.
5.1 MB
Binary file not shown.
4.6 MB
Binary file not shown.

mkcert-bin/mkcert-v1.4.2-linux-arm

4.15 MB
Binary file not shown.

0 commit comments

Comments
 (0)