Skip to content

Commit

Permalink
Update index.mjs
Browse files Browse the repository at this point in the history
  • Loading branch information
chalin committed Nov 10, 2023
1 parent 7b3d503 commit a8b993d
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions tools/getHugoModules/index.mjs
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
// Runs `hugo mod get <module>@<vers>` for Docsy module dependencies.
// Get dependencies versions from `package.json`.
// 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 packageVersion = packageJson.dependencies[npmPkgNm];
if (!packageVersion) {
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}${packageVersion}`;
const command = `hugo mod get ${hugoModuleRefAtV}${pkgVers}`;
console.log(`> ${command}`);
const output = execSync(command);
console.log(output.toString());
} catch (error) {
console.error('An error occurred:', error.message);
console.error(`ERROR: ${error.message}\n`);
exitStatus = 1;
}
}
Expand All @@ -30,13 +36,11 @@ function readPackageJson() {
const packageJsonData = fs.readFileSync('package.json', 'utf8');
return JSON.parse(packageJsonData);
} catch (error) {
console.error('Failed to read package.json:', error.message);
console.error('FAILED to read package.json:', error.message);
exit();
}
}

const exit = () => process.exit(exitStatus);

const packagesToUpdate = [
// NPM package name, `Hugo module name@` optionally follow by `v` if needed
['@fortawesome/fontawesome-free', 'github.com/FortAwesome/Font-Awesome@'],
Expand Down

0 comments on commit a8b993d

Please sign in to comment.