1
mirror of https://github.com/jakejarvis/hugo-extended.git synced 2025-07-03 14:36:38 -04:00

allow binaries in vendor folder to be cached

aka: don't delete binaries in node_modules folder, since they shouldn't change anyways (unless the package is also updated)
This commit is contained in:
2020-02-18 17:40:51 -05:00
parent 434a6865cf
commit 6c87e415dc
10 changed files with 3588 additions and 129 deletions

View File

@ -7,22 +7,17 @@ const { hugoVersion } = require('../package.json');
const baseUrl = `https://github.com/gohugoio/hugo/releases/download/v${hugoVersion}/`;
// Default to extended Hugo, fall back to vanilla Hugo on unsupported platforms
const hugoBin = new binWrapper()
// eslint-disable-next-line new-cap
module.exports = new binWrapper()
.src(`${baseUrl}hugo_extended_${hugoVersion}_Linux-64bit.tar.gz`, 'linux', 'x64')
.src(`${baseUrl}hugo_extended_${hugoVersion}_macOS-64bit.tar.gz`, 'darwin', 'x64')
.src(`${baseUrl}hugo_extended_${hugoVersion}_Windows-64bit.zip`, 'win32', 'x64')
.src(`${baseUrl}hugo_${hugoVersion}_FreeBSD-32bit.tar.gz`, 'freebsd', 'x86')
.src(`${baseUrl}hugo_${hugoVersion}_FreeBSD-64bit.tar.gz`, 'freebsd', 'x64')
.src(`${baseUrl}hugo_${hugoVersion}_FreeBSD-ARM.tar.gz`, 'freebsd', 'arm')
.src(`${baseUrl}hugo_${hugoVersion}_Linux-32bit.tar.gz`, 'linux', 'x86')
.src(`${baseUrl}hugo_${hugoVersion}_Linux-ARM.tar.gz`, 'linux', 'arm')
.src(`${baseUrl}hugo_extended_${hugoVersion}_macOS-64bit.tar.gz`, 'darwin', 'x64')
.src(`${baseUrl}hugo_${hugoVersion}_macOS-32bit.tar.gz`, 'darwin', 'x86')
.src(`${baseUrl}hugo_extended_${hugoVersion}_Windows-64bit.zip`, 'win32', 'x64')
.src(`${baseUrl}hugo_${hugoVersion}_Windows-32bit.zip`, 'win32', 'x86')
.src(`${baseUrl}hugo_${hugoVersion}_FreeBSD-64bit.tar.gz`, 'freebsd', 'x64')
.src(`${baseUrl}hugo_${hugoVersion}_FreeBSD-32bit.tar.gz`, 'freebsd', 'x86')
.src(`${baseUrl}hugo_${hugoVersion}_FreeBSD-ARM.tar.gz`, 'freebsd', 'arm')
.dest(path.join(__dirname, '../vendor'))
.use(process.platform === 'win32' ? 'hugo.exe' : 'hugo');
// TODO: download checksums.txt file and validate package integrity
module.exports = function () {
return hugoBin;
};

View File

@ -1,30 +1,9 @@
'use strict';
const path = require('path');
const bin = require('.');
function getProjectRoot() {
// `projectRoot` on postinstall could be INIT_CWD introduced in npm >= 5.4
// see: https://github.com/npm/npm/issues/16990
const initCwd = process.env.INIT_CWD;
if (initCwd)
return initCwd;
// Fallback of getting INIT_CWD
const cwd = process.cwd();
const paths = cwd.split(path.sep);
// If `process.cwd` ends with 'node_modules/*' then get the dependent root directory,
// otherwise return the `cwd` (ordinary it will be the postinstall process of hugo-bin itself).
if (paths.length > 1 && paths[paths.length - 2] === 'node_modules')
return path.resolve('../../', cwd);
return cwd;
}
bin(getProjectRoot()).run(['version'])
.then(() => {
console.log('✔ Hugo installed successfully!');
})
.catch(error => {
console.error('✖ ERROR: Hugo installation failed. :(\n', error);
});
bin.run(['version']).then(() => {
console.log('✔ Hugo installed successfully!');
}).catch(error => {
console.error('✖ ERROR: Hugo installation failed. :(\n', error);
});