You've already forked hugo-extended
mirror of
https://github.com/jakejarvis/hugo-extended.git
synced 2025-10-16 12:14:26 -04:00
Switch to async methods (#128)
This commit is contained in:
12
lib/index.js
12
lib/index.js
@@ -1,12 +1,11 @@
|
||||
import fs from 'node:fs';
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import process from 'node:process';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import BinWrapper from '@xhmikosr/bin-wrapper';
|
||||
import { packageConfigSync } from 'pkg-conf';
|
||||
|
||||
const { hugoVersion } = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url)));
|
||||
import { packageConfig } from 'pkg-conf';
|
||||
|
||||
const { hugoVersion } = JSON.parse(await fs.readFile(new URL('../package.json', import.meta.url)));
|
||||
const destDir = path.join(fileURLToPath(new URL('../vendor', import.meta.url)));
|
||||
const binName = process.platform === 'win32' ? 'hugo.exe' : 'hugo';
|
||||
|
||||
@@ -41,11 +40,10 @@ const normalBin = (baseDownloadUrl) => new BinWrapper()
|
||||
.dest(destDir)
|
||||
.use(binName);
|
||||
|
||||
function main(projectRoot) {
|
||||
const config = packageConfigSync('hugo-bin', { cwd: projectRoot });
|
||||
async function main(projectRoot) {
|
||||
const config = await packageConfig('hugo-bin', { cwd: projectRoot });
|
||||
const extended = (process.env.HUGO_BIN_BUILD_TAGS || process.env.npm_config_hugo_bin_build_tags || config.buildTags) === 'extended';
|
||||
const downloadRepo = (process.env.HUGO_BIN_DOWNLOAD_REPO || process.env.npm_config_hugo_bin_download_repo || config.downloadRepo || 'https://github.com');
|
||||
|
||||
const baseDownloadUrl = `${downloadRepo}/gohugoio/hugo/releases/download/v${hugoVersion}/`;
|
||||
|
||||
return extended ? extendedBin(baseDownloadUrl) : normalBin(baseDownloadUrl);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import path from 'node:path';
|
||||
import process from 'node:process';
|
||||
import picocolors from 'picocolors';
|
||||
import bin from './index.js';
|
||||
import hugoBin from './index.js';
|
||||
|
||||
function getProjectRoot() {
|
||||
// `projectRoot` on postinstall could be INIT_CWD introduced in npm >= 5.4
|
||||
@@ -23,10 +23,17 @@ function getProjectRoot() {
|
||||
return cwd;
|
||||
}
|
||||
|
||||
bin(getProjectRoot()).run(['version'])
|
||||
.then(() => {
|
||||
async function main() {
|
||||
const projectRoot = getProjectRoot();
|
||||
const bin = await hugoBin(projectRoot);
|
||||
|
||||
bin.run(['version']).then(() => {
|
||||
console.log(picocolors.green('Hugo binary successfully installed!'));
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(picocolors.red(`${error.message}\nHugo binary installation failed!`));
|
||||
console.error(picocolors.red('Hugo binary installation failed!'));
|
||||
throw new Error(error);
|
||||
});
|
||||
}
|
||||
|
||||
main();
|
||||
|
Reference in New Issue
Block a user