From 528d5899e6c57aec5f2f8f957bec3c298fcd0b41 Mon Sep 17 00:00:00 2001 From: satoshun00 Date: Tue, 31 Jul 2018 04:14:20 +0900 Subject: [PATCH 1/3] wip: Support Hugo extended --- lib/index.js | 27 ++++++++------- package-lock.json | 86 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 5 +-- 3 files changed, 104 insertions(+), 14 deletions(-) diff --git a/lib/index.js b/lib/index.js index a7c6487e..04a68166 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,8 +1,11 @@ const path = require('path'); const BinWrapper = require('bin-wrapper'); +const pkgConf = require('pkg-conf'); const pkg = require('../package'); -const hugoVersion = pkg.hugoVersion; +const config = pkgConf.sync('hugo-bin'); +const hugoVersion = process.env.HUGO_BIN_VERSION || process.env.npm_config_hugo_bin_version || config.version || pkg.defaultHugoVersion; +const extended = process.env.HUGO_BIN_EXTENDED || process.env.npm_config_hugo_bin_extended || config.extended || false; const baseUrl = `/~https://github.com/gohugoio/hugo/releases/download/v${hugoVersion}/`; const binNameMap = { darwin: { @@ -30,17 +33,17 @@ const binNameMap = { } }; const binName = (binNameMap[process.platform] && binNameMap[process.platform][process.arch]) || ''; - +const srcPrefix = `hugo${extended ? '_extended' : ''}_${hugoVersion}_`; module.exports = 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') - .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.tar.gz`, 'darwin', 'x86') - .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') + .src(`${baseUrl}${srcPrefix}_FreeBSD-32bit.tar.gz`, 'freebsd', 'x86') + .src(`${baseUrl}${srcPrefix}_FreeBSD-64bit.tar.gz`, 'freebsd', 'x64') + .src(`${baseUrl}${srcPrefix}_FreeBSD-ARM.tar.gz`, 'freebsd', 'arm') + .src(`${baseUrl}${srcPrefix}_Linux-32bit.tar.gz`, 'linux', 'x86') + .src(`${baseUrl}${srcPrefix}_Linux-64bit.tar.gz`, 'linux', 'x64') + .src(`${baseUrl}${srcPrefix}_Linux-ARM.tar.gz`, 'linux', 'arm') + .src(`${baseUrl}${srcPrefix}_macOS-32bit.tar.gz`, 'darwin', 'x86') + .src(`${baseUrl}${srcPrefix}_macOS-64bit.tar.gz`, 'darwin', 'x64') + .src(`${baseUrl}${srcPrefix}_Windows-32bit.zip`, 'win32', 'x86') + .src(`${baseUrl}${srcPrefix}_Windows-64bit.zip`, 'win32', 'x64') .dest(path.join(__dirname, '../vendor')) .use(binName); diff --git a/package-lock.json b/package-lock.json index e1e9a02d..55546bb8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1626,6 +1626,11 @@ "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz", "integrity": "sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg=" }, + "json-parse-better-errors": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz", + "integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==" + }, "json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", @@ -1683,6 +1688,22 @@ } } }, + "locate-path": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", + "integrity": "sha1-K1aLJl7slExtnA3pw9u7ygNUzY4=", + "requires": { + "p-locate": "2.0.0", + "path-exists": "3.0.0" + }, + "dependencies": { + "path-exists": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", + "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=" + } + } + }, "lodash": { "version": "4.17.10", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz", @@ -1996,6 +2017,22 @@ "resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-1.1.0.tgz", "integrity": "sha1-nJRWmJ6fZYgBewQ01WCXZ1w9oF4=" }, + "p-limit": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", + "integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==", + "requires": { + "p-try": "1.0.0" + } + }, + "p-locate": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz", + "integrity": "sha1-IKAQOyIqcMj9OcwuWAaA893l7EM=", + "requires": { + "p-limit": "1.3.0" + } + }, "p-map": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/p-map/-/p-map-1.2.0.tgz", @@ -2009,6 +2046,11 @@ "p-finally": "1.0.0" } }, + "p-try": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz", + "integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=" + }, "package-json": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/package-json/-/package-json-4.0.1.tgz", @@ -2124,6 +2166,50 @@ "pinkie": "2.0.4" } }, + "pkg-conf": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/pkg-conf/-/pkg-conf-2.1.0.tgz", + "integrity": "sha1-ISZRTKbyq/69FoWW3xi6V4Z/AFg=", + "requires": { + "find-up": "2.1.0", + "load-json-file": "4.0.0" + }, + "dependencies": { + "find-up": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", + "integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=", + "requires": { + "locate-path": "2.0.0" + } + }, + "load-json-file": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-4.0.0.tgz", + "integrity": "sha1-L19Fq5HjMhYjT9U62rZo607AmTs=", + "requires": { + "graceful-fs": "4.1.11", + "parse-json": "4.0.0", + "pify": "3.0.0", + "strip-bom": "3.0.0" + } + }, + "parse-json": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-4.0.0.tgz", + "integrity": "sha1-vjX1Qlvh9/bHRxhPmKeIy5lHfuA=", + "requires": { + "error-ex": "1.3.2", + "json-parse-better-errors": "1.0.2" + } + }, + "strip-bom": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", + "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=" + } + } + }, "pluralize": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/pluralize/-/pluralize-7.0.0.tgz", diff --git a/package.json b/package.json index 031b0802..74ec15dc 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "hugo-bin", "version": "0.30.0", - "hugoVersion": "0.42.2", + "defaultHugoVersion": "0.42.2", "description": "Binary wrapper for Hugo", "repository": "fenneclab/hugo-bin", "author": "satoshun00 ", @@ -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", From c057b3659d5364d189aef8c1ac9b72860f8197c4 Mon Sep 17 00:00:00 2001 From: satoshun00 Date: Sat, 11 Aug 2018 18:35:08 +0900 Subject: [PATCH 2/3] fallback support, update readme.md --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ lib/index.js | 45 ++++++++++++++++++++++++++++++--------------- package.json | 2 +- 3 files changed, 73 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index d5fde293..23f36ea8 100644 --- a/README.md +++ b/README.md @@ -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 detail. + ## Usage ### API @@ -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 variation of Hugo binaries. + +Each options 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 [extended version](/~https://github.com/gohugoio/hugo/releases/tag/v0.43) binary. + +If this set to `extended` but it's not available for the user's platform, then the normal version would be downloaded instead. + ## Supported versions See [the package.json commit history](/~https://github.com/fenneclab/hugo-bin/commits/master/package.json). diff --git a/lib/index.js b/lib/index.js index 04a68166..b4800987 100644 --- a/lib/index.js +++ b/lib/index.js @@ -4,8 +4,8 @@ const pkgConf = require('pkg-conf'); const pkg = require('../package'); const config = pkgConf.sync('hugo-bin'); -const hugoVersion = process.env.HUGO_BIN_VERSION || process.env.npm_config_hugo_bin_version || config.version || pkg.defaultHugoVersion; -const extended = process.env.HUGO_BIN_EXTENDED || process.env.npm_config_hugo_bin_extended || config.extended || false; +const hugoVersion = pkg.hugoVersion; +const extended = (process.env.HUGO_BIN_BUILD_TAGS || process.env.npm_config_hugo_bin_build_tags || config.buildTags || '') === 'extended'; const baseUrl = `/~https://github.com/gohugoio/hugo/releases/download/v${hugoVersion}/`; const binNameMap = { darwin: { @@ -32,18 +32,33 @@ const binNameMap = { x64: 'hugo.exe' } }; +const dest = path.join(__dirname, '../vendor'); const binName = (binNameMap[process.platform] && binNameMap[process.platform][process.arch]) || ''; -const srcPrefix = `hugo${extended ? '_extended' : ''}_${hugoVersion}_`; -module.exports = new BinWrapper() - .src(`${baseUrl}${srcPrefix}_FreeBSD-32bit.tar.gz`, 'freebsd', 'x86') - .src(`${baseUrl}${srcPrefix}_FreeBSD-64bit.tar.gz`, 'freebsd', 'x64') - .src(`${baseUrl}${srcPrefix}_FreeBSD-ARM.tar.gz`, 'freebsd', 'arm') - .src(`${baseUrl}${srcPrefix}_Linux-32bit.tar.gz`, 'linux', 'x86') - .src(`${baseUrl}${srcPrefix}_Linux-64bit.tar.gz`, 'linux', 'x64') - .src(`${baseUrl}${srcPrefix}_Linux-ARM.tar.gz`, 'linux', 'arm') - .src(`${baseUrl}${srcPrefix}_macOS-32bit.tar.gz`, 'darwin', 'x86') - .src(`${baseUrl}${srcPrefix}_macOS-64bit.tar.gz`, 'darwin', 'x64') - .src(`${baseUrl}${srcPrefix}_Windows-32bit.zip`, 'win32', 'x86') - .src(`${baseUrl}${srcPrefix}_Windows-64bit.zip`, 'win32', 'x64') - .dest(path.join(__dirname, '../vendor')) +const extendedBin = new BinWrapper() + .src(`${baseUrl}hugo_${hugoVersion}_extended_Linux-64bit.tar.gz`, 'linux', 'x64') + .src(`${baseUrl}hugo_${hugoVersion}_extended_macOS-64bit.tar.gz`, 'darwin', 'x64') + .src(`${baseUrl}hugo_${hugoVersion}_extended_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') + .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.tar.gz`, 'darwin', 'x86') + .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(dest) + .use(binName); +module.exports = extended ? extendedBin : normalBin; diff --git a/package.json b/package.json index 74ec15dc..a0962796 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "hugo-bin", "version": "0.30.0", - "defaultHugoVersion": "0.42.2", + "hugoVersion": "0.42.2", "description": "Binary wrapper for Hugo", "repository": "fenneclab/hugo-bin", "author": "satoshun00 ", From d962e8db4fe10c6eb0a38c47f8c7929c2a55506b Mon Sep 17 00:00:00 2001 From: satoshun00 Date: Sun, 2 Sep 2018 21:46:34 +0900 Subject: [PATCH 3/3] fixup! wip: Support Hugo extended --- README.md | 10 +++++----- cli.js | 0 index.js | 2 +- lib/index.js | 14 ++++++++------ lib/install.js | 21 ++++++++++++++++++++- package.json | 2 +- 6 files changed, 35 insertions(+), 14 deletions(-) mode change 100644 => 100755 cli.js diff --git a/README.md b/README.md index 23f36ea8..e681748b 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ 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 detail. +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 @@ -46,9 +46,9 @@ See the [Hugo Documentation](https://gohugo.io/) for more information. ## Installation options -hugo-bin supports options to change variation of Hugo binaries. +hugo-bin supports options to change the variation of Hugo binaries. -Each options can be configured in the `hugo-bin` section of your `package.json`: +Each option can be configured in the `hugo-bin` section of your `package.json`: ```json { @@ -80,9 +80,9 @@ export HUGO_BIN_BUILD_TAGS="extended" Default: `""` -Set it to `extended` to download [extended version](/~https://github.com/gohugoio/hugo/releases/tag/v0.43) binary. +Set it to `extended` to download the [extended version](/~https://github.com/gohugoio/hugo/releases/tag/v0.43) binary. -If this set to `extended` but it's not available for the user's platform, then the normal version would be downloaded instead. +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 diff --git a/cli.js b/cli.js old mode 100644 new mode 100755 diff --git a/index.js b/index.js index 3ffdc83e..77e8c708 100644 --- a/index.js +++ b/index.js @@ -1 +1 @@ -module.exports = require('./lib').path(); +module.exports = require('./lib')(process.cwd()).path(); diff --git a/lib/index.js b/lib/index.js index b4800987..cf5f9c6d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -3,9 +3,7 @@ const BinWrapper = require('bin-wrapper'); const pkgConf = require('pkg-conf'); const pkg = require('../package'); -const config = pkgConf.sync('hugo-bin'); const hugoVersion = pkg.hugoVersion; -const extended = (process.env.HUGO_BIN_BUILD_TAGS || process.env.npm_config_hugo_bin_build_tags || config.buildTags || '') === 'extended'; const baseUrl = `/~https://github.com/gohugoio/hugo/releases/download/v${hugoVersion}/`; const binNameMap = { darwin: { @@ -35,9 +33,9 @@ const binNameMap = { const dest = path.join(__dirname, '../vendor'); const binName = (binNameMap[process.platform] && binNameMap[process.platform][process.arch]) || ''; const extendedBin = new BinWrapper() - .src(`${baseUrl}hugo_${hugoVersion}_extended_Linux-64bit.tar.gz`, 'linux', 'x64') - .src(`${baseUrl}hugo_${hugoVersion}_extended_macOS-64bit.tar.gz`, 'darwin', 'x64') - .src(`${baseUrl}hugo_${hugoVersion}_extended_Windows-64bit.zip`, 'win32', 'x64') + .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') @@ -61,4 +59,8 @@ const normalBin = new BinWrapper() .src(`${baseUrl}hugo_${hugoVersion}_Windows-64bit.zip`, 'win32', 'x64') .dest(dest) .use(binName); -module.exports = extended ? extendedBin : normalBin; +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; +}; diff --git a/lib/install.js b/lib/install.js index 7b9dc414..e398ab3c 100644 --- a/lib/install.js +++ b/lib/install.js @@ -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'); }) diff --git a/package.json b/package.json index a0962796..e7eaaf71 100644 --- a/package.json +++ b/package.json @@ -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 ",