Skip to content

Commit ac7a04a

Browse files
committed
Use Gulp for frontend.
1 parent 11be5d4 commit ac7a04a

20 files changed

+363
-450
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ bower_components
99
main/index.yaml
1010
main/lib
1111
main/lib.zip
12-
main/static/dst
12+
main/static/dev
1313
main/static/ext
1414
main/static/min
1515
node_modules

README.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,43 @@ Running the Development Environment
1414
-----------------------------------
1515

1616
$ cd /path/to/project-name
17-
$ ./run.py -s
17+
$ gulp
1818

1919
To test it visit `http://localhost:8080/` in your browser.
2020

2121
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2222

23-
To watch for changes of your `*.less` & `*.coffee` files and compile them
24-
automatically to `*.css` & `*.js` execute in another bash:
23+
For a complete list of commands:
2524

26-
$ ./run.py -w
25+
$ gulp help
2726

28-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2927

30-
For a complete list of commands:
28+
Initializing or Resetting the project
29+
------------------------------------
30+
31+
$ cd /path/to/project-name
32+
$ npm install
33+
$ gulp
34+
35+
If something goes wrong you can always do:
3136

32-
$ ./run.py -h
37+
$ gulp initial
38+
$ npm install
39+
$ gulp
3340

3441
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3542

36-
Gulp is used only for watching for changes and live reloading the page.
37-
Install [Gulp][] as a global package:
43+
To install [Gulp][] as a global package:
3844

3945
$ npm install -g gulp
4046

41-
and then from the root execute with no arguments:
42-
43-
$ gulp
44-
4547
Deploying on Google App Engine
4648
------------------------------
4749

48-
Before deploying make sure that the `app.yaml` and `config.py` are up to date
49-
and you ran the `run.py` script to minify all the static files:
50+
$ gulp deploy
5051

51-
$ ./run.py -m
52-
$ appcfg.py update main
52+
Before deploying make sure that the `main/app.yaml` and `gulp/config.coffee`
53+
are up to date.
5354

5455
Tech Stack
5556
----------

gulp/config.coffee

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
paths = require './paths'
2+
3+
config =
4+
ext: [
5+
"#{paths.static.ext}/jquery/dist/jquery.js"
6+
"#{paths.static.ext}/moment/moment.js"
7+
"#{paths.static.ext}/nprogress/nprogress.js"
8+
"#{paths.static.ext}/bootstrap/js/alert.js"
9+
"#{paths.static.ext}/bootstrap/js/button.js"
10+
"#{paths.static.ext}/bootstrap/js/transition.js"
11+
"#{paths.static.ext}/bootstrap/js/collapse.js"
12+
"#{paths.static.ext}/bootstrap/js/dropdown.js"
13+
"#{paths.static.ext}/bootstrap/js/tooltip.js"
14+
]
15+
style: [
16+
"#{paths.src.style}/style.less"
17+
]
18+
script: [
19+
"#{paths.src.script}/**/*.coffee"
20+
]
21+
22+
module.exports = config

gulp/paths.coffee

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
paths =
2+
main: 'main'
3+
4+
deps: {}
5+
py: {}
6+
static: {}
7+
src: {}
8+
temp: {}
9+
10+
11+
paths.temp.root = 'temp'
12+
paths.temp.storage = "#{paths.temp.root}/storage"
13+
paths.temp.venv = "#{paths.temp.root}/venv"
14+
15+
paths.deps.bower_components = 'bower_components'
16+
paths.deps.node_modules = 'node_modules'
17+
paths.deps.py = "#{paths.temp.root}/venv"
18+
paths.deps.py_guard = "#{paths.temp.root}/pip.guard"
19+
20+
paths.py.lib = "#{paths.main}/lib"
21+
paths.py.lib_file = "#{paths.py.lib}.zip"
22+
23+
paths.static.root = "#{paths.main}/static"
24+
paths.static.dev = "#{paths.static.root}/dev"
25+
paths.static.ext = "#{paths.static.root}/ext"
26+
paths.static.min = "#{paths.static.root}/min"
27+
28+
paths.src.root = "#{paths.static.root}/src"
29+
paths.src.script = "#{paths.src.root}/script"
30+
paths.src.style = "#{paths.src.root}/style"
31+
32+
33+
module.exports = paths

