Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Commit

Permalink
build: Rename inner callbacks for clarity.
Browse files Browse the repository at this point in the history
Add missing `nextTask` callback to `compress`.
  • Loading branch information
Kit Cambridge committed Mar 9, 2015
1 parent a7f5fe8 commit e8f809b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 54 deletions.
36 changes: 19 additions & 17 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var WrapperPlugin = require("./build/wrapper");

function main() {
async.auto({
pages: function pages(callback) {
pages: function pages(nextTask) {
writePages([{
"title": "JSON 3",
"src": path.join(__dirname, "README.md"),
Expand Down Expand Up @@ -51,14 +51,14 @@ function main() {
}
})
}
}], callback);
}], nextTask);
},

build: function build(callback) {
build: function build(nextTask) {
var compiler = webpack({
context: path.join(__dirname, "src"),
entry: {
json3: "./runInContext.js",
json3: "./runInContext.js"
},
output: {
path: path.join(__dirname, "lib"),
Expand Down Expand Up @@ -86,23 +86,25 @@ function main() {
compiler.run(function afterRun(err, stats) {
if (err) {
console.error("Error building JSON 3: %s", err);
callback(err);
nextTask(err);
}
console.log(stats.toString());
callback();
nextTask();
});
},

compress: ["build", function compress(callback) {
compress: ["build", function compress(nextTask) {
var srcPath = path.join(__dirname, "lib", "json3.js");
var destPath = path.join(__dirname, "lib", "json3.min.js");
writeMinified(srcPath, destPath, function afterMinify(err, fileSizes) {
if (err) {
console.error("Error compressing JSON 3: %s", err);
nextTask(err);
return;
}
console.log("Development size: %d KB; compressed size: %d KB",
fileSizes.src, fileSizes.dest);
nextTask();
});
}]
}, function afterBuild(err) {
Expand All @@ -115,18 +117,18 @@ function main() {
}

function writePages(pages, callback) {
async.each(pages, function eachPage(page, callback) {
async.each(pages, function eachPage(page, nextPage) {
genPage(page.title, page.dest, page.src, page.markedOptions, afterGen);
function afterGen(err) {
if (err) {
console.log("Error generating project page %j: %s", page.title, err);
callback(err);
nextPage(err);
return;
}
console.log("Project page %j generated successfully.", page.title);
callback();
nextPage();
}
});
}, callback);
}

// Compress JSON 3 using the Closure Compiler.
Expand Down Expand Up @@ -160,20 +162,20 @@ function writeMinified(srcPath, destPath, callback) {
].join("\n"));
async.each([
// Write the compressed version to disk.
function write(callback) {
fs.writeFile(destPath, minSrc, callback);
function write(nextFunc) {
fs.writeFile(destPath, minSrc, nextFunc);
},
// Calculate the `gzip`-ped size of the compressed version.
function gzipSize(callback) {
function gzipSize(nextFunc) {
zlib.gzip(minSrc, function afterGzip(err, results) {
if (!err) {
fileSizes.dest = getKilobytes(results.length);
}
callback();
nextFunc();
});
}
], function eachFunc(func, callback) {
func(callback);
], function eachFunc(func, nextFunc) {
func(nextFunc);
}, function afterFinish(err) {
if (err) {
callback(err);
Expand Down
36 changes: 18 additions & 18 deletions lib/json3.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
/* 1 */
/***/ function(module, exports, __webpack_require__) {

var attempt = __webpack_require__(6);
var attempt = __webpack_require__(7);

module.exports = makeHas;
function makeHas(stringify, parse, Date, Number, String) {
Expand Down Expand Up @@ -275,7 +275,7 @@
}
if (name == "json-parse") {
// Test `JSON.parse`.
var parse = parse, isSupported = typeof parse == "function";
var isSupported = typeof parse == "function";
if (isSupported) {
isSupported = !!attempt(function () {
// FF 3.1b1, b2 will throw an exception if a bare literal is provided.
Expand Down Expand Up @@ -329,7 +329,7 @@
/* 2 */
/***/ function(module, exports, __webpack_require__) {

var hasDontEnumBug = __webpack_require__(7);
var hasDontEnumBug = __webpack_require__(6);

// A list of non-enumerable properties inherited from `Object.prototype`.
var dontEnums = ["valueOf", "toString", "toLocaleString",
Expand Down Expand Up @@ -816,7 +816,7 @@
/* 5 */
/***/ function(module, exports, __webpack_require__) {

var attempt = __webpack_require__(6),
var attempt = __webpack_require__(7),
toPaddedString = __webpack_require__(8);

var undefined;
Expand Down Expand Up @@ -986,20 +986,6 @@

/***/ },
/* 6 */
/***/ function(module, exports, __webpack_require__) {

// Internal: Contains `try...catch` logic used by other functions.
// This prevents other functions from being deoptimized.
module.exports = attempt;
function attempt(func) {
try {
return func();
} catch (exception) {}
}


/***/ },
/* 7 */
/***/ function(module, exports, __webpack_require__) {

// The `valueOf` property inherits the non-enumerable flag from
Expand All @@ -1023,6 +1009,20 @@
}


/***/ },
/* 7 */
/***/ function(module, exports, __webpack_require__) {

// Internal: Contains `try...catch` logic used by other functions.
// This prevents other functions from being deoptimized.
module.exports = attempt;
function attempt(func) {
try {
return func();
} catch (exception) {}
}


/***/ },
/* 8 */
/***/ function(module, exports, __webpack_require__) {
Expand Down
Loading

0 comments on commit e8f809b

Please sign in to comment.