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

Add generic hugo command passthrough method

parent 640fcd07
......@@ -38,26 +38,32 @@ class Hugo {
// Public.
//
// Builds the Hugo source from sourcePath and writes the output at
// destinationPath. Note that destinationPath is relevant to sourcePath
// (don’t shoot me, this is a Hugo convention so I’m mirroring it for
// consistency with regular Hugo usage). The returned result is the
// object returned from the exec() call with stdout and stderr properties.
async build (sourcePath = '.', destinationPath = 'public/', baseURL = 'http://localhost:1313') {
const hugoBuildCommand = `${this.hugoBinaryPath} --source=${sourcePath} --destination=${destinationPath} --baseURL=${baseURL}`
// Runs a generic, blocking Hugo command using the passed arguments.
async command (args) {
const hugoCommand = `${this.hugoBinaryPath} ${args}`
const options = {
env: process.env
}
const result = await exec(hugoBuildCommand, options)
const result = await exec(hugoCommand, options)
if (result.stderr !== '') {
// There was an error.
throw new HugoError('Build failed', result.stderr)
throw new HugoError(`Hugo command failed (arguments: ${args})`, result.stderr)
}
return result.stdout
}
// Builds the Hugo source from sourcePath and writes the output at
// destinationPath. Note that destinationPath is relevant to sourcePath
// (don’t shoot me, this is a Hugo convention so I’m mirroring it for
// consistency with regular Hugo usage). The returned result is the
// object returned from the exec() call with stdout and stderr properties.
async build (sourcePath = '.', destinationPath = 'public/', baseURL = 'http://localhost:1313') {
const hugoBuildCommand = `--source=${sourcePath} --destination=${destinationPath} --baseURL=${baseURL}`
return await this.command(hugoBuildCommand)
}
// Starts a Hugo server with defaults set for rendering to disk and using outside live reload.
// (These are the defaults our current use case on Site.js).
//
......
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