Skip to content

Commit 9dd62af

Browse files
feat(*): Rewrite install logic, add checksum and health checks, add additional params (#28)
- Rewrite install logic - Add checksum and health checks - Add support for more OS and architecture variants - Add support for all Hugo version - Add additional CLI params
1 parent 7979d58 commit 9dd62af

10 files changed

+978
-1350
lines changed

.github/workflows/ci.yml

+25
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,28 @@ jobs:
3737
run: npm ci
3838
- name: Lint
3939
run: npm run lint
40+
41+
test:
42+
name: Test
43+
needs: build
44+
runs-on: ${{ matrix.os }}
45+
strategy:
46+
fail-fast: false
47+
matrix:
48+
include:
49+
- os: ubuntu-20.04
50+
- os: windows-2019
51+
- os: macos-10.15
52+
steps:
53+
- name: Checkout repository
54+
uses: actions/checkout@v2
55+
- name: Setup NodeJS
56+
uses: actions/setup-node@v2
57+
with:
58+
node-version: 14.15.x
59+
- name: Install dependencies
60+
run: npm ci
61+
- name: Build
62+
run: npm run build
63+
- name: Test
64+
run: npm run test

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
test-output
2+
13
# Created by https://www.toptal.com/developers/gitignore/api/node,vscode
24
# Edit at https://www.toptal.com/developers/gitignore?templates=node,vscode
35

bin/hugo-installer.ts

+50-20
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,88 @@
11
#!/usr/bin/env node
22

3-
import * as objectPath from 'object-path';
3+
import objectPath from 'object-path';
4+
import * as os from 'os';
45
import * as path from 'path';
56
import * as yargs from 'yargs';
67

78
import { installHugo } from '../index';
89

910
// Read CLI parameters
10-
const argv: { [param: string]: any } = yargs
11+
const argv = yargs
1112
.version(false) // Disable default version flag (we're using our own in the next line)
12-
.option('version', {
13-
describe: 'Hugo version to install, or path to package.json value with the version',
14-
type: 'string',
15-
required: true,
13+
.option('arch', {
14+
choices: ['arm', 'arm64', 'x64', 'x86'],
15+
default: os.arch(),
16+
describe: 'System architecture that the binary should run on. It is recommended to use auto-detect by not using this option.',
1617
})
1718
.option('destination', {
18-
describe: 'Destination to download the Hugo binary into',
19-
type: 'string',
2019
default: 'bin/hugo',
20+
describe: 'Destination to download the Hugo binary into.',
21+
type: 'string',
22+
})
23+
.option('downloadUrl', {
24+
default: 'https://github.com/gohugoio/hugo/releases/download/',
25+
describe:
26+
'Source base URL from where the Hugo binary will be fetched. By default, GitHub will be used. When using a custom URL, make sure to replicate GitHub release asset URLs and append a trailing slash to the custom URL.',
27+
type: 'string',
2128
})
2229
.option('extended', {
23-
describe: 'Download Hugo extended',
30+
default: false,
31+
describe: 'Download Hugo extended version.',
32+
type: 'boolean',
33+
})
34+
.option('os', {
35+
choices: ['darwin', 'freebsd', 'linux', 'openbsd', 'win32'],
36+
default: os.platform(),
37+
describe: 'Operating system that the binary should run on. It is recommended to use auto-detect by not using this option.',
38+
})
39+
.option('skipChecksumCheck', {
40+
default: false,
41+
describe: 'Skip checksum checks for downloaded binaries. It is recommended to leave this option enabled.',
2442
type: 'boolean',
43+
})
44+
.option('skipHealthCheck', {
2545
default: false,
46+
describe: 'Skip health checks for downloaded binaries. It is recommended to leave this option enabled.',
47+
type: 'boolean',
48+
})
49+
.option('version', {
50+
describe:
51+
'Hugo version to install, or path to package.json value with the version. Make sure to use the exact version number defined in Hugo releases.',
52+
type: 'string',
53+
required: true,
2654
})
2755
.strict().argv;
2856

2957
// If the version does not have the format of a version number, assume it's an object path
3058
if (isNaN(parseFloat(argv.version))) {
31-
// Note: No is no other way in NodeJS to dynamically resolve and import the project's package.json file
59+
// Note: There is no other way in NodeJS to dynamically resolve and import the project's package.json file
3260
// eslint-disable-next-line @typescript-eslint/no-var-requires
3361
const packageJson: any = require(path.resolve(process.cwd(), 'package.json'));
3462
const packageJsonHugoVersion: string | null = objectPath.get(packageJson, argv.version, null);
3563
if (!packageJsonHugoVersion) {
36-
console.error(`Cannot find a hugo version in the package.json file at "${argv.version}"`);
64+
console.error(`The version "${argv.version}" is either invalid or not part of the "package.json" file.`);
3765
process.exit(1);
3866
}
3967
argv.version = packageJsonHugoVersion;
4068
}
4169

4270
// Run
43-
const versionString = `${argv.version}${argv.extended ? '_extended' : ''}`;
44-
console.log(`Download hugo binary (version "${versionString}") into "${argv.destination}" ...`);
45-
installHugo(argv.version, argv.destination)
71+
installHugo({
72+
arch: argv.arch,
73+
downloadUrl: argv.downloadUrl,
74+
destination: argv.destination,
75+
extended: argv.extended,
76+
os: argv.os,
77+
skipChecksumCheck: argv.skipChecksumCheck,
78+
skipHealthCheck: argv.skipHealthCheck,
79+
version: argv.version,
80+
})
4681
.then(() => {
4782
console.log('Success!');
4883
process.exit();
4984
})
5085
.catch((error: any) => {
51-
console.error('Error!');
52-
if (error.toString().indexOf('404') !== -1) {
53-
console.error(` -> It seems like the hugo version "${versionString}" does not exist.`);
54-
}
55-
console.log('');
56-
console.dir(error);
86+
console.log(error);
5787
process.exit(1);
5888
});

0 commit comments

Comments
 (0)