Skip to content

Commit

Permalink
Beside the modular version provide a packed one as single file in the…
Browse files Browse the repository at this point in the history
… build.
  • Loading branch information
evanvosberg committed Mar 21, 2015
1 parent 49f9898 commit 1e0d234
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 19 deletions.
2 changes: 2 additions & 0 deletions grunt/config/modularize.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ module.exports = {
options: {
// all
"index": {
"global": "CryptoJS",
"exports": "CryptoJS",
"components": ["core", "x64-core", "lib-typedarrays", "enc-utf16", "enc-base64", "md5", "sha1", "sha256", "sha224", "sha512", "sha384", "sha3", "ripemd160", "hmac", "pbkdf2", "evpkdf", "cipher-core", "mode-cfb", "mode-ctr", "mode-ctr-gladman", "mode-ofb", "mode-ecb", "pad-ansix923", "pad-iso10126", "pad-iso97971", "pad-zeropadding", "pad-nopadding", "format-hex", "aes", "tripledes", "rc4", "rabbit", "rabbit-legacy"]
},
"crypto-js": {
"pack": true,
"global": "CryptoJS",
"exports": "CryptoJS",
"components": ["core", "x64-core", "lib-typedarrays", "enc-utf16", "enc-base64", "md5", "sha1", "sha256", "sha224", "sha512", "sha384", "sha3", "ripemd160", "hmac", "pbkdf2", "evpkdf", "cipher-core", "mode-cfb", "mode-ctr", "mode-ctr-gladman", "mode-ofb", "mode-ecb", "pad-ansix923", "pad-iso10126", "pad-iso97971", "pad-zeropadding", "pad-nopadding", "format-hex", "aes", "tripledes", "rc4", "rabbit", "rabbit-legacy"]
},
Expand Down
66 changes: 47 additions & 19 deletions grunt/tasks/modularize.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ var _ = require("lodash"),
module.exports = function (grunt) {

grunt.registerMultiTask('modularize', function () {
var done = this.async(),
var options = this.options(),

done = this.async(),

modules = {},

Expand All @@ -20,38 +22,64 @@ module.exports = function (grunt) {
};

// Prepare Factory-Module-Definition settings
_.each(this.options(), function (conf, module) {
var sources = [],
_.each(options, function (conf, name) {
var sources = [],

options = {
opts = {
depends: {}
};
},

deps = [];

if (conf.exports) {
options.exports = conf.exports;
opts.exports = conf.exports;
}

if (module === "core" || module === "crypto-js") {
options.global = "CryptoJS";
if (conf.global) {
opts.global = conf.global;
}

// Find and add self as source
_.each(this.filesSrc, function (source) {
if (grunt.file.exists(source + module + ".js")) {
sources.push(source + module + ".js");
if (grunt.file.exists(source + name + ".js")) {
sources.push(source + name + ".js");
}
}, this);

// Read dependencies
_.each(_.difference(conf.components, [module]), function (value, i) {
options.depends['./' + value] = value === "core" ? "CryptoJS" : null;
});

// TODO create a single file including all dependencies
if (conf.pack) {
return;
}
// Collect all components
deps = _.chain(conf.components)
.map(function (depName) {
return options[depName].components;
})
.flatten()
.unique()
.without(name)
.sort(function (a, b) {
return options[a].components.indexOf(b) === -1 ? -1 : 1;
})
.value();

// Add components as source files -> results a single file
_.each(this.filesSrc, function (source) {
_.each(deps, function (depName) {
if (grunt.file.exists(source + depName + ".js")) {
sources.push(source + depName + ".js");
}
});
}, this);
} else {
// Read components and add them as dependecies
_.each(_.without(conf.components, name), function (value, i) {
opts.depends['./' + value] = value === "core" ? "CryptoJS" : null;
});
}

// Remove duplicates
sources = _.unique(sources);

modules[module] = [sources, options];
// Add module settings to fmd definition
modules[name] = [sources, opts];
}, this);

// Build packege modules
Expand Down

0 comments on commit 1e0d234

Please sign in to comment.