Skip to content

Commit

Permalink
Replaces Q by native promises
Browse files Browse the repository at this point in the history
  • Loading branch information
marchant committed Apr 1, 2024
1 parent cbf49f7 commit 02c3063
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions _build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

var FS = require("fs");
var PATH = require("path");
var Q = require("q");
var Writable = require("stream").Writable;
var shell = require('shelljs'); // nicer scripting interface
var generateJsdoc = require("./jsdoc/jsdoc");
Expand All @@ -17,24 +16,26 @@ var spawn = require("child_process").spawn;
* @return {Promise} A promise for the completion of the command.
*/
var exec = function (command, args, cwd, silent) {
var deferred = Q.defer();
cwd = cwd || process.cwd();
var promise = new Promise(function(resolve, reject) {

if (!silent) {
console.log("+", command, args.join(" "), "# in", cwd);
}
var proc = spawn(command, args, {
cwd: cwd,
stdio: silent ? "ignore" : "inherit"
});
proc.on('exit', function(code) {
if (code !== 0) {
deferred.reject(new Error(command + " " + args.join(" ") + " in " + cwd + " exited with code " + code));
} else {
deferred.resolve();
var cwd = cwd || process.cwd();

if (!silent) {
console.log("+", command, args.join(" "), "# in", cwd);
}
var proc = spawn(command, args, {
cwd: cwd,
stdio: silent ? "ignore" : "inherit"
});
proc.on('exit', function(code) {
if (code !== 0) {
reject(new Error(command + " " + args.join(" ") + " in " + cwd + " exited with code " + code));
} else {
resolve();
}
});
});
return deferred.promise;
return promise;
};

var SOURCE_PATH = PATH.join(__dirname, "..");
Expand All @@ -45,7 +46,7 @@ var APPS = {
var TEMP_DIR = PATH.join(SOURCE_PATH, "tmp");

function cloneAndMopApps(apps) {
return Q.all(Object.keys(apps).map(function (name) {
return Promise.all(Object.keys(apps).map(function (name) {
var repo = apps[name].url;
var commit = apps[name].commit || "master";

Expand Down Expand Up @@ -106,13 +107,13 @@ function mopHomeExample() {
})
.then(function () {
// Remove generated files from root
return Q.all(paths.map(function (path) {
return Promise.all(paths.map(function (path) {
return exec("rm", ["-r", PATH.join(outPath, path)]);
}));
})
.then(function () {
// Copy generated files back to root
return Q.all(paths.map(function (path) {
return Promise.all(paths.map(function (path) {
return exec("cp", ["-r", PATH.join(buildPath, path), PATH.join(outPath, path)]);
}));
})
Expand Down Expand Up @@ -167,7 +168,6 @@ if (require.main === module) {
})
.then(function () {
console.log("done");
})
.done();
});

}

0 comments on commit 02c3063

Please sign in to comment.