|
| 1 | +var path = require('path'); |
| 2 | +var _ = require('lodash'); |
| 3 | + |
| 4 | +module.exports = function (grunt) { |
| 5 | + grunt.initConfig( |
| 6 | + { |
| 7 | + pkg: grunt.file.readJSON('package.json'), |
| 8 | + |
| 9 | + // Default values |
| 10 | + version: 'NEXT', |
| 11 | + name: 'tweenjs', |
| 12 | + docsZip: "<%= pkg.name %>_docs-<%= version %>.zip", |
| 13 | + |
| 14 | + // Setup doc names / paths. |
| 15 | + docsName: '<%= pkg.name %>_docs-<%= version %>', |
| 16 | + docsZip: "<%= docsName %>.zip", |
| 17 | + docsFolder: "./output/<%= docsName %>/", |
| 18 | + |
| 19 | + // Setup Uglify for JS minification. |
| 20 | + uglify: { |
| 21 | + options: { |
| 22 | + banner: grunt.file.read('LICENSE'), |
| 23 | + preserveComments: "some", |
| 24 | + compress: { |
| 25 | + global_defs: { |
| 26 | + "DEBUG": false |
| 27 | + } |
| 28 | + }, |
| 29 | + }, |
| 30 | + build: { |
| 31 | + files: { |
| 32 | + 'output/<%= pkg.name.toLowerCase() %>-<%= version %>.min.js': getConfigValue('source'), |
| 33 | + } |
| 34 | + } |
| 35 | + }, |
| 36 | + |
| 37 | + // Build docs using yuidoc |
| 38 | + yuidoc: { |
| 39 | + compile: { |
| 40 | + name: '<%= pkg.name %>', |
| 41 | + version: '<%= version %>', |
| 42 | + description: '<%= pkg.description %>', |
| 43 | + url: '<%= pkg.url %>', |
| 44 | + logo: '<%= pkg.logo %>', |
| 45 | + options: { |
| 46 | + paths: ['../src/'], |
| 47 | + outdir: '<%= docsFolder %>', |
| 48 | + linkNatives: true, |
| 49 | + attributesEmit: true, |
| 50 | + selleck: true, |
| 51 | + helpers: ["./path.js"], |
| 52 | + themedir: "createjsTheme/" |
| 53 | + } |
| 54 | + } |
| 55 | + }, |
| 56 | + |
| 57 | + compress: { |
| 58 | + build: { |
| 59 | + options: { |
| 60 | + mode:'zip', |
| 61 | + archive:'output/<%= docsZip %>' |
| 62 | + }, |
| 63 | + files: [ |
| 64 | + {expand:true, src:'**', cwd:'<%= docsFolder %>'} |
| 65 | + ] |
| 66 | + } |
| 67 | + }, |
| 68 | + |
| 69 | + copy: { |
| 70 | + docsZip: { |
| 71 | + files: [ |
| 72 | + {expand:true, cwd:'output/', src:'<%= docsZip %>', dest:'../docs/'} |
| 73 | + ] |
| 74 | + }, |
| 75 | + docsSite: { |
| 76 | + files: [ |
| 77 | + {expand:true, cwd:'<%= docsFolder %>', src:'**', dest:getConfigValue('docs_out_path')} |
| 78 | + ] |
| 79 | + }, |
| 80 | + src: { |
| 81 | + files: [ |
| 82 | + {expand: true, cwd:'./output/', src: '*.js', dest: '../lib/'} |
| 83 | + ] |
| 84 | + } |
| 85 | + }, |
| 86 | + |
| 87 | + updateversion: { |
| 88 | + build: { |
| 89 | + file: '../src/tweenjs/version.js', |
| 90 | + version: '<%= version %>' |
| 91 | + }, |
| 92 | + } |
| 93 | + } |
| 94 | + ); |
| 95 | + |
| 96 | + function getBuildConfig() { |
| 97 | + // Read the global settings file first. |
| 98 | + var config = grunt.file.readJSON('config.json'); |
| 99 | + |
| 100 | + // If we have a config.local.json .. prefer its values. |
| 101 | + if (grunt.file.exists('config.local.json')) { |
| 102 | + var config2 = grunt.file.readJSON('config.local.json'); |
| 103 | + _.extend(config, config2); |
| 104 | + } |
| 105 | + |
| 106 | + return config; |
| 107 | + } |
| 108 | + |
| 109 | + function getConfigValue(name) { |
| 110 | + var config = grunt.config.get('buildConfig'); |
| 111 | + |
| 112 | + if (config == null) { |
| 113 | + config = getBuildConfig(); |
| 114 | + grunt.config.set('buildConfig', config); |
| 115 | + } |
| 116 | + |
| 117 | + return config[name]; |
| 118 | + } |
| 119 | + |
| 120 | + // Load all the tasks we need |
| 121 | + grunt.loadNpmTasks('grunt-contrib-uglify'); |
| 122 | + grunt.loadNpmTasks('grunt-contrib-yuidoc'); |
| 123 | + grunt.loadNpmTasks('grunt-contrib-compress'); |
| 124 | + grunt.loadNpmTasks('grunt-contrib-copy'); |
| 125 | + grunt.loadTasks('tasks/'); |
| 126 | + |
| 127 | + /** |
| 128 | + * Build the docs using YUIdocs. |
| 129 | + */ |
| 130 | + grunt.registerTask('docs', [ |
| 131 | + "yuidoc", "compress", "copy:docsZip" |
| 132 | + ]); |
| 133 | + |
| 134 | + /** |
| 135 | + * Sets out version to the version in package.json (defaults to NEXT) |
| 136 | + */ |
| 137 | + grunt.registerTask('setVersion', function () { |
| 138 | + grunt.config.set('version', grunt.config.get('pkg').version); |
| 139 | + }); |
| 140 | + |
| 141 | + /** |
| 142 | + * Task for exporting a next build. |
| 143 | + * |
| 144 | + */ |
| 145 | + grunt.registerTask('next', [ |
| 146 | + "coreBuild" |
| 147 | + ]); |
| 148 | + |
| 149 | + /** |
| 150 | + * Task for exporting a release build (version based on package.json) |
| 151 | + * |
| 152 | + */ |
| 153 | + grunt.registerTask('build', [ |
| 154 | + "setVersion", "coreBuild", "copy:docsSite" |
| 155 | + ]); |
| 156 | + |
| 157 | + /** |
| 158 | + * Main build task, always runs after next or build. |
| 159 | + * |
| 160 | + */ |
| 161 | + grunt.registerTask('coreBuild', [ |
| 162 | + "updateversion", "uglify", "docs", "copy:src" |
| 163 | + ]); |
| 164 | +}; |
0 commit comments