Permalink
Browse files

Add support for Netlify functions

  • Loading branch information...
crgeary committed Jun 4, 2018
1 parent eb68dae commit 90d8045a57aba6269b7b7d9824f4f062842ed4ab
Showing with 2,519 additions and 218 deletions.
  1. +3 −1 .gitignore
  2. +27 −4 gulpfile.babel.js
  3. +1 −0 netlify.toml
  4. +2,487 −213 package-lock.json
  5. +1 −0 package.json
  6. 0 src/lambda/.gitkeep
@@ -4,4 +4,6 @@
/static/images
/static/fonts
/static/css/app.css
/static/js/app.js
/static/js/app.js
/functions
@@ -6,6 +6,7 @@ import runSequence from 'run-sequence'
import gulpLoadPlugins from 'gulp-load-plugins'
import { spawn } from "child_process"
import tildeImporter from 'node-sass-tilde-importer'
import fs from 'fs';
const $ = gulpLoadPlugins()
const browserSync = require('browser-sync').create()
@@ -40,17 +41,40 @@ gulp.task('init-watch', () => {
$.watch('src/sass/**/*.scss', () => gulp.start('sass'))
$.watch('src/js/**/*.js', () => gulp.start('js-watch'))
$.watch('src/images/**/*', () => gulp.start('images'))
$.watch('src/lambda/**/*', () => gulp.start('build-functions'))
})
gulp.task('build', () => {
runSequence(['sass', 'js', 'fonts', 'images', 'pub-delete'], 'hugo')
runSequence(['sass', 'js', 'fonts', 'images', 'pub-delete', 'build-functions'], 'hugo')
})
gulp.task('build-preview', () => {
runSequence(['sass', 'js', 'fonts', 'images', 'pub-delete'], 'hugo-preview')
runSequence(['sass', 'js', 'fonts', 'images', 'pub-delete', 'build-functions'], 'hugo-preview')
})
gulp.task('build-functions', (cb) => {
fs.readdir('./src/lambda', (err, files) => {
if (err) {
throw err;
}
if (!files.filter(file => file.endsWith('.js')).length) {
console.log('No Netlify functions.');
return;
}
return spawn('netlify-lambda', ['build', 'src/lambda'], { stdio: 'inherit' }).on('close', (code) => {
if (code === 0) {
cb();
} else {
console.log('netlify-lambda failed.');
cb('netlify-lambda failed.');
}
})
})
})
gulp.task('hugo', (cb) => {
let baseUrl = process.env.NODE_ENV === 'production' ? process.env.URL : process.env.DEPLOY_PRIME_URL;
@@ -68,7 +92,6 @@ gulp.task('hugo', (cb) => {
})
gulp.task('hugo-preview', (cb) => {
let args = ['--buildDrafts', '--buildFuture'];
if (process.env.DEPLOY_PRIME_URL) {
@@ -140,7 +163,7 @@ gulp.task('cms-delete', () => {
})
gulp.task('pub-delete', () => {
return del(['public/**', '!public'], {
return del(['public/**', '!public', 'functions/**', '!functions'], {
// dryRun: true,
dot: true
}).then(paths => {
@@ -1,6 +1,7 @@
[build]
command = "npm run build"
publish = "public"
functions = "functions"
[build.environment]
HUGO_VERSION = "0.38.2"
Oops, something went wrong.

0 comments on commit 90d8045

Please sign in to comment.