Browse files

Fix build script, add compression

  • Loading branch information...
1 parent 322e3df commit 8ee0aadd32474be35627bc4aff3b9e38f5401f39 Christian Johansen committed Feb 15, 2012
Showing with 80 additions and 58 deletions.
  1. +75 −57 build
  2. +1 −1 doc/samples/strftime.html
  3. +4 −0 package.json
View
132 build
@@ -4,71 +4,89 @@ var path = require("path");
var util = require("util");
var exec = require("child_process").exec;
var fs = require("fs");
+var jsp = require("uglify-js").parser;
+var pro = require("uglify-js").uglify;
-var cwd = process.cwd();
-process.chdir(path.dirname(path.dirname(require.resolve("sinon"))));
+var files = [];
+var read = 0;
-exec("ruby -rubygems build", function (error, stdout, stderr) {
- if (error !== null) {
- console.log("Failed building Sinon.JS " + error);
- } else {
- buildBuster(stdout.match(/(\d\.\d\.\d)/)[1]);
- }
-});
+function minify(script) {
+ var ast = jsp.parse(script);
+ ast = pro.ast_mangle(ast);
+ ast = pro.ast_squeeze(ast);
+ return pro.gen_code(ast);
+}
-function buildBuster(sinonVersion) {
- process.cwd(cwd);
- var files = [];
- var read = 0;
+function wrap(script) {
+ return "(function () { var when; function define(cb) { when = cb(); } " +
+ script + ";return buster; }());";
+}
- function finish() {
- if (read == fileNames.length) {
- var fileName = path.resolve(cwd, "resources/buster-test.js");
+function finish() {
+ if (read == fileNames.length) {
+ var fileName = path.resolve(process.cwd(), "resources/buster-test.js");
- fs.writeFile(fileName, files.join("\n"), function (err) {
- if (err) {
- console.log("Failed building resources/buster-test.js: " + err.message);
- } else {
- var kb = Math.floor(files.join("\n").length / 10.24) / 100;
- console.log("Built resources/buster-test.js (" + kb + "kB)");
- }
- });
+ var contents = wrap(files.join("\n"));
+ if (process.argv[2] == "--minify" || process.argv[2] == "-m") {
+ contents = minify(contents);
}
+ fs.writeFile(fileName, contents, function (err) {
+ if (err) {
+ console.log("Failed building resources/buster-test.js: " + err.message);
+ } else {
+ var kb = Math.floor(contents.length / 10.24) / 100;
+ console.log("Built resources/buster-test.js (" + kb + "kB)");
+ }
+ });
}
+}
- var fileNames = [
- "buster-core/lib/buster-core",
- "buster-core/lib/buster-event-emitter",
- "buster-format/lib/buster-format",
- "buster-assertions/lib/buster-assertions",
- "buster-assertions/lib/buster-assertions/expect",
- "buster-evented-logger/lib/buster-evented-logger",
- "buster-test/lib/buster-test/stack-filter",
- "buster-test/lib/buster-test/spec",
- "buster-test/lib/buster-test/test-case",
- "buster-test/lib/buster-test/test-runner",
- "buster-test/lib/buster-test/reporters",
- "buster-test/lib/buster-test/reporters/html",
- "buster-test/lib/buster-test/auto-run",
- "buster-test/lib/buster-test/test-context",
- "buster-test/lib/buster-test",
- "sinon/pkg/sinon-" + sinonVersion,
- "sinon-buster/lib/sinon-buster",
- "lib/buster/buster-wiring.js",
- "lib/buster.js"];
+var fileNames = [
+ "when/when",
+ "buster-core/lib/buster-core",
+ "buster-core/lib/buster-event-emitter",
+ "buster-format/lib/buster-format",
+ "buster-assertions/lib/buster-assertions",
+ "buster-assertions/lib/buster-assertions/expect",
+ "buster-evented-logger/lib/buster-evented-logger",
+ "buster-test/lib/buster-test/stack-filter",
+ "buster-test/lib/buster-test/spec",
+ "buster-test/lib/buster-test/test-case",
+ "buster-test/lib/buster-test/test-runner",
+ "buster-test/lib/buster-test/reporters",
+ "buster-test/lib/buster-test/reporters/html",
+ "buster-test/lib/buster-test/auto-run",
+ "buster-test/lib/buster-test/test-context",
+ "buster-test/lib/buster-test",
+ "sinon/lib/sinon.js",
+ "sinon/lib/sinon/spy.js",
+ "sinon/lib/sinon/stub.js",
+ "sinon/lib/sinon/mock.js",
+ "sinon/lib/sinon/collection.js",
+ "sinon/lib/sinon/sandbox.js",
+ "sinon/lib/sinon/test.js",
+ "sinon/lib/sinon/test_case.js",
+ "sinon/lib/sinon/assert.js",
+ "sinon/lib/sinon/util/event.js",
+ "sinon/lib/sinon/util/fake_xml_http_request.js",
+ "sinon/lib/sinon/util/fake_timers.js",
+ "sinon/lib/sinon/util/fake_server.js",
+ "sinon/lib/sinon/util/fake_server_with_clock.js",
+ "sinon-buster/lib/sinon-buster",
+ "lib/buster/buster-wiring.js",
+ "lib/buster.js"];
- fileNames.forEach(function (fileName, i) {
- try {
- fileName = require.resolve(fileName);
- } catch (e) {
- fileName = path.resolve(cwd, fileName);
- }
+fileNames.forEach(function (fileName, i) {
+ try {
+ fileName = require.resolve(fileName);
+ } catch (e) {
+ fileName = path.resolve(process.cwd(), fileName);
+ }
- fs.readFile(fileName, "utf-8", function (err, data) {
- if (err) throw err;
- files[i] = data;
- read += 1;
- finish();
- });
+ fs.readFile(fileName, "utf-8", function (err, data) {
+ if (err) throw err;
+ files[i] = data;
+ read += 1;
+ finish();
});
-}
+});
View
2 doc/samples/strftime.html
@@ -5,7 +5,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
- <script type="text/javascript" src="buster-test.js"></script>
+ <script type="text/javascript" src="../../resources/buster-test.js"></script>
<script type="text/javascript" src="strftime.js"></script>
<script type="text/javascript" src="strftime-test.js"></script>
</body>
View
4 package.json
@@ -34,5 +34,9 @@
"sinon": ">=1.3.1",
"sinon-buster": ">=0.4.1",
"buster-static": ">=0.3"
+ },
+ "devDependencies": {
+ "when": "https://github.com/cujojs/when/tarball/v0.11.1",
+ "uglify-js": "~1.2.5"
}
}

0 comments on commit 8ee0aad

Please sign in to comment.