From 2babfd561cc09de6cdc452529205e83545fd693e Mon Sep 17 00:00:00 2001 From: Shun Sato Date: Wed, 19 Oct 2016 23:36:34 +0900 Subject: [PATCH] feat(hugo): upgrade Hugo to v0.17 (#9) --- README.md | 8 ++ lib/cli.js => cli.js | 4 +- index.js | 1 + lib/binary.js | 14 --- lib/getBinalyName.js | 74 -------------- lib/index.js | 42 +++++++- lib/install.js | 2 +- package.json | 21 ++-- test/getBinalyName.js | 226 ------------------------------------------ test/index.js | 2 +- 10 files changed, 64 insertions(+), 330 deletions(-) rename lib/cli.js => cli.js (66%) create mode 100644 index.js delete mode 100644 lib/binary.js delete mode 100644 lib/getBinalyName.js delete mode 100644 test/getBinalyName.js diff --git a/README.md b/README.md index 478dc71..50af78c 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,13 @@ npm run create -- 'post/my-new-post' # see below 'npm-run-script' See the [Hugo Documentation](https://gohugo.io/) for more information. +## Supported versions + +| hugo-bin version | Hugo version | +|:-----------------:|:------------:| +| ^0.4.0 | v0.17 | +| ^0.3.0 | v0.16 | + ## Full example - [fenneclab/blog.fenneclab.com](https://github.com/fenneclab/blog.fenneclab.com) @@ -49,6 +56,7 @@ See the [Hugo Documentation](https://gohugo.io/) for more information. ## Super Inspired By - [mastilver/apex-bin](https://github.com/mastilver/apex-bin) +- [imagemin/jpegtran-bin](https://github.com/imagemin/jpegtran-bin) ## License diff --git a/lib/cli.js b/cli.js similarity index 66% rename from lib/cli.js rename to cli.js index dcd377a..39aab99 100644 --- a/lib/cli.js +++ b/cli.js @@ -2,7 +2,7 @@ const spawn = require('child_process').spawn; const input = process.argv.slice(2); -const bin = require('./'); +const hugo = require('./'); -spawn(bin, input, {stdio: 'inherit'}) +spawn(hugo, input, {stdio: 'inherit'}) .on('exit', process.exit); diff --git a/index.js b/index.js new file mode 100644 index 0000000..3ffdc83 --- /dev/null +++ b/index.js @@ -0,0 +1 @@ +module.exports = require('./lib').path(); diff --git a/lib/binary.js b/lib/binary.js deleted file mode 100644 index be9d71c..0000000 --- a/lib/binary.js +++ /dev/null @@ -1,14 +0,0 @@ -const path = require('path'); -const BinWrapper = require('bin-wrapper'); -const getBinalyName = require('./getBinalyName'); -const pkg = require('../package'); - -const hugoVersion = pkg.hugoVersion; -const baseUrl = `https://github.com/spf13/hugo/releases/download/v${hugoVersion}/`; - -const binalyNames = getBinalyName(hugoVersion, process.platform, process.arch); - -module.exports = new BinWrapper() - .src(`${baseUrl}${binalyNames.comp}`) - .dest(path.join(__dirname, '../vendor')) - .use(`${binalyNames.exe}`); diff --git a/lib/getBinalyName.js b/lib/getBinalyName.js deleted file mode 100644 index d1b4238..0000000 --- a/lib/getBinalyName.js +++ /dev/null @@ -1,74 +0,0 @@ -const semver = require('semver'); -// see: https://github.com/spf13/hugo/releases - -const packageMap = version => ({ - darwin: { - arm: `hugo_${version}_darwin-arm32.tgz`, - 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 legacyPackageMap = version => ({ - darwin: { - ia32: `hugo_${version}_darwin_386.zip`, - x64: `hugo_${version}_darwin_amd64.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` - } -}); - -module.exports = (version, plat, arch) => { - const validSemverVersion = `${version}.0`; - if (semver.lt(validSemverVersion, '0.10.0')) { - throw new Error(`hugoVersion<0.10 is not supported: ${version}`); - } - // exceptionally when... - if (version === '0.15' && plat === 'win32' && arch === 'ia32') { - return { - comp: 'hugo_0.15_windows_386_32-bit-only.zip', - exe: 'hugo_0.15_windows_386.exe' - } - } - 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 { - comp, - exe - }; -} diff --git a/lib/index.js b/lib/index.js index 44888b0..54d0b08 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,3 +1,41 @@ -const bin = require('./binary'); +const path = require('path'); +const BinWrapper = require('bin-wrapper'); +const pkg = require('../package'); -module.exports = bin.path(); +const hugoVersion = pkg.hugoVersion; +const baseUrl = `https://github.com/spf13/hugo/releases/download/v${hugoVersion}/`; +const binNameMap = { + darwin: { + ia32: `hugo_${hugoVersion}_darwin_386`, + x64: `hugo_${hugoVersion}_darwin_amd64` + }, + freebsd: { + arm: `hugo_${hugoVersion}_freebsd_arm`, + ia32: `hugo_${hugoVersion}_freebsd_386`, + x64: `hugo_${hugoVersion}_freebsd_amd64` + }, + linux: { + arm: `hugo_${hugoVersion}_linux_arm`, + ia32: `hugo_${hugoVersion}_linux_386`, + x64: `hugo_${hugoVersion}_linux_amd64` + }, + win32: { + ia32: `hugo_${hugoVersion}_windows_386.exe`, + x64: `hugo_${hugoVersion}_windows_amd64.exe` + } +}; +const binName = (binNameMap[process.platform] && binNameMap[process.platform][process.arch]) || ''; + +module.exports = new BinWrapper() + .src(`${baseUrl}hugo_${hugoVersion}_FreeBSD-32bit.zip`, 'freebsd', 'x86') + .src(`${baseUrl}hugo_${hugoVersion}_FreeBSD-64bit.zip`, 'freebsd', 'x64') + .src(`${baseUrl}hugo_${hugoVersion}_freebsd_arm.zip`, 'freebsd', 'arm') + .src(`${baseUrl}hugo_${hugoVersion}_Linux-32bit.tar.gz`, 'linux', 'x86') + .src(`${baseUrl}hugo_${hugoVersion}_Linux-64bit.tar.gz`, 'linux', 'x64') + .src(`${baseUrl}hugo_${hugoVersion}_linux_arm.tar.gz`, 'linux', 'arm') + .src(`${baseUrl}hugo_${hugoVersion}_MacOS-32bit.zip`, 'darwin', 'x86') + .src(`${baseUrl}hugo_${hugoVersion}_MacOS-64bit.zip`, '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')) + .use(binName); diff --git a/lib/install.js b/lib/install.js index 23431cc..94c9768 100644 --- a/lib/install.js +++ b/lib/install.js @@ -1,4 +1,4 @@ -const bin = require('./binary'); +const bin = require('./'); const log = require('logalot'); bin.run(['version'], err => { diff --git a/package.json b/package.json index 9e8f505..419d2ce 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "hugo-bin", "version": "0.3.0", - "hugoVersion": "0.16", + "hugoVersion": "0.17", "description": "Binary wrapper for Hugo", - "main": "lib/index.js", + "main": "index.js", "scripts": { "test": "eslint . && mocha", "postinstall": "rm -rf vendor && node lib/install" @@ -12,16 +12,18 @@ "author": "satoshun00 ", "license": "MIT", "files": [ - "lib" + "lib", + "index.js", + "cli.js" ], "bin": { - "hugo": "lib/cli.js" + "hugo": "cli.js" }, "devDependencies": { - "bin-check": "3.0.0", - "eslint": "2.11.0", - "lodash": "4.13.1", - "mocha": "2.5.3" + "bin-check": "4.0.1", + "eslint": "3.8.1", + "lodash": "4.16.4", + "mocha": "3.1.2" }, "engines": { "node": ">=4.0.0" @@ -38,7 +40,6 @@ }, "dependencies": { "bin-wrapper": "3.0.2", - "logalot": "2.1.0", - "semver": "5.1.0" + "logalot": "2.1.0" } } diff --git a/test/getBinalyName.js b/test/getBinalyName.js deleted file mode 100644 index 8a1d94f..0000000 --- a/test/getBinalyName.js +++ /dev/null @@ -1,226 +0,0 @@ -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`); - } - }); - }); - -}); diff --git a/test/index.js b/test/index.js index d10d171..b238e91 100644 --- a/test/index.js +++ b/test/index.js @@ -1,6 +1,6 @@ const assert = require('assert'); const binCheck = require('bin-check'); -const hugoBin = require('../lib'); +const hugoBin = require('../'); describe('hugo-bin', () => { it('should return path to binary and work', () => {