gulp/tasks/build.coffee

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
gulp = require('gulp-help') require 'gulp'
2+
minimist = require 'minimist'
3+
$ = do require 'gulp-load-plugins'
4+
paths = require '../paths'
5+
6+
7+
gulp.task 'build',
8+
"Compiles styles & scripts files into minified version
9+
and pack python dependencies into #{paths.py.lib_file}.",
10+
$.sequence 'clean:venv', 'clean', 'install_dependencies', 'ext', ['script', 'style', 'zip']
11+
12+
13+
gulp.task 'rebuild',
14+
'Re-build the project: complete cleaning and install & build all requirements again.',
15+
$.sequence 'initial', 'build'
16+
17+
18+
gulp.task 'deploy', 'Deploying your project on Google App Engine', ['build'], ->
19+
gulp.src('run.py').pipe $.start [
20+
{match: /run.py$/, cmd: 'appcfg.py update main --skip_sdk_update_check'}
21+
]
22+
23+
24+
gulp.task 'run',
25+
'Start the dev_appserver.py. Available options:\n
26+
-o HOST - the host to start the dev_appserver.py\n
27+
-p PORT - the port to start the dev_appserver.py\n
28+
-a="..." - all following args are passed to dev_appserver.py\n', ->
29+
$.sequence('install_dependencies', ['ext:dev', 'script:dev', 'style:dev']) ->
30+
argv = process.argv.slice 2
31+
32+
known_options =
33+
default:
34+
p: ''
35+
o: ''
36+
a: ''
37+
38+
options = minimist argv, known_options
39+
40+
options_str = ''
41+
for k of known_options.default
42+
if options[k]
43+
if k == 'a'
44+
options_str += " --appserver-args \"#{options[k]}\""
45+
else
46+
options_str += " -#{k} #{options[k]}"
47+
48+
gulp.src('run.py').pipe $.start [{match: /run.py$/, cmd: 'python run.py -s'}]

gulp/tasks/clean.coffee

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
del = require 'del'
2+
gulp = require('gulp-help') require 'gulp'
3+
paths = require '../paths'
4+
5+
6+
gulp.task 'clean',
7+
'Clean the project from temp files, Python compiled files
8+
and minified styles and scripts.', ['clean:dev'], ->
9+
del './**/*.pyc'
10+
del './**/*.pyo'
11+
del './**/*.~'
12+
13+
14+
gulp.task 'clean:dev', false, ->
15+
del [paths.static.dev, paths.static.ext, paths.static.min]
16+
17+
18+
gulp.task 'clean:venv', false, ->
19+
del [paths.py.lib, paths.py.lib_file]
20+
del paths.deps.py
21+
del paths.deps.py_guard
22+
23+
24+
gulp.task 'initial',
25+
'Complete cleaning the project: cleans all the
26+
Pip requirements, temp files, Node & Bower related tools and libraries.',
27+
['clean', 'clean:venv'], ->
28+
del [paths.deps.bower_components, paths.deps.node_modules]
29+
30+
31+
gulp.task 'flush', 'Clears the datastore, blobstore, etc', ->
32+
del paths.temp.storage
33+

gulp/tasks/deps.coffee

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
fs = require 'fs'
2+
gulp = require('gulp-help') require 'gulp'
3+
main_bower_files = require 'main-bower-files'
4+
$ = do require 'gulp-load-plugins'
5+
paths = require '../paths'
6+
7+
8+
gulp.task 'npm', false, ->
9+
gulp.src('package.json')
10+
.pipe $.plumber()
11+
.pipe do $.start
12+
13+
14+
gulp.task 'bower', false, ->
15+
cmd = 'node_modules/.bin/bower install'
16+
if /^win/.test process.platform
17+
cmd = cmd.replace /\//g, '\\'
18+
start_map = [{match: /bower.json$/, cmd: cmd}]
19+
gulp.src('bower.json')
20+
.pipe $.plumber()
21+
.pipe $.start start_map
22+
23+
24+
gulp.task 'copy_bower_files', false, ['bower'], ->
25+
gulp.src do main_bower_files, base: paths.deps.bower_components
26+
.pipe gulp.dest paths.static.ext
27+
28+
29+
gulp.task 'pip', false, ->
30+
gulp.src('run.py').pipe $.start [{match: /run.py$/, cmd: 'python run.py -d'}]
31+
32+
33+
gulp.task 'zip', false, ->
34+
fs.exists paths.py.lib_file, (exists) ->
35+
if not exists
36+
fs.exists paths.py.lib, (exists) ->
37+
if exists
38+
gulp.src "#{paths.py.lib}/**"
39+
.pipe $.plumber()
40+
.pipe $.zip 'lib.zip'
41+
.pipe gulp.dest paths.main
42+
43+
44+
gulp.task 'install_dependencies', false, $.sequence 'npm', 'pip', 'copy_bower_files'

