| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 26ca8b4 commit b936634
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,19 +1,34 @@ | |||
| 1 | 1 | var generateJson = require("./scripts/generateJson"); | |
| 2 | 2 | var generateNativeCode = require("./scripts/generateNativeCode"); | |
| 3 | 3 | var generateMissingTests = require("./scripts/generateMissingTests"); | |
| 4 | + var submoduleStatus = require("../lifecycleScripts/submodules/getStatus"); | ||
| 4 | 5 | ||
| 5 | 6 | module.exports = function generate() { | |
| 6 | - return new Promise(function(resolve, reject) { | ||
| 7 | - try { | ||
| 7 | + return submoduleStatus() | ||
| 8 | + .then(function(statuses) { | ||
| 9 | + var dirtySubmodules = statuses | ||
| 10 | + .filter(function(status) { | ||
| 11 | + return status.onNewCommit | ||
| 12 | + || status.needsInitialization | ||
| 13 | + || status.workDirDirty; | ||
| 14 | + }); | ||
| 15 | + | ||
| 16 | + if (dirtySubmodules.length) { | ||
| 17 | + console.log("WARNING - Some submodules are out-of-sync"); | ||
| 18 | + dirtySubmodules.forEach(function(submodule) { | ||
| 19 | + console.log("\t" + submodule.name); | ||
| 20 | + }); | ||
| 21 | + } | ||
| 22 | + }) | ||
| 23 | + .then(function() { | ||
| 8 | 24 | generateJson(); | |
| 9 | 25 | generateNativeCode(); | |
| 10 | 26 | generateMissingTests(); | |
| 11 | - resolve(); | ||
| 12 | - } | ||
| 13 | - catch(e) { | ||
| 14 | - reject(e); | ||
| 15 | - } | ||
| 16 | - }); | ||
| 27 | + }) | ||
| 28 | + .catch(function(e) { | ||
| 29 | + console.log("ERROR - Could not generate native code"); | ||
| 30 | + console.log(e); | ||
| 31 | + }); | ||
| 17 | 32 | } | |
| 18 | 33 | ||
| 19 | 34 | if (require.main === module) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -121,7 +121,6 @@ function build() { | |||
| 121 | 121 | return arg; | |
| 122 | 122 | }); | |
| 123 | 123 | ||
| 124 | - console.log(args); | ||
| 125 | 124 | return new Promise(function(resolve, reject) { | |
| 126 | 125 | var child = cp.spawn(cmd, args, opts); | |
| 127 | 126 | child.on("close", function(code) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,11 +3,11 @@ var path = require("path"); | |||
| 3 | 3 | ||
| 4 | 4 | var local = path.join.bind(path, __dirname); | |
| 5 | 5 | ||
| 6 | + var submodules = require(local("submodules")); | ||
| 6 | 7 | var configure = require(local("configureLibssh2")); | |
| 7 | 8 | var generate = require(local("../generate")); | |
| 8 | 9 | ||
| 9 | 10 | module.exports = function prepareForBuild() { | |
| 10 | - | ||
| 11 | 11 | return new Promise(function(resolve, reject) { | |
| 12 | 12 | cp.exec("npm install --ignore-scripts", function(err, stdout, stderr) { | |
| 13 | 13 | if (err) { | |
@@ -19,7 +19,11 @@ module.exports = function prepareForBuild() { | |||
| 19 | 19 | console.info(stdout); | |
| 20 | 20 | } | |
| 21 | 21 | }); | |
| 22 | - }).then(function() { | ||
| 22 | + }) | ||
| 23 | + .then(function() { | ||
| 24 | + return submodules(); | ||
| 25 | + }) | ||
| 26 | + .then(function() { | ||
| 23 | 27 | return Promise.all([ | |
| 24 | 28 | configure(), | |
| 25 | 29 | generate() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,37 @@ | |||
| 1 | + var path = require("path"); | ||
| 2 | + var rootDir = path.join(__dirname, "../.."); | ||
| 3 | + var exec = require(path.join(rootDir, "./utils/execPromise")); | ||
| 4 | + | ||
| 5 | + module.exports = function getStatus() { | ||
| 6 | + return exec("git submodule status", { cwd: rootDir}) | ||
| 7 | + .then(function(stdout) { | ||
| 8 | + function getStatusPromiseFromLine(line) { | ||
| 9 | + var lineSections = line.trim().split(" "); | ||
| 10 | + var onNewCommit = !!~lineSections[0].indexOf("+"); | ||
| 11 | + var needsInitialization = !!~lineSections[0].indexOf("-"); | ||
| 12 | + var commitOid = lineSections[0].replace("+", "").replace("-", ""); | ||
| 13 | + var name = lineSections[1]; | ||
| 14 | + | ||
| 15 | + return exec("git status", { cwd: path.join(rootDir, name)}) | ||
| 16 | + .then(function(workDirStatus) { | ||
| 17 | + return { | ||
| 18 | + commitOid: commitOid, | ||
| 19 | + onNewCommit: onNewCommit, | ||
| 20 | + name: name, | ||
| 21 | + needsInitialization: needsInitialization, | ||
| 22 | + workDirDirty: !~workDirStatus | ||
| 23 | + .trim() | ||
| 24 | + .split("\n") | ||
| 25 | + .pop() | ||
| 26 | + .indexOf("nothing to commit") | ||
| 27 | + }; | ||
| 28 | + }); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + return Promise.all(stdout | ||
| 32 | + .trim() | ||
| 33 | + .split("\n") | ||
| 34 | + .map(getStatusPromiseFromLine) | ||
| 35 | + ); | ||
| 36 | + }); | ||
| 37 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,74 @@ | |||
| 1 | + var path = require("path"); | ||
| 2 | + var rootDir = path.join(__dirname, "../.."); | ||
| 3 | + | ||
| 4 | + var gitExecutableLocation = require( | ||
| 5 | + path.join(rootDir, "./utils/gitExecutableLocation") | ||
| 6 | + ); | ||
| 7 | + var submoduleStatus = require("./getStatus"); | ||
| 8 | + | ||
| 9 | + var exec = require(path.join(rootDir, "./utils/execPromise")); | ||
| 10 | + | ||
| 11 | + module.exports = function submodules() { | ||
| 12 | + return gitExecutableLocation() | ||
| 13 | + .catch(function() { | ||
| 14 | + console.log("ERROR - Compilation of NodeGit requires git CLI to be " + | ||
| 15 | + "installed and on the path"); | ||
| 16 | + | ||
| 17 | + throw new Error("git CLI is not installed or not on the path"); | ||
| 18 | + }) | ||
| 19 | + .then(function() { | ||
| 20 | + return submoduleStatus(); | ||
| 21 | + }) | ||
| 22 | + .then(function(statuses) { | ||
| 23 | + function printSubmodule(submoduleName) { | ||
| 24 | + console.log("\t" + submoduleName); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + var dirtySubmodules = statuses | ||
| 28 | + .filter(function(status) { | ||
| 29 | + return status.workDirDirty && !status.needsInitialization; | ||
| 30 | + }) | ||
| 31 | + .map(function(dirtySubmodule) { | ||
| 32 | + return dirtySubmodule.name; | ||
| 33 | + }); | ||
| 34 | + | ||
| 35 | + if (dirtySubmodules.length) { | ||
| 36 | + console.log( | ||
| 37 | + "ERROR - The following submodules have uncommited changes:" | ||
| 38 | + ); | ||
| 39 | + dirtySubmodules.forEach(printSubmodule); | ||
| 40 | + console.log( | ||
| 41 | + "\nThey must either be committed or discarded before we build" | ||
| 42 | + ); | ||
| 43 | + | ||
| 44 | + throw new Error("Dirty Submodules: " + dirtySubmodules.join(" ")); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + var outOfSyncSubmodules = statuses | ||
| 48 | + .filter(function(status) { | ||
| 49 | + return status.onNewCommit && !status.needsInitialization; | ||
| 50 | + }) | ||
| 51 | + .map(function(outOfSyncSubmodule) { | ||
| 52 | + return outOfSyncSubmodule.name; | ||
| 53 | + }); | ||
| 54 | + | ||
| 55 | + if (outOfSyncSubmodules.length) { | ||
| 56 | + console.log( | ||
| 57 | + "WARNING - The following submodules are pointing to an new commit:" | ||
| 58 | + ); | ||
| 59 | + outOfSyncSubmodules.forEach(printSubmodule); | ||
| 60 | + console.log("\nThey will not be updated."); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + return Promise.all(statuses | ||
| 64 | + .filter(function(status) { | ||
| 65 | + return !status.onNewCommit; | ||
| 66 | + }) | ||
| 67 | + .map(function(submoduleToUpdate) { | ||
| 68 | + return exec( | ||
| 69 | + "git submodule update --init --recursive " + submoduleToUpdate.name | ||
| 70 | + ); | ||
| 71 | + }) | ||
| 72 | + ); | ||
| 73 | + }); | ||
| 74 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,23 @@ | |||
| 1 | + var cp = require("child_process"); | ||
| 2 | + | ||
| 3 | + module.exports = function gitExecutableLocation() { | ||
| 4 | + return new Promise(function(resolve, reject) { | ||
| 5 | + var cmd; | ||
| 6 | + | ||
| 7 | + if (process.platform === "win32") { | ||
| 8 | + cmd = "where git"; | ||
| 9 | + } | ||
| 10 | + else { | ||
| 11 | + cmd = "which git"; | ||
| 12 | + } | ||
| 13 | + | ||
| 14 | + cp.exec(cmd, function(err, stdout, stderr) { | ||
| 15 | + if (err) { | ||
| 16 | + reject(err, stderr); | ||
| 17 | + } | ||
| 18 | + else { | ||
| 19 | + resolve(stdout); | ||
| 20 | + } | ||
| 21 | + }); | ||
| 22 | + }); | ||
| 23 | + }; | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments