From 8c308c2bf7f658945d80be9d5880361238635f5b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 9 Jun 2015 17:41:40 +0200 Subject: Spawn --- Gruntfile.js | 234 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 234 insertions(+) create mode 100644 Gruntfile.js (limited to 'Gruntfile.js') diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 000000000..d83e60b3d --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,234 @@ +'use strict' + +module.exports = function (grunt) { + var paths = { + dist: 'dist', + tmp: '.tmp', + jade: 'views/**/**/*.jade', + css: 'public/stylesheets/*.css', + vendor: 'public/stylesheets/vendor', + js: 'public/javascripts/*.js', + src: 'src/*.js', + routes: 'routes/**/*.js', + main: './server.js', + browserified: 'public/javascripts/bundle.js', + img: 'public/images/*.{png,jpg,jpeg,gif,webp,svg}', + test: 'tests', + server: 'server.js' + } + + require('time-grunt')(grunt) + + // Project Configuration + grunt.initConfig({ + paths: paths, + pkg: grunt.file.readJSON('package.json'), + browserify: { + dev: { + src: [ paths.js, '!public/javascripts/bundle.js' ], + dest: paths.browserified, + options: { + browserifyOptions: { 'debug': true }, + watch: true + } + }, + dist: { + src: [ paths.js ], + dest: paths.browserified + } + }, + copy: { + dev: { + cwd: 'node_modules/bootstrap/dist/', + src: [ 'css/*', 'fonts/*' ], + expand: true, + dest: paths.vendor + } + }, + clean: { + dev: { + files: [{ + dot: true, + src: [ + paths.browserified + ] + }] + }, + dist: { + files: [{ + dot: true, + src: [ + paths.tmp, + paths.browserified, + '<%= paths.dist %>/*', + '!<%= paths.dist %>/.git*' + ] + }] + } + }, + csslint: { + options: { + csslintrc: '.csslintrc' + }, + src: paths.css + }, + express: { + dev: { + options: { + script: paths.server, + harmony: true, + port: 9000, + node_env: 'development', + debug: true, + background: true + } + }, + test: { + options: { + script: paths.server, + harmony: true, + port: 9000, + node_env: 'test', + background: true, + debug: false + } + }, + prod: { + options: { + script: paths.server, + harmony: true, + port: 9000, + node_env: 'production', + background: false, + debug: false + } + } + }, + filerev: { + options: { + copy: false + }, + dist: { + cwd: 'dist', + src: [ paths.js, paths.css, paths.img ], + dest: 'dist', + expand: true + } + }, + htmlmin: { + dist: { + options: { + removeComments: true, + collapseWhitespace: true + }, + files: [ { + expand: true, + src: [ '<%= paths.dist %>/views/**/**/*.html' ] + } ] + } + }, + imagemin: { + dist: { + files: [{ + expand: true, + cwd: './public/images', + src: '*.{png,jpg,jpeg}', + dest: '<%= paths.dist %>/public/images' + }] + } + }, + jade: { + dist: { + options: { + pretty: true + }, + files: [ { + src: '**/*.jade', + dest: '<%= paths.dist %>/views', + ext: '.html', + cwd: './views', + expand: true + } ] + } + }, + jshint: { + all: { + src: paths.js, + options: { + jshintrc: true + } + } + }, + usemin: { + html: [ '<%= paths.dist %>/views/**/**/*.html' ], + css: [ '<%= paths.dist %>/public/stylesheets/*.css' ], + options: { + assetsDirs: [ '<%= paths.dist %>/public' ] + } + }, + useminPrepare: { + html: '<%= paths.dist %>/views/index.html', + options: { + root: 'public', + dest: '<%= paths.dist %>/public' + } + }, + watch: { + express: { + files: [ paths.main, paths.routes, paths.src ], + tasks: [ 'express:dev' ], + options: { + livereload: true, + spawn: false + } + }, + dev: { + files: [ paths.jade, paths.css, paths.browserified ], + options: { + livereload: true, + nospawn: false + } + } + } + }) + + // Build client javascript and copy bootstrap dependencies + grunt.registerTask('build', [], function () { + grunt.loadNpmTasks('grunt-browserify') + grunt.loadNpmTasks('grunt-contrib-copy') + grunt.loadNpmTasks('grunt-newer') + + grunt.task.run( + 'newer:browserify:dev', + 'newer:copy:dev' + ) + }) + + // Start in dev mode (reload front end files without refresh) + grunt.registerTask('dev', [], function () { + grunt.loadNpmTasks('grunt-browserify') + grunt.loadNpmTasks('grunt-contrib-watch') + grunt.loadNpmTasks('grunt-express-server') + grunt.loadNpmTasks('grunt-contrib-copy') + grunt.loadNpmTasks('grunt-newer') + + grunt.task.run( + 'newer:browserify:dev', + 'newer:copy:dev', + 'express:dev', + 'watch' + ) + }) + + // TODO + // Build dist directory for production + + // Clean build + grunt.registerTask('clean', [], function () { + grunt.loadNpmTasks('grunt-contrib-clean') + + grunt.task.run( + 'clean:dist' + ) + }) +} -- cgit v1.2.3