From a7dc4d8ae4eac68e80dcc54a7613c981a6957c6e Mon Sep 17 00:00:00 2001 From: Olmo Maldonado Date: Mon, 17 Feb 2014 13:01:15 -0600 Subject: [PATCH] Using grunt-mootools-packager --- Gruntfile.js | 166 +++++++++++------------------------------------------------ package.json | 3 +- 2 files changed, 31 insertions(+), 138 deletions(-) rewrite Gruntfile.js (91%) diff --git a/Gruntfile.js b/Gruntfile.js dissimilarity index 91% index 8da056b1..d118a929 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,136 +1,30 @@ -"use strict"; - -var debug = require('debug')('build'), - YAML = require('js-yaml'); - -function dump(input){ - debug((JSON.stringify(input) || '').replace(/",/g, '",\n')); - process.exit(0); -} - -module.exports = function(grunt){ - - grunt.loadNpmTasks('grunt-karma'); - - grunt.initConfig({ - - build: { - options: { - name: 'Core' - }, - all: { - src: 'Source/**/*.js', - dest: 'mootools-all.js' - }, - nocompat: { - options: { - strip: ['.*compat'] - }, - src: 'Source/**/*.js', - dest: 'mootools-nocompat.js' - } - } - - }); - - var DESC_REGEXP = /\/\*\s*^---([.\s\S]*)^(?:\.\.\.|---)\s*\*\//m; - var STRIP_EXP = ['\\/[\\/*]\s*<', '>([.\\s\\S]*?)<\\/', '>(?:\\s*\\*\\/)?']; - var registry = {}, buffer = [], included = {}, set = []; - - function validDefinition(object) { - return !!object.name && !!(object.requires || object.provides); - } - - function getPrimaryKey(definition){ - return definition.package + '/' + definition.name; - } - - // provides keys to the source file based on the name and the components provided - function getKeys(definition){ - return definition.provides.map(function(component){ - return definition.package + '/' + component; - }).concat(getPrimaryKey(definition)); - } - - function toArray(object){ - if (!object) return []; - if (object.charAt) return [object]; - return grunt.util.toArray(object); - } - - function resolveDeps(definition){ - definition.requires.forEach(function(key){ - resolveDeps(registry[key]); - }); - if (included[definition.key]) return; - buffer.push(definition); - included[definition.key] = true; - } - - grunt.registerMultiTask('build', 'Build MooTools.js with all modules.', function(){ - - var options = this.options({ - only: false, - strip: [], - separator: grunt.util.linefeed - }); - - this.files.forEach(function(f){ - // expand and filter by existence - var files = grunt.file.expand({nonull: true}, f.src).filter(function(filepath){ - return grunt.file.exists(filepath) || grunt.log.warn('empty or invalid: ' + filepath); - }); - - // read files and populate registry map - files.forEach(function(filepath){ - - var source = grunt.file.read(filepath); - var definition = YAML.load(source.match(DESC_REGEXP)[1] || ''); - - if (!definition || !validDefinition(definition)) return grunt.log.error('invalid definition: ' + filepath); - - definition.package = options.name; - definition.source = source; - definition.key = getPrimaryKey(definition); - definition.provides = toArray(definition.provides); - // assume requires are relative to the package, if no package provided - definition.requires = toArray(definition.requires).map(function(component){ - return ~component.indexOf('/') ? component : (definition.package + '/' + component); - }); - - // track all files collected, used to check that all sources were included - set.push(definition.key); - - getKeys(definition).forEach(function(key){ - if (key in registry && key != definition.key){ - return grunt.log.warn('key: ' + key + ', has repeated definition: ' + filepath); - } - registry[key] = definition; - }); - - }); - - if (!options.only){ - // include all sources - for (var key in registry) if (key in registry) resolveDeps(registry[key]); - if (set.length != buffer.length) return grunt.log.error('Could not include all sources.'); - } else { - toArray(options.only).forEach(resolveDeps); - } - - buffer = buffer.map(function(def){ return def.source; }).join(options.separator); - - // strip blocks - toArray(options.strip).forEach(function(block){ - var regexp = RegExp(STRIP_EXP.join(block), 'gm'); - buffer = buffer.replace(regexp, ''); - }); - - grunt.file.write(f.dest, buffer); - }); - - }); - - grunt.registerTask('default', ['build']); - -}; +"use strict"; + +module.exports = function(grunt){ + + grunt.loadNpmTasks('grunt-mootools-packager'); + + grunt.initConfig({ + + packager: { + options: { + name: 'Core' + }, + all: { + src: 'Source/**/*.js', + dest: 'mootools-all.js' + }, + nocompat: { + options: { + strip: ['.*compat'] + }, + src: 'Source/**/*.js', + dest: 'mootools-nocompat.js' + } + } + + }); + + grunt.registerTask('default', ['packager']); + +}; diff --git a/package.json b/package.json index a10b10aa..2ea865fb 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,6 @@ "homepage": "http://mootools.net", "devDependencies": { "grunt": "~0.4.2", - "js-yaml": "~3.0.1", - "debug": "~0.7.4" + "grunt-mootools-packager": "0.0.1" } } -- 2.11.4.GIT