Created
October 25, 2013 16:22
-
-
Save tkh44/7157423 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = function(grunt) { | |
| 'use strict'; | |
| grunt.loadNpmTasks('grunt-sails-linker'); | |
| // Project configuration. | |
| grunt.initConfig({ | |
| pkg: grunt.file.readJSON('package.json'), | |
| copy: { | |
| dev: { | |
| files: [ | |
| { | |
| expand: true, | |
| cwd: './assets', | |
| src: ['**/*', '!**/*.less'], | |
| dest: '.tmp/public' | |
| } | |
| ] | |
| }, | |
| build: { | |
| files: [ | |
| { | |
| expand: true, | |
| cwd: '.tmp/public', | |
| src: ['**/*', '!**/*.less'], | |
| dest: 'www' | |
| } | |
| ] | |
| } | |
| }, | |
| clean: { | |
| dev: ['.tmp/public/**'], | |
| build: ['www'] | |
| }, | |
| jst: { | |
| dev: { | |
| options: { | |
| templateSettings: { | |
| interpolate : /\{\{(.+?)\}\}/g | |
| } | |
| }, | |
| files: { | |
| '.tmp/public/jst.js': ['assets/templates/**/*.html'] | |
| } | |
| } | |
| }, | |
| less: { | |
| dev: { | |
| files: [ | |
| { | |
| expand: true, | |
| cwd: 'assets/styles/', | |
| src: ['styles.less'], | |
| dest: '.tmp/public/styles/', | |
| ext: '.css' | |
| } | |
| ] | |
| } | |
| }, | |
| 'sails-linker': { | |
| devJs: { | |
| options: { | |
| startTag: '<!--SCRIPTS-->', | |
| endTag: '<!--SCRIPTS END-->', | |
| fileTmpl: '\n<script src="%s"></script>\n', | |
| appRoot: '.tmp/public/' | |
| }, | |
| files: { | |
| '.tmp/public/index.html': [ | |
| '.tmp/public/mixins/jquery.js', | |
| '.tmp/public/mixins/mast.dev.js', | |
| '.tmp/public/mixins/jquery.hammer.min.js', | |
| '.tmp/public/mixins/backbone-localstorage.js', | |
| '.tmp/public/mixins/**/*.js', | |
| '.tmp/public/marth/js/**/*.js', | |
| '.tmp/public/js/**/*.js' | |
| ] | |
| } | |
| }, | |
| devStyles: { | |
| options: { | |
| startTag: '<!--STYLES-->', | |
| endTag: '<!--STYLES END-->', | |
| fileTmpl: '\n<link rel="stylesheet" href="%s">\n', | |
| appRoot: '.tmp/public/' | |
| }, | |
| files: { | |
| '.tmp/public/index.html': ['.tmp/public/mixins/**/*.css', '.tmp/public/styles/**/*.css'] | |
| } | |
| }, | |
| // Bring in JST template object | |
| devTpl: { | |
| options: { | |
| startTag: '<!--TEMPLATES-->', | |
| endTag: '<!--TEMPLATES END-->', | |
| fileTmpl: '\n<script type="text/javascript" src="%s"></script>\n', | |
| appRoot: '.tmp/public/' | |
| }, | |
| files: { | |
| '.tmp/public/index.html': ['.tmp/public/jst.js'] | |
| } | |
| } | |
| }, | |
| watch : { | |
| api: { | |
| files: ['api/**/*'] | |
| }, | |
| assets: { | |
| files: ['assets/**/*'], | |
| tasks: ['assetsChanged'] | |
| } | |
| } | |
| }); | |
| // Get path to core grunt dependencies from Sails | |
| var depsPath = grunt.option('gdsrc'); | |
| grunt.loadTasks(depsPath + '/grunt-contrib-clean/tasks'); | |
| grunt.loadTasks(depsPath + '/grunt-contrib-copy/tasks'); | |
| grunt.loadTasks(depsPath + '/grunt-sails-linker/tasks'); | |
| grunt.loadTasks(depsPath + '/grunt-contrib-jst/tasks'); | |
| grunt.loadTasks('node_modules/grunt-contrib-less/tasks'); | |
| grunt.loadTasks(depsPath + '/grunt-contrib-watch/tasks'); | |
| // When Sails is lifted: | |
| grunt.registerTask('default', [ | |
| 'reloadAssets', | |
| 'watch' | |
| ]); | |
| grunt.registerTask('reloadAssets', [ | |
| 'clean:dev', | |
| 'jst:dev', | |
| 'less:dev', | |
| 'copy:dev', | |
| 'sails-linker:devJs', | |
| 'sails-linker:devStyles', | |
| 'sails-linker:devTpl' | |
| ]); | |
| // When assets are changed: | |
| grunt.registerTask('assetsChanged', [ | |
| 'reloadAssets' | |
| ]); | |
| // Build the assets into a web accessable folder. | |
| grunt.registerTask('build', [ | |
| 'reloadAssets', | |
| 'clean:build', | |
| 'copy:build' | |
| ]); | |
| // When API files are changed: | |
| grunt.event.on('watch', function(action, filepath) { | |
| grunt.log.writeln(filepath + ' has ' + action); | |
| // Send a request to a development-only endpoint on the server | |
| // which will reuptake the file that was changed. | |
| var baseurl = grunt.option('baseurl'); | |
| var gruntSignalRoute = grunt.option('signalpath'); | |
| var url = baseurl + gruntSignalRoute + '?action=' + action + '&filepath=' + filepath; | |
| require('http').get(url) | |
| .on('error', function(e) { | |
| console.error(filepath + ' has ' + action + ', but could not signal the Sails.js server: ' + e.message); | |
| }); | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment