Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Site.js
lib
Node Hugo
Commits
cca7137b
Verified
Commit
cca7137b
authored
Feb 12, 2020
by
Aral Balkan
Browse files
Add generic hugo command passthrough method
parent
640fcd07
Changes
1
Hide whitespace changes
Inline
Side-by-side
index.js
View file @
cca7137b
...
...
@@ -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
(
hugo
Build
Command
,
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).
//
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment