var path = require('path'); var _ = require('lodash'); module.exports = function (grunt) { grunt.initConfig( { pkg: grunt.file.readJSON('package.json'), // Default values version: 'NEXT', fileVersion: '-<%= version %>', name: 'tweenjs', // Setup doc names / paths. docsName: '<%= pkg.name %>_docs<%= fileVersion %>', docsZip: "<%= docsName %>.zip", // Setup Uglify for JS minification. uglify: { options: { banner: grunt.file.read('LICENSE'), preserveComments: "some", compress: { global_defs: { "DEBUG": false } }, mangle: { except: getExclusions() } }, build: { files: { 'output/<%= pkg.name.toLowerCase() %><%= fileVersion %>.min.js': getConfigValue('source'), } } }, concat: { options: { separator: '', process: function(src, filepath) { // Remove a few things from each file, they will be added back at the end. // Strip the license header. var file = src.replace(/^(\/\*\s)[\s\S]+?\*\//, "") // Strip namespace // file = file.replace(/(this.createjs)\s=\s\1.*/, ""); // Strip namespace label file = file.replace(/\/\/\s*namespace:/, ""); // Strip @module file = file.replace(/\/\*\*[\s\S]+?@module[\s\S]+?\*\//, ""); // Clean up white space file = file.replace(/^\s*/, ""); file = file.replace(/\s*$/, ""); // Append on the class name file = "\n\n//##############################################################################\n"+ "// " + path.basename(filepath) + "\n" + "//##############################################################################\n\n"+ file; return file; } }, build: { files: { 'output/<%= pkg.name.toLowerCase() %><%= fileVersion %>.js': getCombinedSource() } } }, // Build docs using yuidoc yuidoc: { compile: { name: '<%= pkg.name %>', version: '<%= version %>', description: '<%= pkg.description %>', url: '<%= pkg.url %>', logo: '<%= pkg.logo %>', options: { paths: ['./'], outdir: '<%= docsFolder %>', linkNatives: true, attributesEmit: true, selleck: true, helpers: ["../build/path.js"], themedir: "../build/createjsTheme/" } } }, compress: { build: { options: { mode:'zip', archive:'output/<%= docsZip %>' }, files: [ {expand:true, src:'**', cwd:'<%= docsFolder %>'} ] } }, clean: { docs: { src: ["<%= docsFolder %>/assets/scss"] } }, copy: { docsZip: { files: [ {expand: true, cwd:'output/', src:'<%= docsZip %>', dest:'../docs/'} ] }, docsSite: { files: [ {expand:true, cwd:'<%= docsFolder %>', src:'**', dest:getConfigValue('docs_out_path')} ] }, src: { files: [ {expand: true, cwd:'./output/', src: '*<%=fileVersion %>*.js', dest: '../lib/'} ] } }, updateversion: { tween: { file: '../src/tweenjs/version.js', version: '<%= version %>' } }, clearversion: { tween: { file: '../src/tweenjs/version.js' } }, sass: { docs: { options: { style: 'compressed', sourcemap:"none" }, files: { 'createjsTheme/assets/css/main.css': 'createjsTheme/assets/scss/main.scss' } } } } ); function getBuildConfig() { // Read the global settings file first. var config = grunt.file.readJSON('config.json'); // If we have a config.local.json .. prefer its values. if (grunt.file.exists('config.local.json')) { var config2 = grunt.file.readJSON('config.local.json'); _.extend(config, config2); } return config; } function getConfigValue(name) { var config = grunt.config.get('buildConfig'); if (config == null) { config = getBuildConfig(); grunt.config.set('buildConfig', config); } return config[name]; } function getCombinedSource() { var configs = [ {cwd: '', config:'config.json', source:'source'} ]; return combineSource(configs); } function combineSource(configs) { // Pull out all the source paths. var sourcePaths = []; for (var i=0;i/"); }); grunt.registerTask('resetBase', "Internal utility task to reset the base, after setDocsBase", function() { grunt.file.setBase('../build'); grunt.config.set('docsFolder', "./output/<%= docsName %>/"); }); /** * Build the docs using YUIdocs. */ grunt.registerTask('docs', [ "sass", "setDocsBase", "yuidoc", "resetBase", "clean:docs", "compress", "copy:docsZip" ]); /** * Sets out version to the version in package.json (defaults to NEXT) */ grunt.registerTask('setVersion', function () { grunt.config.set('version', grunt.config.get('pkg').version); grunt.config.set('fileVersion', ''); }); /** * Task for exporting a next build. * */ grunt.registerTask('next', function() { grunt.config("buildArgs", this.args || []); getBuildArgs(); grunt.task.run(["coreBuild", "clearBuildArgs"]); }); /** * Task for exporting only the next lib. * */ grunt.registerTask('nextlib', [ "updateversion", "combine", "uglify", "clearversion", "copy:src" ]); /** Aliased task for WebStorm quick-run */ grunt.registerTask('_next_tween', ["next"]); /** * Task for exporting a release build (version based on package.json) * */ grunt.registerTask('build', function() { grunt.config("buildArgs", this.args || []); getBuildArgs(); grunt.task.run(["setVersion", "coreBuild", "updatebower", "copy:docsSite", "clearBuildArgs"]); }); grunt.registerTask('clearBuildArgs', function() { grunt.config("buildArgs", []); }); /** * Main build task, always runs after next or build. * */ grunt.registerTask('coreBuild', [ "updateversion", "combine", "uglify", "clearversion", "docs", "copy:src" ]); /** * Task for exporting combined view. * */ grunt.registerTask('combine', 'Combine all source into a single, un-minified file.', [ "concat" ]); };