summaryrefslogtreecommitdiffstats
path: root/bin/platform.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2014-07-11 17:42:16 -0700
committerSamy Pessé <samypesse@gmail.com>2014-07-11 17:42:16 -0700
commit3842e5bf4a42f75aed9ed413047a503920226589 (patch)
tree46a6624f18381a8abb682cfd0b9941a2bc6032cf /bin/platform.js
parent1b87cec893806928a9f26bfe5e04102645dad0e5 (diff)
parentf05b138fd6cbd46ff72ca45bb8f08994df9035b0 (diff)
downloadgitbook-3842e5bf4a42f75aed9ed413047a503920226589.zip
gitbook-3842e5bf4a42f75aed9ed413047a503920226589.tar.gz
gitbook-3842e5bf4a42f75aed9ed413047a503920226589.tar.bz2
Merge pull request #358 from GitbookIO/featureplatform
Add base command git:push and git:remote
Diffstat (limited to 'bin/platform.js')
-rw-r--r--bin/platform.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/bin/platform.js b/bin/platform.js
new file mode 100644
index 0000000..6bf0b94
--- /dev/null
+++ b/bin/platform.js
@@ -0,0 +1,53 @@
+var Q = require("q");
+var utils = require("./utils");
+
+var publish = function(folder) {
+ if (!folder) {
+ console.log("Need a repository folder");
+ return process.exit(-1);
+ }
+
+ utils.gitCmd("push", ["gitbook", "master"])
+ .then(function(out) {
+ console.log(out.stdout);
+ }, function(err) {
+ if (err.code == 128) {
+ console.log("No book on gitbook.io is configured with this git repository.");
+ console.log("Run 'gitbook git:remote username/book' to intialize this repository.");
+ } else {
+ console.log(err.message);
+ }
+ process.exit(-1);
+ });
+};
+
+var remote = function(folder, bookId) {
+ if (!folder || !bookId) {
+ console.log("Need a repository folder and a book id");
+ return process.exit(-1);
+ }
+
+ var url = "https://push.gitbook.io/"+bookId+".git";
+ var addRemote = function() {
+ return utils.gitCmd("remote", ["add", "gitbook", url]);
+ }
+
+ addRemote()
+ .fail(function(err) {
+ if (err.code == 128) {
+ return utils.gitCmd("remote", ["rm", "gitbook"]).then(addRemote);
+ }
+ return Q.reject(err);
+ })
+ .then(function(out) {
+ console.log("Book remote '"+url+"' added to the folder");
+ }, function(err) {
+ console.log(err.message);
+ process.exit(-1);
+ });
+};
+
+module.exports = {
+ publish: publish,
+ remote: remote
+};