forked from google/docsy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.mjs
56 lines (46 loc) · 1.57 KB
/
index.mjs
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
// Runs `hugo mod get <module>@<vers>` for Docsy module dependencies.
// It gets dependency versions from `package.json`.
import fs from 'fs';
import { execSync } from 'child_process';
const packageJson = readPackageJson();
let exitStatus = 0;
const exit = () => process.exit(exitStatus);
function getHugoModule(npmPkgNm, hugoModuleRefAtV) {
try {
// Extract module version
const pkgVers = packageJson.dependencies[npmPkgNm];
if (!pkgVers) {
throw new Error(`${npmPkgNm} not found in dependencies`);
}
if (!/^\d/.test(pkgVers)) {
const msg = `${npmPkgNm} version must be exact (start with a number), not: ${pkgVers}`;
throw new Error(msg);
}
const command = `hugo mod get ${hugoModuleRefAtV}${pkgVers}`;
console.log(`> ${command}`);
const output = execSync(command);
console.log(output.toString());
} catch (error) {
console.error(`ERROR: ${error.message}\n`);
exitStatus = 1;
}
}
function readPackageJson() {
try {
const packageJsonData = fs.readFileSync('package.json', 'utf8');
return JSON.parse(packageJsonData);
} catch (error) {
console.error('FAILED to read package.json:', error.message);
exit();
}
}
const packagesToUpdate = [
// NPM package name, `Hugo module name@` optionally follow by `v` if needed
['@fortawesome/fontawesome-free', 'github.com/FortAwesome/Font-Awesome@'],
['bootstrap', 'github.com/twbs/bootstrap@v']
];
packagesToUpdate.forEach(([npmPkgNm, hugoModuleRefAtV]) => {
getHugoModule(npmPkgNm, hugoModuleRefAtV, packageJson);
});
exit();
// cSpell:ignore hugo twbs