mirror of
https://github.com/jakejarvis/hugo-extended.git
synced 2026-08-03 18:55:21 -04:00
feat(getBinalyName): add support for Hugo v0.16 (#2)
This commit is contained in:
@@ -42,6 +42,23 @@ npm run create -- 'post/my-new-post' # see below 'npm-run-script'
|
|||||||
|
|
||||||
See the [Hugo Documentation](https://gohugo.io/) for more information.
|
See the [Hugo Documentation](https://gohugo.io/) for more information.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
This can be form of a `hugoBin` field in a `package.json` file.
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"name": "some-package",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"hugoBin": {
|
||||||
|
"hugoVersion": "0.15"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- `hugoVersion` - Hugo binary version (defualt: See [`hugo-bin/package.json`](package.json) file).
|
||||||
|
The supported version is `>=0.10`.
|
||||||
|
|
||||||
## Full example
|
## Full example
|
||||||
|
|
||||||
- [fenneclab/blog.fenneclab.com](https://github.com/fenneclab/blog.fenneclab.com)
|
- [fenneclab/blog.fenneclab.com](https://github.com/fenneclab/blog.fenneclab.com)
|
||||||
|
|||||||
+7
-6
@@ -1,13 +1,14 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const BinWrapper = require('bin-wrapper');
|
const BinWrapper = require('bin-wrapper');
|
||||||
|
const pkgConf = require('pkg-conf');
|
||||||
const getBinalyName = require('./getBinalyName');
|
const getBinalyName = require('./getBinalyName');
|
||||||
|
|
||||||
const HUGO_VERSION = '0.15';
|
const hugoVersion = pkgConf.sync('hugoBin').hugoVersion;
|
||||||
const baseUrl = `https://github.com/spf13/hugo/releases/download/v${HUGO_VERSION}/`;
|
const baseUrl = `https://github.com/spf13/hugo/releases/download/v${hugoVersion}/`;
|
||||||
const binalyNames = getBinalyName(HUGO_VERSION);
|
|
||||||
|
const binalyNames = getBinalyName(hugoVersion, process.platform, process.arch);
|
||||||
|
|
||||||
module.exports = new BinWrapper()
|
module.exports = new BinWrapper()
|
||||||
.src(`${baseUrl}${binalyNames.binaryName}${binalyNames.comp}`)
|
.src(`${baseUrl}${binalyNames.comp}`)
|
||||||
.dest(path.join(__dirname, '../vendor'))
|
.dest(path.join(__dirname, '../vendor'))
|
||||||
.use(`${binalyNames.binaryName}${binalyNames.exe}`);
|
.use(`${binalyNames.exe}`);
|
||||||
|
|||||||
+66
-33
@@ -1,40 +1,73 @@
|
|||||||
const PLATFORMS = {
|
const semver = require('semver');
|
||||||
darwin: 'darwin',
|
// see: https://github.com/spf13/hugo/releases
|
||||||
freebsd: 'freebsd',
|
|
||||||
linux: 'linux',
|
|
||||||
// sunos: '', not supported
|
|
||||||
win32: 'windows'
|
|
||||||
};
|
|
||||||
|
|
||||||
const ARCHS = {
|
const packageMap = version => ({
|
||||||
arm: 'arm',
|
darwin: {
|
||||||
ia32: '386',
|
arm: `hugo_${version}_darwin-arm32.tgz`,
|
||||||
x64: 'amd64'
|
ia32: `hugo_${version}_osx-32bit.tgz`,
|
||||||
};
|
x64: `hugo_${version}_osx-64bit.tgz`
|
||||||
|
},
|
||||||
|
freebsd: {
|
||||||
|
arm: `hugo_${version}_freebsd-arm32.tgz`,
|
||||||
|
ia32: `hugo_${version}_freebsd-32bit.tgz`,
|
||||||
|
x64: `hugo_${version}_freebsd-64bit.tgz`
|
||||||
|
},
|
||||||
|
linux: {
|
||||||
|
arm: `hugo_${version}_linux-arm64.tgz`,
|
||||||
|
ia32: `hugo_${version}_linux-32bit.tgz`,
|
||||||
|
x64: `hugo_${version}_linux-64bit.tgz`
|
||||||
|
},
|
||||||
|
sunos: {
|
||||||
|
x64: `hugo_${version}_solaris-64bit.tgz`
|
||||||
|
},
|
||||||
|
win32: {
|
||||||
|
ia32: `hugo_${version}_windows-32bit.zip`,
|
||||||
|
x64: `hugo_${version}_windows-64bit.zip`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const COMPS = {
|
const legacyPackageMap = version => ({
|
||||||
darwin: '.zip',
|
darwin: {
|
||||||
freebsd: '.zip',
|
ia32: `hugo_${version}_darwin_386.zip`,
|
||||||
linux: '.tar.gz',
|
x64: `hugo_${version}_darwin_amd64.zip`
|
||||||
// sunos: '', not supported
|
},
|
||||||
win32: '.zip'
|
freebsd: {
|
||||||
};
|
arm: `hugo_${version}_freebsd_arm.zip`,
|
||||||
|
ia32: `hugo_${version}_freebsd_386.zip`,
|
||||||
|
x64: `hugo_${version}_freebsd_amd64.zip`
|
||||||
|
},
|
||||||
|
linux: {
|
||||||
|
arm: `hugo_${version}_linux_arm.tar.gz`,
|
||||||
|
ia32: `hugo_${version}_linux_386.tar.gz`,
|
||||||
|
x64: `hugo_${version}_linux_amd64.tar.gz`
|
||||||
|
},
|
||||||
|
sunos: {}, // not supported
|
||||||
|
win32: {
|
||||||
|
ia32: `hugo_${version}_windows_386.zip`,
|
||||||
|
x64: `hugo_${version}_windows_amd64.zip`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const EXES = {
|
module.exports = (version, plat, arch) => {
|
||||||
darwin: '',
|
const validSemverVersion = `${version}.0`;
|
||||||
freebsd: '',
|
if (semver.lt(validSemverVersion, '0.10.0')) {
|
||||||
linux: '',
|
throw new Error(`hugoVersion<0.10 is not supported: ${version}`);
|
||||||
// sunos: '', not supported
|
}
|
||||||
win32: 'windows'
|
// exceptionally when...
|
||||||
};
|
if (version === '0.15' && plat === 'win32' && arch === 'ia32') {
|
||||||
|
return {
|
||||||
module.exports = version => {
|
comp: 'hugo_0.15_windows_386_32-bit-only.zip',
|
||||||
const platform = PLATFORMS[process.platform];
|
exe: 'hugo_0.15_windows_386.exe'
|
||||||
const arch = ARCHS[process.arch];
|
}
|
||||||
const comp = COMPS[process.platform];
|
}
|
||||||
const exe = EXES[process.platform];
|
const isLegacy = semver.lte(validSemverVersion, '0.15.0');
|
||||||
|
const comp = isLegacy ? legacyPackageMap(version)[plat][arch] : packageMap(version)[plat][arch];
|
||||||
|
if (!comp) {
|
||||||
|
throw new Error(`Can't detect binaly name. Check your platform: ${plat}, arch: ${arch}, version: ${version}.
|
||||||
|
For more info: https://github.com/fenneclab/hugo-bin/blob/master/test/getBinalyName.js`);
|
||||||
|
}
|
||||||
|
const exe = (isLegacy ? `${comp.replace(/\.zip|\.tar\.gz/, '')}` : 'hugo') + (plat === 'win32' ? '.exe' : '');
|
||||||
return {
|
return {
|
||||||
binaryName: `hugo_${version}_${platform}_${arch}`,
|
|
||||||
comp,
|
comp,
|
||||||
exe
|
exe
|
||||||
};
|
};
|
||||||
|
|||||||
+8
-3
@@ -4,9 +4,8 @@
|
|||||||
"description": "Binary wrapper for Hugo",
|
"description": "Binary wrapper for Hugo",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"pretest": "rm -rf vendor && npm run postinstall",
|
|
||||||
"test": "eslint . && mocha",
|
"test": "eslint . && mocha",
|
||||||
"postinstall": "node lib/install"
|
"postinstall": "rm -rf vendor && node lib/install"
|
||||||
},
|
},
|
||||||
"repository": "fenneclab/hugo-bin",
|
"repository": "fenneclab/hugo-bin",
|
||||||
"author": "satoshun00 <shun.sato@fenneclab.com>",
|
"author": "satoshun00 <shun.sato@fenneclab.com>",
|
||||||
@@ -20,6 +19,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"bin-check": "3.0.0",
|
"bin-check": "3.0.0",
|
||||||
"eslint": "2.11.0",
|
"eslint": "2.11.0",
|
||||||
|
"lodash": "4.13.1",
|
||||||
"mocha": "2.5.3"
|
"mocha": "2.5.3"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
@@ -37,6 +37,11 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bin-wrapper": "3.0.2",
|
"bin-wrapper": "3.0.2",
|
||||||
"logalot": "2.1.0"
|
"logalot": "2.1.0",
|
||||||
|
"pkg-conf": "1.1.3",
|
||||||
|
"semver": "5.1.0"
|
||||||
|
},
|
||||||
|
"hugoBin": {
|
||||||
|
"hugoVersion": "0.14"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,226 @@
|
|||||||
|
const _ = require('lodash');
|
||||||
|
const assert = require('assert');
|
||||||
|
const getBinalyName = require('../lib/getBinalyName');
|
||||||
|
|
||||||
|
describe('#getBinalyName', () => {
|
||||||
|
_.flatMapDeep([
|
||||||
|
['0.10', '0.11', '0.12', '0.13', '0.14', '0.15'].map(version => [{
|
||||||
|
version,
|
||||||
|
platform: 'darwin',
|
||||||
|
arch: 'ia32',
|
||||||
|
expected: {
|
||||||
|
comp: `hugo_${version}_darwin_386.zip`,
|
||||||
|
exe: `hugo_${version}_darwin_386`
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
version,
|
||||||
|
platform: 'darwin',
|
||||||
|
arch: 'x64',
|
||||||
|
expected: {
|
||||||
|
comp: `hugo_${version}_darwin_amd64.zip`,
|
||||||
|
exe: `hugo_${version}_darwin_amd64`
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
version,
|
||||||
|
platform: 'freebsd',
|
||||||
|
arch: 'arm',
|
||||||
|
expected: {
|
||||||
|
comp: `hugo_${version}_freebsd_arm.zip`,
|
||||||
|
exe: `hugo_${version}_freebsd_arm`
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
version,
|
||||||
|
platform: 'freebsd',
|
||||||
|
arch: 'ia32',
|
||||||
|
expected: {
|
||||||
|
comp: `hugo_${version}_freebsd_386.zip`,
|
||||||
|
exe: `hugo_${version}_freebsd_386`
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
version,
|
||||||
|
platform: 'freebsd',
|
||||||
|
arch: 'x64',
|
||||||
|
expected: {
|
||||||
|
comp: `hugo_${version}_freebsd_amd64.zip`,
|
||||||
|
exe: `hugo_${version}_freebsd_amd64`
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
version,
|
||||||
|
platform: 'linux',
|
||||||
|
arch: 'arm',
|
||||||
|
expected: {
|
||||||
|
comp: `hugo_${version}_linux_arm.tar.gz`,
|
||||||
|
exe: `hugo_${version}_linux_arm`
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
version,
|
||||||
|
platform: 'linux',
|
||||||
|
arch: 'ia32',
|
||||||
|
expected: {
|
||||||
|
comp: `hugo_${version}_linux_386.tar.gz`,
|
||||||
|
exe: `hugo_${version}_linux_386`
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
version,
|
||||||
|
platform: 'linux',
|
||||||
|
arch: 'x64',
|
||||||
|
expected: {
|
||||||
|
comp: `hugo_${version}_linux_amd64.tar.gz`,
|
||||||
|
exe: `hugo_${version}_linux_amd64`
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
version,
|
||||||
|
platform: 'win32',
|
||||||
|
arch: 'ia32',
|
||||||
|
expected: {
|
||||||
|
comp: version === '0.15' ? `hugo_${version}_windows_386_32-bit-only.zip` : `hugo_${version}_windows_386.zip`,
|
||||||
|
exe: `hugo_${version}_windows_386.exe`
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
version,
|
||||||
|
platform: 'win32',
|
||||||
|
arch: 'x64',
|
||||||
|
expected: {
|
||||||
|
comp: `hugo_${version}_windows_amd64.zip`,
|
||||||
|
exe: `hugo_${version}_windows_amd64.exe`
|
||||||
|
}
|
||||||
|
}]),
|
||||||
|
['0.16'].map(version => [{
|
||||||
|
version,
|
||||||
|
platform: 'darwin',
|
||||||
|
arch: 'arm',
|
||||||
|
expected: {
|
||||||
|
comp: `hugo_${version}_darwin-arm32.tgz`,
|
||||||
|
exe: 'hugo'
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
version,
|
||||||
|
platform: 'darwin',
|
||||||
|
arch: 'ia32',
|
||||||
|
expected: {
|
||||||
|
comp: `hugo_${version}_osx-32bit.tgz`,
|
||||||
|
exe: 'hugo'
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
version,
|
||||||
|
platform: 'darwin',
|
||||||
|
arch: 'x64',
|
||||||
|
expected: {
|
||||||
|
comp: `hugo_${version}_osx-64bit.tgz`,
|
||||||
|
exe: 'hugo'
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
version,
|
||||||
|
platform: 'freebsd',
|
||||||
|
arch: 'arm',
|
||||||
|
expected: {
|
||||||
|
comp: `hugo_${version}_freebsd-arm32.tgz`,
|
||||||
|
exe: 'hugo'
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
version,
|
||||||
|
platform: 'freebsd',
|
||||||
|
arch: 'ia32',
|
||||||
|
expected: {
|
||||||
|
comp: `hugo_${version}_freebsd-32bit.tgz`,
|
||||||
|
exe: 'hugo'
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
version,
|
||||||
|
platform: 'freebsd',
|
||||||
|
arch: 'x64',
|
||||||
|
expected: {
|
||||||
|
comp: `hugo_${version}_freebsd-64bit.tgz`,
|
||||||
|
exe: 'hugo'
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
version,
|
||||||
|
platform: 'linux',
|
||||||
|
arch: 'arm',
|
||||||
|
expected: {
|
||||||
|
comp: `hugo_${version}_linux-arm64.tgz`,
|
||||||
|
exe: 'hugo'
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
version,
|
||||||
|
platform: 'linux',
|
||||||
|
arch: 'ia32',
|
||||||
|
expected: {
|
||||||
|
comp: `hugo_${version}_linux-32bit.tgz`,
|
||||||
|
exe: 'hugo'
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
version,
|
||||||
|
platform: 'linux',
|
||||||
|
arch: 'x64',
|
||||||
|
expected: {
|
||||||
|
comp: `hugo_${version}_linux-64bit.tgz`,
|
||||||
|
exe: 'hugo'
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
version,
|
||||||
|
platform: 'sunos',
|
||||||
|
arch: 'x64',
|
||||||
|
expected: {
|
||||||
|
comp: `hugo_${version}_solaris-64bit.tgz`,
|
||||||
|
exe: 'hugo'
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
version,
|
||||||
|
platform: 'win32',
|
||||||
|
arch: 'ia32',
|
||||||
|
expected: {
|
||||||
|
comp: `hugo_${version}_windows-32bit.zip`,
|
||||||
|
exe: 'hugo.exe'
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
version,
|
||||||
|
platform: 'win32',
|
||||||
|
arch: 'x64',
|
||||||
|
expected: {
|
||||||
|
comp: `hugo_${version}_windows-64bit.zip`,
|
||||||
|
exe: 'hugo.exe'
|
||||||
|
}
|
||||||
|
}])
|
||||||
|
]).forEach(test => {
|
||||||
|
it(`should return hugo binaly name with version: ${test.version}, platform: ${test.platform}, arch: ${test.arch}`, () => {
|
||||||
|
assert.deepStrictEqual(getBinalyName(test.version, test.platform, test.arch), test.expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
['0.9', '0.8', '0.7'].forEach(v => {
|
||||||
|
it(`should throw error when path an unsupported hugoVersion: ${v}`, () => {
|
||||||
|
try {
|
||||||
|
getBinalyName(v, process.platform, process.arch);
|
||||||
|
assert.fail('unexpected success');
|
||||||
|
} catch (err) {
|
||||||
|
assert(err instanceof Error);
|
||||||
|
assert.strictEqual(err.message, `hugoVersion<0.10 is not supported: ${v}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
_.flatMapDeep([
|
||||||
|
['0.10', '0.11', '0.12', '0.13', '0.14', '0.15'].map(version => [{
|
||||||
|
version,
|
||||||
|
platform: 'darwin',
|
||||||
|
arch: 'arn'
|
||||||
|
}, {
|
||||||
|
version,
|
||||||
|
platform: 'sunos',
|
||||||
|
arch: 'x64'
|
||||||
|
}])
|
||||||
|
]).forEach(test => {
|
||||||
|
it(`should throw error when path an unsupported version: ${test.version}, platform: ${test.platform}, arch: ${test.arch}`, () => {
|
||||||
|
try {
|
||||||
|
getBinalyName(test.version, test.platform, test.arch);
|
||||||
|
assert.fail('unexpected success');
|
||||||
|
} catch (err) {
|
||||||
|
assert(err instanceof Error);
|
||||||
|
assert.strictEqual(err.message, `Can't detect binaly name. Check your platform: ${test.platform}, arch: ${test.arch}, version: ${test.version}.
|
||||||
|
For more info: https://github.com/fenneclab/hugo-bin/blob/master/test/getBinalyName.js`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user