From b92eb8c473dcc9a009db48cf40befdb8054a45bc Mon Sep 17 00:00:00 2001 From: Evan Vosberg Date: Tue, 23 Apr 2013 18:05:04 +0200 Subject: [PATCH] Add javascript builder to convert sources into smart modules. --- builder/build.yml | 85 ++++++++++++++++++- builder/builder.js | 202 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 35 ++++++++ 3 files changed, 321 insertions(+), 1 deletion(-) create mode 100644 builder/builder.js create mode 100644 package.json diff --git a/builder/build.yml b/builder/build.yml index 566615c..af37ad0 100644 --- a/builder/build.yml +++ b/builder/build.yml @@ -58,4 +58,87 @@ rollups: tripledes: [core, enc-base64, md5, evpkdf, cipher-core, tripledes] rc4: [core, enc-base64, md5, evpkdf, cipher-core, rc4] rabbit: [core, enc-base64, md5, evpkdf, cipher-core, rabbit] - rabbit-legacy: [core, enc-base64, md5, evpkdf, cipher-core, rabbit-legacy] \ No newline at end of file + rabbit-legacy: [core, enc-base64, md5, evpkdf, cipher-core, rabbit-legacy] + + core: [core] + + evpkdf: [core, sha1, hmac, evpkdf] + + lib-typedarrays: [core, lib-typedarrays] + + format-openssl: [core, cipher-core] + format-hex: [core, cipher-core, format-hex] + + enc-latin1: [core] + enc-utf8: [core] + enc-hex: [core] + enc-utf16: [core, enc-utf16] + enc-base64: [core, enc-base64] + + mode-cfb: [core, cipher-core, mode-cfb] + mode-ctr: [core, cipher-core, mode-ctr] + mode-ctr-gladman: [core, cipher-core, mode-ctr-gladman] + mode-ofb: [core, cipher-core, mode-ofb] + mode-ecb: [core, cipher-core, mode-ecb] + + pad-pkcs7: [core, cipher-core, pad-pkcs7] + pad-ansix923: [core, cipher-core, pad-ansix923] + pad-iso10126: [core, cipher-core, pad-iso10126] + pad-iso97971: [core, cipher-core, pad-iso97971] + pad-zeropadding: [core, cipher-core, pad-zeropadding] + pad-nopadding: [core, cipher-core, pad-nopadding] + +exports: + md5: CryptoJS.MD5 + sha1: CryptoJS.SHA1 + sha256: CryptoJS.SHA256 + sha224: CryptoJS.SHA224 + sha512: CryptoJS.SHA512 + sha384: CryptoJS.SHA384 + sha3: CryptoJS.SHA3 + ripemd160: CryptoJS.RIPEMD160 + + hmac-md5: CryptoJS.HmacMD5 + hmac-sha1: CryptoJS.HmacSHA1 + hmac-sha256: CryptoJS.HmacSHA256 + hmac-sha224: CryptoJS.HmacSHA224 + hmac-sha512: CryptoJS.HmacSHA512 + hmac-sha384: CryptoJS.HmacSHA384 + hmac-sha3: CryptoJS.HmacSHA3 + hmac-ripemd160: CryptoJS.HmacRIPEMD160 + + pbkdf2: CryptoJS.PBKDF2 + + aes: CryptoJS.AES + tripledes: CryptoJS.TripleDES + rc4: CryptoJS.RC4 + rabbit: CryptoJS.Rabbit + rabbit-legacy: CryptoJS.RabbitLegacy + + core: CryptoJS + + evpkdf: CryptoJS.EvpKDF + + lib-typedarrays: CryptoJS.lib.WordArray + + format-openssl: CryptoJS.format.OpenSSL + format-hex: CryptoJS.format.Hex + + enc-latin1: CryptoJS.enc.Latin1 + enc-utf8: CryptoJS.enc.Utf1 + enc-hex: CryptoJS.enc.Hex + enc-utf16: CryptoJS.enc.Utf16 + enc-base64: CryptoJS.enc.Base64 + + mode-cfb: CryptoJS.mode.CFB + mode-ctr: CryptoJS.mode.CTR + mode-ctr-gladman: CryptoJS.mode.CTRGladman + mode-ofb: CryptoJS.mode.OFB + mode-ecb: CryptoJS.mode.ECB + + pad-pkcs7: CryptoJS.pad.Pkcs7 + pad-ansix923: CryptoJS.pad.Ansix923 + pad-iso10126: CryptoJS.pad.Iso10126 + pad-iso97971: CryptoJS.pad.Iso97971 + pad-zeropadding: CryptoJS.pad.ZeroPadding + pad-nopadding: CryptoJS.pad.NoPadding \ No newline at end of file diff --git a/builder/builder.js b/builder/builder.js new file mode 100644 index 0000000..eed9b67 --- /dev/null +++ b/builder/builder.js @@ -0,0 +1,202 @@ +(function (undef) { + + var _ = require("underscore"), + + fs = require("fs"), + + fsx = require("fs.extra"), + + fmd = require("fmd"), + + targz = require("tar.gz"), + + uglify = require("uglify-js"), + + readFile = function (path) { + return fs.readFileSync(path) + .toString(); + }, + + writeFile = function (path, content) { + fsx.mkdirpSync(path.replace(/[^\/]+\/?$/, "")); + fs.writeFileSync(path, content); + }, + + paths = { + src: __dirname + "/../src", + dist: __dirname + "/../build" + }, + + packages = { + npm: { + archive: paths.dist + "/crypto-js-npm.tar.gz", + + dest: paths.dist + "/crypto-js", + dest_lib: paths.dist + "/crypto-js", + dest_lib_min: paths.dist + "/crypto-js", + + copy: { + "../package.json": "package.json", + "../README.md": "README.md" + }, + + toPath: function (module, req) { + if (module === "crypto-js") { + return; + } + else if (req) { + return "./"; + } + else { + return module; + } + } + }, + release: { + archive: paths.dist + "/crypto-js.tar.gz", + + dest: paths.dist + "/crypto-js", + dest_lib: paths.dist + "/crypto-js/lib-uncompressed", + dest_lib_min: paths.dist + "/crypto-js/lib", + + copy: {}, + + toPath: function (module, req) { + if (module === "index") { + return; + } + else if (req) { + return module === "crypto-js" ? "./crypto-js/" : "./"; + } + else { + return module === "crypto-js" ? module : "crypto-js/" + module; + } + } + } + }, + + config = { + require: {}, + exports: {} + }, + + // Read YAML build config + yConfig = require("js-yaml") + .load(fs.readFileSync(__dirname + "/build.yml") + .toString()); + + // Compose config from YAML + _.each(yConfig.components, function (module) { + config.require[module] = ["core"]; + }); + _.extend(config.require, yConfig.rollups); + _.extend(config.exports, yConfig.exports); + + // Add full rollup to config (depending on all modules) + config.require["crypto-js"] = [].concat(yConfig.components); + config.exports["crypto-js"] = "CryptoJS"; + + config.require["index"] = [].concat(yConfig.components); + config.exports["index"] = "CryptoJS"; + + // Compose modules + _.each(packages, function (pkg) { + + pkg._modules = {}; + + _.each(config.require, function (deps, module) { + var modulePath = pkg.toPath(module), + + requirePath = pkg.toPath(module, true), + + sources = [], + + options = { + depends: {} + }; + + if (modulePath === undef) { + return; + } + + if (config.exports[module]) { + options.exports = config.exports[module]; + } + + if (module === "core" || module === "crypto-js") { + options.global = "CryptoJS"; + } + + if (fs.existsSync(paths.src + "/" + module + ".js")) { + sources = [paths.src + "/" + module + ".js"]; + } + + // Read dependencies + _.each(_.difference(deps, [module]), function (value, i) { + options.depends[requirePath + value] = value === "core" ? "CryptoJS" : null; + }); + + pkg._modules[modulePath] = [sources, options]; + }); + }); + + // Build a package + function buildPackage(pkg) { + // Clear package destination directory + fsx.rmrfSync(pkg.dest); + + // Build packege modules + fmd({ + target: pkg.dest_lib, + factories: ["commonjs", "amd", "global"], + trim_whitespace: true, + new_line: "unix", + indent: "\t" + }) + .define(pkg._modules) + .build(function (createdFiles) { + + // Minify modules + _.each(createdFiles, function (file) { + var minContent = (uglify) + .minify(pkg.dest_lib + "/" + file) + .code; + + writeFile(pkg.dest_lib_min + "/" + file, minContent); + }); + + // Copy files + _.each(pkg.copy, function (to, from) { + fsx.copy(paths.src + "/" + from, pkg.dest + "/" + to, function () {}); + }); + + // Pack into archive + new targz() + .compress(pkg.dest, pkg.archive, function () { + // Clear package destination directory + fsx.rmrfSync(pkg.dest); + + // Mark package as built + pkg._built = true; + + // Build next package + buildNextPackage(); + }); + }); + } + + // Build next package iterator + function buildNextPackage() { + var type; + + for (type in packages) { + if (!packages[type]._built) { + return buildPackage(packages[type]); + } + } + } + + // Start package building + buildNextPackage(); + +}()); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..b468179 --- /dev/null +++ b/package.json @@ -0,0 +1,35 @@ +{ + "name": "crypto-js", + "title": "crypto-js", + "description": "Modularized port of googlecode project crypto-js.", + "version": "3.2.1", + "homepage": "http://github.com/evanvosberg/crypto-js", + "author": { + "name": "Evan Vosberg", + "url": "http://github.com/evanvosberg" + }, + "repository": { + "type": "git", + "url": "http://github.com/evanvosberg/crypto-js.git" + }, + "bugs": { + "url": "http://github.com/evanvosberg/crypto-js/issues" + }, + "licenses": [{ + "type": "New BSD", + "url": "http://opensource.org/licenses/BSD-3-Clause" + }], + "dependencies": { + + }, + "devDependencies": { + "underscore": "~1.4.4", + "handlebars": "~1.0.10", + "uglify-js": "~2.2.5", + "js-yaml": "~2.0.4", + "fs.extra": "~1.2.0", + "tar.gz": "~0.1.1", + "fmd": "~0.0.1" + }, + "keywords": ["Hash", "MD5", "SHA1", "SHA-1", "SHA256", "SHA-256", "RC4", "Rabbit", "AES", "DES", "PBKDF2", "HMAC", "OFB", "CFB", "CTR", "CBC", "Base64"] +} \ No newline at end of file