Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions src/commands/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,33 @@ async function startDevServer(settings, log) {
return ps
}

const getBuildFunction = functionBuilder =>
async function build() {
this.log(
`${NETLIFYDEVLOG} Function builder ${chalk.yellow(functionBuilder.builderName)} ${chalk.magenta(
'building'
)} functions from directory ${chalk.yellow(functionBuilder.src)}`
)

try {
await functionBuilder.build()
this.log(
`${NETLIFYDEVLOG} Function builder ${chalk.yellow(functionBuilder.builderName)} ${chalk.green(
'finished'
)} building functions from directory ${chalk.yellow(functionBuilder.src)}`
)
} catch (error) {
const errorMessage = (error.stderr && error.stderr.toString()) || error.message
this.log(
`${NETLIFYDEVLOG} Function builder ${chalk.yellow(functionBuilder.builderName)} ${chalk.red(
'failed'
)} building functions from directory ${chalk.yellow(functionBuilder.src)}${
errorMessage ? ` with error:\n${errorMessage}` : ''
}`
)
}
}

class DevCommand extends Command {
async run() {
this.log(`${NETLIFYDEV}`)
Expand Down Expand Up @@ -492,21 +519,10 @@ class DevCommand extends Command {
`${NETLIFYDEVWARN} This is a beta feature, please give us feedback on how to improve at https://github.com/netlify/cli/`
)

const debouncedBuild = debounce(
async () => {
this.log(
`${NETLIFYDEVLOG} Function builder ${chalk.yellow(
functionBuilder.builderName
)} building functions from ${chalk.yellow(functionBuilder.src)}`
)
await functionBuilder.build()
},
300,
{
leading: true,
trailing: true,
}
)
const debouncedBuild = debounce(getBuildFunction(functionBuilder).bind(this), 300, {
leading: true,
trailing: true,
})

await debouncedBuild()

Expand Down
1 change: 1 addition & 0 deletions src/utils/serve-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function createHandler(dir) {
Object.keys(require.cache).forEach(k => {
delete require.cache[k]
})
console.log(`${NETLIFYDEVLOG} ${path} ${action}, successfully reloaded!`)
}
const watcher = chokidar.watch(dir, { ignored: /node_modules/ })
watcher.on('change', clearCache('modified')).on('unlink', clearCache('deleted'))
Expand Down