From 95c16e274f85d67e5b189fec0b8708c5e7f040fa Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Sat, 16 Mar 2013 23:50:40 -0700 Subject: [PATCH] new lumbar-based solution for building fullcalendar submodules --- .gitignore | 1 + Gruntfile.js | 221 +++++++++++++++++----------------- build/loader.js | 312 ------------------------------------------------ build/watch | 1 + files.js | 57 --------- lumbar.json | 75 ++++++++++++ package.json | 3 +- 7 files changed, 187 insertions(+), 483 deletions(-) delete mode 100644 build/loader.js create mode 100755 build/watch delete mode 100644 files.js create mode 100644 lumbar.json diff --git a/.gitignore b/.gitignore index 383201e..9707025 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ build/out +build/archive build/component dist diff --git a/Gruntfile.js b/Gruntfile.js index 7ac0250..1ef60b7 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,9 +1,7 @@ -var _ = require('underscore'); - - module.exports = function(grunt) { + var _ = require('underscore'); // Load required NPM tasks. // You must first run `npm install` in the project's root directory to get these dependencies. @@ -12,197 +10,194 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-copy'); grunt.loadNpmTasks('grunt-contrib-compress'); grunt.loadNpmTasks('grunt-contrib-clean'); + grunt.loadNpmTasks('lumbar'); - - var fileIndex = require('./files.js'); // lists of source/dependency files - var loaderUtils = require('./build/loader.js'); - - // read config files, and combine into one "meta" object + // Parse config files + var lumbarConfig = grunt.file.readJSON('lumbar.json'); var packageConfig = grunt.file.readJSON('package.json'); var componentConfig = grunt.file.readJSON('component.json'); var pluginConfig = grunt.file.readJSON('fullcalendar.jquery.json'); - var meta = _.extend({}, packageConfig, componentConfig, pluginConfig); - // this will eventually get passed to grunt.initConfig + // This will eventually get passed to grunt.initConfig() + // Initialize multitasks... var config = { - meta: meta, // do this primarily for templating (<%= %>) - concat: {}, // initialize multitasks... + concat: {}, uglify: {}, copy: {}, compress: {}, clean: {} }; + // Combine configs for the "meta" template variable (<%= meta.whatever %>) + config.meta = _.extend({}, packageConfig, componentConfig, pluginConfig); - /* Important Top-Level Tasks + // The "grunt" command with no arguments + grunt.registerTask('default', 'archive'); + + + + /* FullCalendar Modules ----------------------------------------------------------------------------------------------------*/ - grunt.registerTask('default', 'dist'); // what will be run with a plain old "grunt" command - - grunt.registerTask('dist', 'Create a distributable ZIP file', [ - 'clean:build', - 'concat', - 'uglify', - 'copy:dependencies', - 'copy:demos', - 'copy:misc', - 'compress' + grunt.registerTask('modules', 'Build the FullCalendar modules', [ + 'lumbar:build', + 'concat:moduleVariables', + 'uglify:modules' ]); - - /* Concatenate Submodules - ----------------------------------------------------------------------------------------------------*/ - - _.each(fileIndex.fullcalendar, function(submodule, name) { - - if (submodule.js) { - config.concat[name + '-js'] = { - options: { - process: true // replace template variables - }, - src: submodule.js, - dest: 'build/out/fullcalendar/' + name + '.js' - }; + // assemble modules + config.lumbar = { + build: { + build: 'lumbar.json', + output: 'build/out' // a directory. lumbar doesn't like trailing slash } + }; - if (submodule.css) { - config.concat[name + '-css'] = { - options: { - process: true // replace template variables - }, - src: submodule.css, - dest: 'build/out/fullcalendar/' + name + '.css' - }; - } + // replace template variables (<%= %>), IN PLACE + config.concat.moduleVariables = { + options: { + process: true // replace + }, + expand: true, + cwd: 'build/out/', + src: [ '*.js', '*.css', '!jquery*' ], + dest: 'build/out/' + }; - if (submodule.printCss) { - config.concat[name + '-print-css'] = { - options: { - process: true // replace template variables - }, - src: submodule.printCss, - dest: 'build/out/fullcalendar/' + name + '.print.css' - }; - } - - }); - - - /* Minify the JavaScript - ----------------------------------------------------------------------------------------------------*/ - - config.uglify.all = { + // create minified versions (*.min.js) + config.uglify.modules = { options: { preserveComments: 'some' // keep comments starting with /*! }, expand: true, - src: 'build/out/fullcalendar/*.js', + src: 'build/out/fullcalendar.js', // only do it for fullcalendar.js ext: '.min.js' } + config.clean.modules = 'build/out/*'; - /* Copy Dependencies + + + /* Archive ----------------------------------------------------------------------------------------------------*/ - config.copy.dependencies = { + grunt.registerTask('archive', 'Create a distributable ZIP archive', [ + 'clean:modules', + 'clean:archive', + 'modules', + 'copy:archiveModules', + 'copy:archiveDependencies', + 'copy:archiveDemos', + 'copy:archiveMisc', + 'compress:archive' + ]); + + // copy FullCalendar modules into ./fullcalendar/ directory + config.copy.archiveModules = { + expand: true, + cwd: 'build/out/', + src: [ '*.js', '*.css', '!jquery*' ], + dest: 'build/archive/fullcalendar/' + }; + + // copy jQuery and jQuery UI into the ./jquery/ directory + config.copy.archiveDependencies = { expand: true, flatten: true, src: [ - fileIndex['jquery'].js, - fileIndex['jquery-ui'].js + // we want to retain the original filenames + lumbarConfig.modules['jquery'].scripts[0], + lumbarConfig.modules['jquery-ui'].scripts[0] ], - dest: 'build/out/jquery/' + dest: 'build/archive/jquery/' }; - - /* Demos - ----------------------------------------------------------------------------------------------------*/ - - config.copy.demos = { + // copy demo files into ./demos/ directory + config.copy.archiveDemos = { options: { - // while copying demo files over, replace loader.js " -} - - -function buildCssTag(path) { - return ""; -} - - -function buildPrintCssTag(path) { - return ""; -} - - -/* DOM Utilities -====================================================================================================*/ - -/* - * Loads an external JS file in the global scope, and calls `callback` when done. - * If the JS file is a CommonJS module, the module's "exports" will be given to the callback. - */ -function loadScript(path, callback) { - var funcName = ('_scriptCallback' + Math.random()).replace('.', ''); - document.write(""); - document.write(""); - document.write(""); - window[funcName] = function() { - removeLastScript(); - removeLastScript(); - removeLastScript(); - var exports = module.exports; - delete window.module; - delete window.exports; - delete window[funcName]; - if (callback) { - callback(exports); - } - }; -} - - -function removeLastScript() { - var script = getLastScript(); - script.parentNode.removeChild(script); -} - - -function getLastScript() { - var scripts = document.getElementsByTagName('script'); - return scripts[scripts.length - 1]; -} - - -function getQueryStringVar(name) { - var qs = extractQueryString(window.location.href); - var match = new RegExp(name + '=([^&]*)').exec(qs); - if (match) { - return match[1]; - } -} - - -function getCookieVar(name) { - var match = new RegExp(name + '=([^;]*)').exec(document.cookie); - if (match) { - return match[1]; - } -} - - -/* File Path Utilities -====================================================================================================*/ - - -function basename(path) { - var match = /.*\/(.*)/.exec(path); - return match ? match[1] : path; -} - - -function dirname(path) { - var match = /(.*)\//.exec(path); - return match ? match[1] : '.'; -} - - -function extractQueryString(url) { - var match = /\?(.*)/.exec(url); - return match ? match[1] : ''; -} - - -/* Language Utilities -====================================================================================================*/ - - -function each(a, f) { - for (var i=0; i