diff --git a/.jshintignore b/.jshintignore index c72813792c..800afa9d24 100644 --- a/.jshintignore +++ b/.jshintignore @@ -1,4 +1,6 @@ appengine/bower/public/bower_components/** +appengine/brunch/app/** +appengine/brunch/public/** appengine/kraken/public/components/** appengine/parse-server/cloud/main.js appengine/sails/config/** @@ -8,4 +10,4 @@ appengine/sails/api/responses/** appengine/webpack/dist/** functions/** **/node_modules/** -coverage/ \ No newline at end of file +coverage/ diff --git a/.jshintrc b/.jshintrc index 14c42a69ac..e765762783 100644 --- a/.jshintrc +++ b/.jshintrc @@ -11,5 +11,6 @@ "strict": true, "trailing": true, "undef": true, - "unused": true + "unused": true, + "esversion": 6 } diff --git a/.travis.yml b/.travis.yml index de617eb499..a6a638c686 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,7 @@ cache: directories: - appengine/analytics/node_modules/ - appengine/bower/node_modules/ + - appengine/brunch/node_modules/ - appengine/cloudsql/node_modules/ - appengine/datastore/node_modules/ - appengine/disk/node_modules/ diff --git a/README.md b/README.md index 910d937994..4e4641e5bd 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ __Databases__ __Tools__ - gcloud-node - [Source code][gcloud_1] | [Documentation][gcloud_2] +- Brunch - [Source code][brunch_1] | [Documentation][brunch_2] - Bower - [Source code][bower_1] | [App Engine Tutorial][bower_2] | [Documentation][bower_3] - Grunt - [Source code][grunt_1] | [App Engine Tutorial][grunt_2] | [Live demo][grunt_3] | [Documentation][grunt_4] - Mailgun - [Source code][mailgun_1] | [App Engine Tutorial][mailgun_2] | [Documentation][mailgun_3] @@ -224,6 +225,9 @@ See [LICENSE](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/ma [gcloud_1]: https://github.com/GoogleCloudPlatform/gcloud-node [gcloud_2]: https://googlecloudplatform.github.io/gcloud-node/#/ +[brunch_1]: https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/appengine/brunch +[brunch_2]: http://brunch.io + [bower_1]: https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/appengine/bower [bower_2]: https://cloud.google.com/nodejs/resources/tools/bower [bower_3]: http://bower.io/ diff --git a/appengine/brunch/.gitignore b/appengine/brunch/.gitignore new file mode 100644 index 0000000000..d097ec82c8 --- /dev/null +++ b/appengine/brunch/.gitignore @@ -0,0 +1,26 @@ +# Numerous always-ignore extensions +*.diff +*.err +*.orig +*.log +*.rej +*.swo +*.swp +*.vi +*~ +*.sass-cache + +# OS or Editor folders +.DS_Store +.cache +.project +.settings +.tmproj +nbproject +Thumbs.db + +# NPM packages folder. +node_modules/ + +# Brunch output folder. +public/ diff --git a/appengine/brunch/README.md b/appengine/brunch/README.md new file mode 100644 index 0000000000..d88372f171 --- /dev/null +++ b/appengine/brunch/README.md @@ -0,0 +1,38 @@ +## Brunch with ES6 running on Google App Engine. + +> [Brunch](http://brunch.io) is a build tool, an alternative to [Grunt](http://gruntjs.com) and [Gulp](http://gulpjs.com) geared towards building assets with an emphasis on speed. + + +This sample demonstrates how to use [Brunch](http://brunch.io) on +[Google App Engine Managed VMs](https://cloud.google.com/appengine/docs/managed-vms/). + +For more information about getting started with Brunch, see the +[Getting Started with Brunch Guide](https://github.com/brunch/brunch-guide/blob/master/content/en/chapter02-getting-started.md). + +You can also view the [live demo](https://alien-lattice-123714.appspot.com) and read the full [Brunch documentation](https://github.com/brunch/brunch-guide). + +## Setup +Add the necessary modules in your `package.json`: +```sh +$ npm install --save-dev express body-parser morgan +``` + +Compiles and copies files over `package.json`: +```sh +npm run build +``` + +## Running locally +Refer to the [appengine/README.md](../README.md) file for instructions on +running and deploying. + +To support custom web servers an `app.js` file was added. +```sh +$ npm start +``` +Will bypass the `brunch-config.js` file and use settings provided in the `app.js` file. + +```sh +$ brunch watch --server +``` +Will use settings provided in the `brunch-config.js` file. diff --git a/appengine/brunch/app.js b/appengine/brunch/app.js new file mode 100644 index 0000000000..a39ee66ec0 --- /dev/null +++ b/appengine/brunch/app.js @@ -0,0 +1,22 @@ +// Copyright 2015-2016, Google, Inc. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +var startServer = require('./brunch-server'); +startServer(process.env.PORT || 8080, '/', function() { + var server = this; + var port = server.address().port; + console.log('App listening at http://localhost:%s', port); + console.log('Press Ctrl+C to quit.'); +}); diff --git a/appengine/brunch/app.yaml b/appengine/brunch/app.yaml new file mode 100644 index 0000000000..c1c22cd8cb --- /dev/null +++ b/appengine/brunch/app.yaml @@ -0,0 +1,20 @@ +# Copyright 2015-2016, Google, Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START app_yaml] +runtime: nodejs +vm: true + +skip_files: + - ^(.*/)?.*/node_modules/.*$ +# [END app_yaml] diff --git a/appengine/brunch/app/assets/views/index.jade b/appengine/brunch/app/assets/views/index.jade new file mode 100644 index 0000000000..96d3bedd89 --- /dev/null +++ b/appengine/brunch/app/assets/views/index.jade @@ -0,0 +1,10 @@ +doctype html +head + meta(charset='utf-8') + title Brunch with ES6 running on Google App Engine + script(src='/app.js') + script. + require('initialize'); + body + #app + h1 Hello World! diff --git a/appengine/brunch/app/initialize.js b/appengine/brunch/app/initialize.js new file mode 100644 index 0000000000..b1f3bbed87 --- /dev/null +++ b/appengine/brunch/app/initialize.js @@ -0,0 +1,4 @@ +document.addEventListener('DOMContentLoaded', () => { + // do your setup here + console.log('Initialized app'); +}); diff --git a/appengine/brunch/brunch-config.js b/appengine/brunch/brunch-config.js new file mode 100644 index 0000000000..1730f0cd45 --- /dev/null +++ b/appengine/brunch/brunch-config.js @@ -0,0 +1,33 @@ +module.exports = { + files: { + javascripts: { + joinTo: { + 'vendor.js': /^(?!app)/, + 'app.js': /^app/ + } + }, + stylesheets: { + joinTo: 'app.css' + }, + }, + plugins: { + babel: { + presets: ['es2015'] + } + }, + server: { + run: true, + port: 8080 + }, + overrides: { + production: { + optimize: true, + sourceMaps: false, + plugins: { + autoReload: { + enabled: false + } + } + } + } +}; diff --git a/appengine/brunch/brunch-server.js b/appengine/brunch/brunch-server.js new file mode 100644 index 0000000000..36fdbbe068 --- /dev/null +++ b/appengine/brunch/brunch-server.js @@ -0,0 +1,19 @@ +'use strict'; + +var express = require('express'); +var http = require('http'); +var Path = require('path'); + +module.exports = function startServer(port, path, callback) { + var app = express(); + var server = http.createServer(app); + app.use(express.static(Path.join(__dirname, '/public'))); + app.set('views', Path.join(__dirname, 'app/assets/views')); + app.set('view engine', 'jade'); + app.get('/', function(req, res) { + res.render('index'); + }); + + server.listen(port, callback); + +}; diff --git a/appengine/brunch/package.json b/appengine/brunch/package.json new file mode 100644 index 0000000000..c1cf47d312 --- /dev/null +++ b/appengine/brunch/package.json @@ -0,0 +1,29 @@ +{ + "name": "appengine-brunch", + "description": "An example of Brunch with ES6 running on Google App Engine.", + "version": "0.0.1", + "private": true, + "license": "Apache Version 2.0", + "author": "targunp", + "engines": { + "node": "~4.2" + }, + "scripts": { + "start": "node app.js", + "watch": "brunch watch --server", + "deploy": "gcloud preview app deploy", + "build": "brunch build --production" + }, + "dependencies": { + "auto-reload-brunch": "^2.0.0", + "babel-brunch": "~6.0.0", + "babel-preset-es2015": "~6.3.13", + "brunch": "^2.4.0", + "clean-css-brunch": "^2.0.0", + "css-brunch": "^2.0.0", + "express": "^4.13.4", + "jade": "^1.11.0", + "javascript-brunch": "^2.0.0", + "uglify-js-brunch": "^2.0.0" + } +} diff --git a/test/appengine/all.test.js b/test/appengine/all.test.js index b3ca3e83e7..f5a1ad3d03 100644 --- a/test/appengine/all.test.js +++ b/test/appengine/all.test.js @@ -51,6 +51,13 @@ var sampleTests = [ args: ['server.js'], msg: 'Express.js + Bower on Google App Engine.' }, + { + dir: 'brunch', + cmd: 'node', + args: ['app.js'], + msg: 'Brunch with ES6 running on Google App Engine.', + TRAVIS: true + }, { dir: 'cloudsql', cmd: 'node',