Verified Commit e642149d authored by Aral Balkan's avatar Aral Balkan
Browse files

Closes #2, #3: Add version property; fix code errors in readme

parent 151ae75b
...@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
## [1.4.0] - 2020-05-05
### Added
- `version` property that returns the Hugo version ([#3](https://source.small-tech.org/site.js/lib/node-hugo/-/issues/3)).
### Fixed
- Incorrect require statements in code samples in readme ([#2](https://source.small-tech.org/site.js/lib/node-hugo/-/issues/2)).
## [1.3.0] - 2020-02-13 ## [1.3.0] - 2020-02-13
### Added ### Added
......
# node-hugo # Node Hugo
A basic cross-platform interface to the Hugo binary from Node.js that: A basic cross-platform interface to the Hugo binary from Node.js that uses the 64-bit release binaries to support Linux, macOS, and Windows.
* Uses the 64-bit release binaries to support Linux, macOS, and Windows.
It should __just work™__ 🤞 It should __just work™__ 🤞
...@@ -15,7 +13,7 @@ npm i @small-tech/node-hugo ...@@ -15,7 +13,7 @@ npm i @small-tech/node-hugo
## Usage ## Usage
```js ```js
const Hugo = require('node-hugo') const Hugo = require('@small-tech/node-hugo')
(async function main () { (async function main () {
...@@ -60,10 +58,10 @@ const Hugo = require('node-hugo') ...@@ -60,10 +58,10 @@ const Hugo = require('node-hugo')
})() })()
``` ```
(Version 1.2.0+) You can also run any Hugo command using the simple passthrough `command()` method: __(Version 1.2.0+)__ You can also run any Hugo command using the simple pass-through `command()` method:
```js ```js
const Hugo = require('node-hugo') const Hugo = require('@small-tech/node-hugo')
(async function main () { (async function main () {
...@@ -81,7 +79,15 @@ const Hugo = require('node-hugo') ...@@ -81,7 +79,15 @@ const Hugo = require('node-hugo')
})() })()
``` ```
(Version 1.3.0+) For creating Hugo servers with an arbitrary argument string, you can use the `serverWithArgs()` method. This works like the blocking `command()` method but provides streaming output from the Hugo server. __(Version 1.3.0+)__ For creating Hugo servers with an arbitrary argument string, you can use the `serverWithArgs()` method. This works like the blocking `command()` method but provides streaming output from the Hugo server.
__(Version 1.4.0+)__ You can retrieve the version of Hugo that’s bundled using the `version` property:
```js
const Hugo = require('@small-tech/node-hugo')
const hugo = new Hugo()
console.log(`Hugo version: ${hugo.version}`)
```
## Maintenance ## Maintenance
......
////////////////////////////////////////////////////////////////////////////////
//
// @small-tech/node-hugo
//
// A basic cross-platform interface to the Hugo binary from Node.js that uses
// the 64-bit release binaries to support Linux, macOS, and Windows.
//
// Copyright ⓒ 2020 Aral Balkan. Licensed under AGPLv3 or later.
// Shared with ♥ by the Small Technology Foundation.
//
// Like this? Fund us!
// https://small-tech.org/fund-us
//
////////////////////////////////////////////////////////////////////////////////
const os = require('os') const os = require('os')
const path = require('path') const path = require('path')
const fs = require('fs-extra') const fs = require('fs-extra')
...@@ -10,6 +25,8 @@ const spawn = childProcess.spawn ...@@ -10,6 +25,8 @@ const spawn = childProcess.spawn
const homeDir = os.homedir() const homeDir = os.homedir()
const hugoVersion = '0.64.1'
class HugoError extends Error { class HugoError extends Error {
constructor (message, output) { constructor (message, output) {
super(message) super(message)
...@@ -38,6 +55,11 @@ class Hugo { ...@@ -38,6 +55,11 @@ class Hugo {
// Public. // Public.
// //
// Returns the Hugo version.
get version () {
return hugoVersion
}
// Runs a generic, blocking Hugo command using the passed arguments. // Runs a generic, blocking Hugo command using the passed arguments.
async command (args) { async command (args) {
const hugoCommand = `${this.hugoBinaryPath} ${args}` const hugoCommand = `${this.hugoBinaryPath} ${args}`
...@@ -171,8 +193,6 @@ class Hugo { ...@@ -171,8 +193,6 @@ class Hugo {
if (platform === undefined) throw new Error('Unsupported platform', this.machine.platform) if (platform === undefined) throw new Error('Unsupported platform', this.machine.platform)
if (architecture === undefined) throw new Error('Unsupported architecture', this.machine.architecture) if (architecture === undefined) throw new Error('Unsupported architecture', this.machine.architecture)
const hugoVersion = '0.64.1'
const hugoBinaryName = `hugo-v${hugoVersion}-${platform}-${architecture}` const hugoBinaryName = `hugo-v${hugoVersion}-${platform}-${architecture}`
const hugoBinaryRelativePath = path.join('hugo-bin', hugoBinaryName) const hugoBinaryRelativePath = path.join('hugo-bin', hugoBinaryName)
let hugoBinaryInternalPath = path.join(__dirname, hugoBinaryRelativePath) let hugoBinaryInternalPath = path.join(__dirname, hugoBinaryRelativePath)
......
{ {
"name": "@small-tech/node-hugo", "name": "@small-tech/node-hugo",
"version": "1.3.0", "version": "1.4.0",
"description": "A basic cross-platform interface to the Hugo binary from Node.js.", "description": "A basic cross-platform interface to the Hugo binary from Node.js.",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git@source.ind.ie:site.js/lib/node-hugo.git" "url": "https://github.com/small-tech/node-hugo"
}, },
"author": { "author": {
"name": "Aral Balkan", "name": "Aral Balkan",
......
...@@ -116,3 +116,13 @@ test('[hugo.serve] ', async t => { ...@@ -116,3 +116,13 @@ test('[hugo.serve] ', async t => {
t.true(hugoBuildOutputDeflated.includes('Non-pagefiles|1'), 'one non-page file is rendered') t.true(hugoBuildOutputDeflated.includes('Non-pagefiles|1'), 'one non-page file is rendered')
t.true(hugoBuildOutputDeflated.includes('Sitemaps|1'), 'one sitemap is rendered') t.true(hugoBuildOutputDeflated.includes('Sitemaps|1'), 'one sitemap is rendered')
}) })
test('[hugo.version]', async t => {
t.plan(1)
const output = await hugo.command('version')
const versionFromHugo = output.match(/v(\d+\.\d+\.\d+)-/)[1]
t.strictEquals(hugo.version, versionFromHugo, 'Hugo version is correct.')
})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment