mirror of
https://github.com/jakejarvis/hugo-extended.git
synced 2025-04-25 15:35:22 -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:
parent
434a6865cf
commit
6c87e415dc
@ -5,8 +5,6 @@ root = true
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
3
.gitattributes
vendored
3
.gitattributes
vendored
@ -1 +1,2 @@
|
||||
* text=auto
|
||||
# Set default behavior to automatically normalize line endings
|
||||
* text=auto eol=lf
|
||||
|
25
README.md
25
README.md
@ -10,41 +10,28 @@ npm install hugo-extended --save-dev
|
||||
yarn add hugo-extended --dev
|
||||
```
|
||||
|
||||
`hugo-extended` defaults to the [extended version](https://gohugo.io/getting-started/installing/#linux) of Hugo on [supported platforms](https://github.com/gohugoio/hugo/releases), and falls back to vanilla Hugo automatically if unsupported.
|
||||
`hugo-extended` defaults to the [extended version](https://gohugo.io/troubleshooting/faq/#i-get-tocss--this-feature-is-not-available-in-your-current-hugo-version) of Hugo on [supported platforms](https://github.com/gohugoio/hugo/releases), and automatically falls back to vanilla Hugo if unsupported (mainly on 32-bit systems).
|
||||
|
||||
## Usage
|
||||
|
||||
See the [Hugo Documentation](https://gohugo.io/documentation/) for additional functionality.
|
||||
The following examples simply refer to executing Hugo as a local Node dependency. See the [official Hugo docs](https://gohugo.io/documentation/) for guidance on actual Hugo usage.
|
||||
|
||||
### package.json
|
||||
### via CLI / `package.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"scripts": {
|
||||
"build": "hugo",
|
||||
"start": "hugo serve",
|
||||
"create": "hugo new"
|
||||
"start": "hugo server --buildDrafts --buildFuture --port 1313"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### CLI:
|
||||
|
||||
```sh
|
||||
$(npm bin)/hugo --help
|
||||
npm run create -- post/my-new-post.md
|
||||
npm start
|
||||
```
|
||||
|
||||
or on Windows:
|
||||
|
||||
```bat
|
||||
for /f "delims=" %F in ('npm bin') do call "%F\hugo" help
|
||||
npm run create -- post/my-new-post.md
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### API
|
||||
### via API:
|
||||
|
||||
```js
|
||||
const { execFile } = require('child_process');
|
||||
|
4
cli.js
4
cli.js
@ -5,7 +5,5 @@
|
||||
const { spawn } = require('child_process');
|
||||
const hugo = require('.');
|
||||
|
||||
const input = process.argv.slice(2);
|
||||
|
||||
spawn(hugo, input, { stdio: 'inherit' })
|
||||
spawn(hugo, process.argv.slice(2), { stdio: 'inherit' })
|
||||
.on('exit', process.exit);
|
||||
|
2
index.js
2
index.js
@ -1,3 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./lib')(process.cwd()).path();
|
||||
module.exports = require('./lib').path();
|
||||
|
19
lib/index.js
19
lib/index.js
@ -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;
|
||||
};
|
||||
|
@ -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);
|
||||
});
|
||||
|
3589
package-lock.json
generated
3589
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
35
package.json
35
package.json
@ -26,19 +26,16 @@
|
||||
],
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"bin-wrapper": "^4.1.0",
|
||||
"rimraf": "^3.0.1"
|
||||
"bin-wrapper": "^4.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"bin-check": "^4.1.0",
|
||||
"eslint": "^6.8.0",
|
||||
"mocha": "^7.0.1"
|
||||
"mocha": "*",
|
||||
"xo": "*"
|
||||
},
|
||||
"scripts": {
|
||||
"eslint": "eslint .",
|
||||
"mocha": "mocha",
|
||||
"test": "npm run eslint && npm run mocha",
|
||||
"postinstall": "rimraf vendor && node lib/install"
|
||||
"postinstall": "node lib/install.js",
|
||||
"test": "xo && mocha"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
@ -51,21 +48,15 @@
|
||||
"bin": {
|
||||
"hugo": "cli.js"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "eslint:recommended",
|
||||
"env": {
|
||||
"es6": true,
|
||||
"node": true
|
||||
},
|
||||
"xo": {
|
||||
"envs": [
|
||||
"es6",
|
||||
"node"
|
||||
],
|
||||
"space": true,
|
||||
"rules": {
|
||||
"prefer-destructuring": [
|
||||
"error",
|
||||
{
|
||||
"object": true,
|
||||
"array": false
|
||||
}
|
||||
],
|
||||
"strict": "error"
|
||||
"object-curly-spacing": "off",
|
||||
"promise/prefer-await-to-then": "warn"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,10 @@ it('Hugo exists and runs?', () => {
|
||||
// Print additional build environment variables if check successful
|
||||
if (works) {
|
||||
execFile(hugoBin, ['env'], (error, stdout) => {
|
||||
if (error) throw error;
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
console.log(stdout);
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user