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
81bb7181
Verified
Commit
81bb7181
authored
Feb 05, 2020
by
Aral Balkan
Browse files
Build command is working
parent
81ddb3f8
Pipeline
#914
canceled with stages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
bin/node-hugo.js
View file @
81bb7181
#!/usr/bin/env node
//////////////////////////////////////////////////////////////////////
//
// node-hugo command-line interface (CLI).
//
// Copyright (c) 2020 Aral Balkan. All Rights Reserved.
// Licensed under AGPLv3 or later.
//
// Note: this CLI is not really useful; just use hugo directly :)
// ===== I built it to have an easy way to test the functionality
// as I was building it. (node-hugo is useful when integrated
// into an existing app, like Site.js – https://sitejs.org).
//
//////////////////////////////////////////////////////////////////////
(
async
function
main
()
{
const
Hugo
=
require
(
'
../index.js
'
)
const
hugo
=
new
Hugo
()
...
...
@@ -13,14 +27,35 @@
showUsage
()
process
.
exit
(
1
)
}
console
.
log
(
`[Hugo] Build. Source:
${
sourcePath
}
Destination:
${
destinationPath
}
`
)
console
.
log
(
`\n[Hugo] Build. Source:
${
sourcePath
}
Destination:
${
destinationPath
}
\n`
)
let
result
try
{
result
=
await
hugo
.
build
(
sourcePath
,
destinationPath
)
}
catch
(
error
)
{
console
.
log
(
error
.
message
,
error
.
output
)
exit
(
1
)
}
const
result
=
hugo
.
build
(
sourcePath
,
destinationPath
)
// Build ok.
const
hugoOutput
=
result
.
split
(
'
\n
'
)
hugoOutput
.
forEach
(
line
=>
{
if
(
line
.
includes
(
'
WARN
'
))
{
line
=
` ⚠
${
line
}
`
}
line
=
`[node-hugo]
${
line
}
`
console
.
log
(
line
)
})
console
.
log
(
result
)
}
else
if
(
command
===
'
serve
'
)
{
//
// TODO
//
console
.
log
(
'
serve (todo)
'
,
process
.
argv
[
3
])
}
else
{
//
// Error.
//
console
.
log
(
`\nUnknown command (
${
command
}
)`
)
showUsage
()
}
...
...
index.js
View file @
81bb7181
...
...
@@ -9,6 +9,14 @@ const exec = util.promisify(childProcess.exec)
const
homeDir
=
os
.
homedir
()
class
HugoError
extends
Error
{
constructor
(
message
,
output
)
{
super
(
message
)
this
.
sdterr
=
output
this
.
name
=
'
HugoError
'
}
}
class
Hugo
{
constructor
(
nodeHugoDir
=
path
.
join
(
homeDir
,
'
.small-tech.org
'
,
'
node-hugo
'
))
{
...
...
@@ -40,8 +48,13 @@ class Hugo {
env
:
process
.
env
}
const
result
=
await
exec
(
hugoBuildCommand
,
options
)
console
.
log
(
'
Hugo build result
'
,
result
)
return
result
if
(
result
.
stderr
!==
''
)
{
// There was an error.
throw
new
HugoError
(
'
Build failed
'
,
result
.
stderr
)
}
return
result
.
stdout
}
// Starts a Hugo server at the requested path to serve and returns the Hugo server instance.
...
...
@@ -105,4 +118,5 @@ class Hugo {
}
}
module
.
exports
=
Hugo
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