1
mirror of https://github.com/jakejarvis/hugo-extended.git synced 2025-04-26 12:18:29 -04:00
hugo-extended/lib/install.js
XhmikosR a24614e635 Replace logalot with signale.
Less dependencies.
2018-10-07 21:02:18 +09:00

31 lines
968 B
JavaScript

const path = require('path');
const signale = require('signale');
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 end with 'node_modules/*' then get the dependent root directory,
// otherwise returns 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(() => {
signale.success('Hugo binary is installed successfully');
})
.catch(err => {
signale.fatal(err.message);
signale.fatal('Hugo binary installation failed');
});