Skip to content

Commit

Permalink
Support Hugo extended (#65)
Browse files Browse the repository at this point in the history
* wip: Support Hugo extended

* fallback support, update readme.md

* fixup! wip: Support Hugo extended
  • Loading branch information
satoshun00 authored Oct 7, 2018
1 parent 5214d55 commit 1113135
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 7 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
npm install --save-dev hugo-bin
```

hugo-bin now supports [Extended version of Hugo](https://github.com/gohugoio/hugo/releases/tag/v0.43). See [Installation options](#installation-options) for more details.

## Usage

### API
Expand Down Expand Up @@ -42,6 +44,46 @@ npm run create -- 'post/my-new-post' # see below 'npm-run-script'

See the [Hugo Documentation](https://gohugo.io/) for more information.

## Installation options

hugo-bin supports options to change the variation of Hugo binaries.

Each option can be configured in the `hugo-bin` section of your `package.json`:

```json
{
"name": "your-package",
"version": "0.0.1",
"hugo-bin": {
"buildTags": "extended"
}
}
```

Also as local or global [.npmrc](https://docs.npmjs.com/files/npmrc) configuration file:

```ini
hugo_bin_build_tags = "extended"
```

Also as environment variable:

```sh
export HUGO_BIN_BUILD_TAGS="extended"
```

**Note that you have to run `npm install hugo-bin` to re-install hugo-bin itself, if you change any one of these options.**

### Options

#### buildTags

Default: `""`

Set it to `extended` to download the [extended version](https://github.com/gohugoio/hugo/releases/tag/v0.43) binary.

If this is set to `extended` but it's not available for the user's platform, then the normal version will be downloaded instead.

## Supported versions

See [the package.json commit history](https://github.com/fenneclab/hugo-bin/commits/master/package.json).
Expand Down
Empty file modified cli.js
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./lib').path();
module.exports = require('./lib')(process.cwd()).path();
26 changes: 23 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path');
const BinWrapper = require('bin-wrapper');
const pkgConf = require('pkg-conf');
const pkg = require('../package');

const hugoVersion = pkg.hugoVersion;
Expand Down Expand Up @@ -29,9 +30,23 @@ const binNameMap = {
x64: 'hugo.exe'
}
};
const dest = path.join(__dirname, '../vendor');
const binName = (binNameMap[process.platform] && binNameMap[process.platform][process.arch]) || '';

module.exports = new BinWrapper()
const extendedBin = 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')
// Falling back to normal version on non supported platforms
.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_${hugoVersion}_macOS-32bit.tar.gz`, 'darwin', 'x86')
.src(`${baseUrl}hugo_${hugoVersion}_Windows-32bit.zip`, 'win32', 'x86')
.dest(dest)
.use(binName);
const normalBin = new BinWrapper()
.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')
Expand All @@ -42,5 +57,10 @@ module.exports = new BinWrapper()
.src(`${baseUrl}hugo_${hugoVersion}_macOS-64bit.tar.gz`, 'darwin', 'x64')
.src(`${baseUrl}hugo_${hugoVersion}_Windows-32bit.zip`, 'win32', 'x86')
.src(`${baseUrl}hugo_${hugoVersion}_Windows-64bit.zip`, 'win32', 'x64')
.dest(path.join(__dirname, '../vendor'))
.dest(dest)
.use(binName);
module.exports = projectRoot => {
const config = pkgConf.sync('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;
};
21 changes: 20 additions & 1 deletion lib/install.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
const path = require('path');
const bin = require('./');
const log = require('logalot');

bin.run(['version'])
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(() => {
log.success('Hugo binary is installed successfully');
})
Expand Down
86 changes: 86 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "hugo-bin",
"version": "0.30.0",
"hugoVersion": "0.42.2",
"hugoVersion": "0.43",
"description": "Binary wrapper for Hugo",
"repository": "fenneclab/hugo-bin",
"author": "satoshun00 <[email protected]>",
Expand All @@ -13,7 +13,8 @@
"dependencies": {
"bin-wrapper": "4.0.0",
"del-cli": "1.1.0",
"logalot": "2.1.0"
"logalot": "2.1.0",
"pkg-conf": "2.1.0"
},
"devDependencies": {
"bin-check": "4.1.0",
Expand Down

0 comments on commit 1113135

Please sign in to comment.