gulp/tasks/ext.coffee

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
gulp = require('gulp-help') require 'gulp'
2+
$ = do require 'gulp-load-plugins'
3+
config = require '../config'
4+
paths = require '../paths'
5+
utils = require '../utils'
6+
7+
8+
gulp.task 'ext', false, ->
9+
gulp.src config.ext
10+
.pipe $.plumber(errorHandler: utils.onError)
11+
.pipe $.concat 'ext.js'
12+
.pipe do $.uglify
13+
.pipe $.size {title: 'Minified ext libs'}
14+
.pipe gulp.dest "#{paths.static.min}/script"
15+
16+
17+
gulp.task 'ext:dev', false, ->
18+
gulp.src config.ext
19+
.pipe $.plumber(errorHandler: utils.onError)
20+
.pipe do $.sourcemaps.init
21+
.pipe $.concat 'ext.js'
22+
.pipe do $.sourcemaps.write
23+
.pipe gulp.dest "#{paths.static.dev}/script"

gulp/tasks/scripts.coffee

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
gulp = require('gulp-help') require 'gulp'
2+
$ = do require 'gulp-load-plugins'
3+
config = require '../config'
4+
paths = require '../paths'
5+
utils = require '../utils'
6+
7+
8+
gulp.task 'script', false, ->
9+
gulp.src config.script
10+
.pipe $.plumber(errorHandler: utils.onError)
11+
.pipe $.coffee()
12+
.pipe $.concat 'script.js'
13+
.pipe do $.uglify
14+
.pipe $.size {title: 'Minified scripts'}
15+
.pipe gulp.dest "#{paths.static.min}/script"
16+
17+
18+
gulp.task 'script:dev', false, ->
19+
gulp.src config.script
20+
.pipe $.plumber(errorHandler: utils.onError)
21+
.pipe do $.sourcemaps.init
22+
.pipe $.coffee()
23+
.pipe $.concat 'script.js'
24+
.pipe do $.sourcemaps.write
25+
.pipe gulp.dest "#{paths.static.dev}/script"

gulp/tasks/styles.coffee

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
gulp = require('gulp-help') require 'gulp'
2+
$ = do require 'gulp-load-plugins'
3+
config = require '../config'
4+
paths = require '../paths'
5+
utils = require '../utils'
6+
7+
8+
gulp.task 'style', false, ->
9+
gulp.src config.style
10+
.pipe $.plumber(errorHandler: utils.onError)
11+
.pipe do $.less
12+
.pipe $.autoprefixer {cascade: false}
13+
.pipe do $.minifyCss
14+
.pipe $.size {title: 'Minified styles'}
15+
.pipe gulp.dest "#{paths.static.min}/style"
16+
17+
18+
gulp.task 'style:dev', false, ->
19+
gulp.src config.style
20+
.pipe $.plumber(errorHandler: utils.onError)
21+
.pipe do $.sourcemaps.init
22+
.pipe do $.less
23+
.pipe do $.sourcemaps.write
24+
.pipe $.autoprefixer {map: true}
25+
.pipe gulp.dest "#{paths.static.dev}/style"
26+

gulp/tasks/watch.coffee

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
gulp = require('gulp-help') require 'gulp'
2+
$ = do require 'gulp-load-plugins'
3+
paths = require '../paths'
4+
5+
6+
gulp.task 'reload', false, ->
7+
do $.livereload.listen
8+
gulp.watch([
9+
"#{paths.static.root}/**/*.css"
10+
"#{paths.static.root}/**/*.js"
11+
"#{paths.main}/**/*.html"
12+
"#{paths.main}/**/*.py"
13+
]).on 'change', $.livereload.changed
14+
15+
16+
gulp.task 'ext_watch_rebuild', false, (callback) ->
17+
$.sequence('copy_bower_files', 'ext:dev', 'style:dev') callback
18+
19+
20+
gulp.task 'watch', false, ->
21+
gulp.watch 'requirements.txt', ['pip']
22+
gulp.watch 'package.json', ['npm']
23+
gulp.watch 'bower.json', ['ext_watch_rebuild']
24+
gulp.watch 'gulp/config.coffee', ['style:dev', 'script:dev']
25+
gulp.watch paths.static.ext, ['ext:dev']
26+
gulp.watch "#{paths.src.script}/**/*.coffee", ['script:dev']
27+
gulp.watch "#{paths.src.style}/**/*.less", ['style:dev']

gulp/utils.coffee

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
$ = do require 'gulp-load-plugins'
2+
3+
onError = (err) ->
4+
do $.util.beep
5+
console.log err
6+
this.emit 'end'
7+
8+
module.exports = {onError}

0 commit comments

Comments
 (0)