1
mirror of https://github.com/jakejarvis/hugo-extended.git synced 2025-07-19 09:45:30 -04:00

Switch to ESM

This commit is contained in:
XhmikosR
2021-12-07 10:34:35 +02:00
parent e524abe8fa
commit e4b83248a0
8 changed files with 131 additions and 209 deletions

View File

@@ -1,12 +1,14 @@
'use strict';
import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import { fileURLToPath } from 'node:url';
import BinWrapper from 'bin-wrapper';
import { packageConfigSync } from 'pkg-conf';
const path = require('path');
const BinWrapper = require('bin-wrapper');
const pkgConf = require('pkg-conf');
const { hugoVersion } = require('../package.json');
const { hugoVersion } = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url)));
const baseUrl = `https://github.com/gohugoio/hugo/releases/download/v${hugoVersion}/`;
const destDir = path.join(__dirname, '../vendor/');
const destDir = path.join(fileURLToPath(new URL('../vendor', import.meta.url)));
const binName = process.platform === 'win32' ? 'hugo.exe' : 'hugo';
const extendedBin = new BinWrapper()
@@ -44,8 +46,11 @@ const normalBin = new BinWrapper()
.dest(destDir)
.use(binName);
module.exports = projectRoot => {
const config = pkgConf.sync('hugo-bin', { cwd: projectRoot });
function main(projectRoot) {
const config = packageConfigSync('hugo-bin', { cwd: projectRoot });
const extended = (process.env.HUGO_BIN_BUILD_TAGS || process.env.npm_config_hugo_bin_build_tags || config.buildTags) === 'extended';
return extended ? extendedBin : normalBin;
};
}
export default main;