diff --git a/src/brackets.js b/src/brackets.js index bb14c4d8d34..5671892293e 100644 --- a/src/brackets.js +++ b/src/brackets.js @@ -101,6 +101,7 @@ define(function (require, exports, module) { require("help/HelpCommandHandlers"); require("search/FindInFiles"); require("search/FindReplace"); + require("fsDrives/fs"); require("extensions/default/dropbox/dropbox"); PerfUtils.addMeasurement("brackets module dependencies resolved"); diff --git a/src/node-webkit_shell.js b/src/brackets_shell.js similarity index 59% rename from src/node-webkit_shell.js rename to src/brackets_shell.js index fb265296138..35feadf1c66 100644 --- a/src/node-webkit_shell.js +++ b/src/brackets_shell.js @@ -10,53 +10,6 @@ var ports = {}; var nodeFs = require('fs'); var os = require('os'); var upDate = new Date(); -function getDropbox(callback) { - if (!window.dropbox) { - var Dialogs = require("widgets/Dialogs"); - var dropboxOAuthDriver = $.extend({}, new Dropbox.Drivers.Redirect ({rememberUser: true}), { - //url: function() { return ""; }, - url: function() { return "";}, - doAuthorize: function(authUrl, token, tokenSecret, callback) { - var $dlg = $("." + Dialogs.DIALOG_ID_INFO + ".template") - .clone() - .removeClass("template") - .addClass("instance") - .appendTo(window.document.body); - $(".dialog-title", $dlg).html("Welcome to use Dropbox as your project storage"); - $(".dialog-message", $dlg).html("A new window will be opened for Dropbox now. Please login and click 'Allow' to allow us to use your dropbox as a project storage. Don't forget to close the window after allowing"); - $dlg.one("click", ".dialog-button", function (e) { - $dlg.modal(true).hide(); - var w = window.showModalDialog(authUrl, null, "dialogWidth:950; dialogHeight:550;dialogLeft:300"); - callback(token); - }); - $dlg.modal({ - backdrop: "static", - show: true, - keyboard: true - }); - } - }); - - window.dropbox = new Dropbox.Client({ - key: "xbfa6vr2n1nk082", secret: "dze5e13g0j4vf07", sandbox: true - }); - - //dropbox.authDriver(new Dropbox.Drivers.Redirect({ rememberUser: true})); - dropbox.authDriver(dropboxOAuthDriver); - dropbox.authenticate(callback); - } - else - callback(null, dropbox); -} -function dropboxHandler(path, callback) { - if (path.indexOf("dropbox://") === 0) { - getDropbox(function (err, dropbox) { - callback(path.replace("dropbox://", ""), dropbox); - }); - return true; - } - return false; -} function _nodeErrorToBracketsError (err) { if (!err) { err = brackets.fs.NO_ERROR; @@ -75,159 +28,6 @@ function _dropboxErrorToBracketsError (err) { } return err; } -$.extend(true, brackets.fs, nodeFs , { - stat: function (path, callback) { - if (!dropboxHandler(path, function (path, dropbox) { - dropbox.stat(path, function(err, stats) { - if (!err) { - err = brackets.fs.NO_ERROR; - stats.isDirectory = function () { - return this.isFolder; - }.bind(stats) - stats.isFile = function () { - return this.isFile; - }.bind($.extend({}, stats)) - stats.mtime = stats.modifiedAt; - } - if (err && err.status === 404) { - err = brackets.fs.ERR_NOT_FOUND; - } - this(err, stats); - }.bind(callback)); - })) { - if (nodeFs) { - nodeFs.stat(path, function (err, stats) { - err = _nodeErrorToBracketsError(err); - if (!err) - stats.mtime = new Date(); - this(err, stats); - }.bind(callback)); - } - else { - $.ajax({ - url: path, - type: "HEAD", - dataType: "html", - error: function( jqXHR, textStatus, errorThrown) { - if (jqXHR.status === 403) { - this.callback(brackets.fs.NO_ERROR, { - isDirectory: function () { - return true; - }, - isFile: function () { - return false; - }, - mtime: new Date() - }); - } - else { - console.warn("stat " + path + " " + textStatus + ": " + errorThrown); - this.callback(brackets.fs.ERR_NOT_FOUND); - } - }.bind({path: path, callback:callback}), - success: function(data, textStatus, jqXHR){ - this(brackets.fs.NO_ERROR, { - isDirectory: function () { - return this.getResponseHeader("IsDirectory"); - }.bind(jqXHR), - isFile: function () { - return !this.getResponseHeader("IsDirectory"); - }.bind(jqXHR), - mtime: new Date(jqXHR.getResponseHeader("Last-Modified")) - }); - }.bind(callback) - }); - } - } - }, - readdir: function (path, callback ) { - if (!dropboxHandler(path, function (path, dropbox) { - dropbox.readdir(path.replace("dropbox://", ""), function(error, fileNames, folder, files) { - this(error, fileNames); - }.bind(callback)); - })) { - if (nodeFs) - nodeFs.readdir(path, callback); - else { - $.ajax({ - url: path + "/manifest.json", - dataType: 'json', - data: '{}', - headers: { - Accept : "text/json; charset=utf-8" - }, - error: function (jqXHR, textStatus, errorThrown) { - console.error("getting " + path + " failed:" + errorThrown); - }, - success: function (data, textStatus, jqXHR) { - var err = brackets.fs.NO_ERROR; - var files; - if (jqXHR.status === 404) - err = brackets.fs.ERR_NOT_FOUND; - if (data) { - files = []; - $(data).find('tr > td > a').each(function (i, link) { - if ($(link).text() !== "Parent Directory") - files.push($(link).attr('href')); - }) - } - this(err, data); - }.bind(callback) - }); - } - } - }, - makedir: function (path, permissions, callback ) { - if (!dropboxHandler(path, function (path, dropbox) { - dropbox.mkdir(path, function (err, stat) { - callback && callback(_dropboxErrorToBracketsError(err)); - }); - })) { - if(nodeFs) - nodeFs.mkdir(path, callback); - else { - callback(brackets.fs.ERR_CANT_WRITE); - } - } - }, - readFile: function (path, encoding, callback ) { - if (!dropboxHandler(path, function (path, dropbox) { - dropbox.readFile(path, {binary:true}, function (err, data) { - err = _dropboxErrorToBracketsError(err); - this(err, data); - }.bind(this)); - }.bind(callback))) { - if (nodeFs) - nodeFs.readFile(path, encoding, function (err, data) { - err = _nodeErrorToBracketsError(err); - this(err, data); - }.bind(callback)); - else { - $.get(path, function (data, textStatus, jqXHR) { - var err = brackets.fs.NO_ERROR; - if (jqXHR.status === 404) - err = brackets.fs.ERR_NOT_FOUND; - this(err, data); - }.bind(callback), "html") - } - } - }, - writeFile: function (path, data, encoding, callback ) { - if (!dropboxHandler(path, function (path, dropbox) { - dropbox.writeFile(path, data, {binary:true}, function (err) { - callback(_dropboxErrorToBracketsError(err)) - }); - })){ - if (nodeFs) - nodeFs.writeFile(path, data, encoding, function (err) { - callback(_nodeErrorToBracketsError(err)); - }); - else { - callback(brackets.fs.NO_ERROR); - } - } - } -}); var execDeviceCommand = function (cmd, callback) { console.log("cmd:" + cmd); child_process.exec("sdb -s " + window.device + " " + cmd, callback); @@ -245,7 +45,7 @@ function ShowOpenDialog ( callback, allowMultipleSelection, chooseDirectories, files.push(this.files[i].path.replace(/\\/g, "/")); callback(0, files); }); -} +} function ReadDir(){ throw arguments.callee.name } @@ -333,14 +133,6 @@ function OpenLiveBrowser(callback, url, enableRemoteDebugging){ var Inspector = require("LiveDevelopment/Inspector/Inspector"); var iframe = $('') .attr("src", "http://" + location.hostname + ":" + 6080 + "/vnc.html") - .load(function () { - iframe.contents().find("#noVNC_canvas").click( function() { - iframe[0].contentWindow.focus(); - }); - $(window).click( function () { - window.focus(); - }); - }) var div = $('
').append(iframe).css("overflow", "hidden") .dialog({width:"550", height:"770", minWidth: "550", minHeight: "770", position:"right", @@ -349,20 +141,6 @@ function OpenLiveBrowser(callback, url, enableRemoteDebugging){ Inspector.disconnect(); } }) - .dialogExtend({ - "close" : true, - "maximize" : true, - "minimize" : true, - "dblclick": "collapse" - }); - iframe.load( function () { - iframe.contents().find("#noVNC_canvas").click( function () { - iframe[0].contentWindow.focus(); - }) - $(window).click(function () { - window.focus(); - }) - }) $(Inspector).off('connect.RemoteEmulator'); $(Inspector).on('connect.RemoteEmulator', function () { this.dialog("open"); diff --git a/src/extensions/default/github/.github.js.swp b/src/extensions/default/github/.github.js.swp new file mode 100644 index 00000000000..65db8b91f57 Binary files /dev/null and b/src/extensions/default/github/.github.js.swp differ diff --git a/src/extensions/default/github/.gitignore b/src/extensions/default/github/.gitignore new file mode 100644 index 00000000000..5239f5589d3 --- /dev/null +++ b/src/extensions/default/github/.gitignore @@ -0,0 +1,4 @@ +_site/* +.DS_Store + +test/.DS_Store \ No newline at end of file diff --git a/src/extensions/default/github/.main.js.swn b/src/extensions/default/github/.main.js.swn new file mode 100644 index 00000000000..17cf32a9ea8 Binary files /dev/null and b/src/extensions/default/github/.main.js.swn differ diff --git a/src/extensions/default/github/.main.js.swo b/src/extensions/default/github/.main.js.swo new file mode 100644 index 00000000000..3699f7c8976 Binary files /dev/null and b/src/extensions/default/github/.main.js.swo differ diff --git a/src/extensions/default/github/.main.js.swp b/src/extensions/default/github/.main.js.swp new file mode 100644 index 00000000000..c0110144da9 Binary files /dev/null and b/src/extensions/default/github/.main.js.swp differ diff --git a/src/extensions/default/github/LICENSE b/src/extensions/default/github/LICENSE new file mode 100644 index 00000000000..6f66ed8197e --- /dev/null +++ b/src/extensions/default/github/LICENSE @@ -0,0 +1,25 @@ +Copyright (c) 2012 Michael Aufreiter, Development Seed +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +- Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. +- Neither the name "Development Seed" nor the names of its contributors may be + used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/src/extensions/default/github/README.md b/src/extensions/default/github/README.md new file mode 100644 index 00000000000..f2c8d8d0703 --- /dev/null +++ b/src/extensions/default/github/README.md @@ -0,0 +1,275 @@ +# Github.js + +Github.js provides a minimal higher-level wrapper around git's [plumbing commands](http://git-scm.com/book/en/Git-Internals-Plumbing-and-Porcelain), exposing an API for manipulating GitHub repositories on the file level. It is being developed in the context of [Prose](http://prose.io), a content editor for GitHub. + +This repo is now officially maintained by [DevelopmentSeed](https://github.com/developmentseed), the people behind [Prose.io](http://prose.io). + + +## Usage + +Create a Github instance. + +```js +var github = new Github({ + username: "YOU_USER", + password: "YOUR_PASSWORD", + auth: "basic" +}); +``` + +Or if you prefer OAuth, it looks like this: + +```js +var github = new Github({ + token: "OAUTH_TOKEN" + auth: "oauth" +}); +``` + +## Repository API + + +```js +var repo = github.getRepo(username, reponame); +``` + +Show repository information + +```js +repo.show(function(err, repo) {}); +``` + +Get contents at a particular path. + +```js +repo.contents("path/to/dir", function(err, contents) {}); +``` + +Fork repository. This operation runs asynchronously. You may want to poll for `repo.contents` until the forked repo is ready. + +```js +repo.fork(function(err) {}); +``` + +Create Pull Request. + +```js +var pull = { + title: message, + body: "This pull request has been automatically generated by Prose.io.", + base: "gh-pages", + head: "michael" + ":" + "prose-patch", +}; +repo.createPullRequest(pull, function(err, pullRequest) {}); +``` + + +Retrieve all available branches (aka heads) of a repository. + +```js +repo.listBranches(function(err, branches) {}); +``` + +Store contents at a certain path, where files that don't yet exist are created on the fly. + +```js +repo.write('master', 'path/to/file', 'YOUR_NEW_CONTENTS', 'YOUR_COMMIT_MESSAGE', function(err) {}); +``` + +Not only can you can write files, you can of course read them. + +```js +repo.read('master', 'path/to/file', function(err, data) {}); +``` + +Move a file from A to B. + +```js +repo.move('master', 'path/to/file', 'path/to/new_file', function(err) {}); +``` + +Remove a file. + +```js +repo.remove('master', 'path/to/file', function(err) {}); +``` + +Exploring files of a repository is easy too by accessing the top level tree object. + +```js +repo.getTree('master', function(err, tree) {}); +``` + +If you want to access all blobs and trees recursively, you can add `?recursive=true`. + +```js +repo.getTree('master?recursive=true', function(err, tree) {}); +``` + +Given a filepath, retrieve the reference blob or tree sha. + +```js +repo.getSha('master', '/path/to/file', function(err, sha) {}); +``` + +For a given reference, get the corresponding commit sha. + +```js +repo.getRef('heads/master', function(err, sha) {}); +``` + +Create a new reference. + +```js +var refSpec = { + "ref": "refs/heads/my-new-branch-name", + "sha": "827efc6d56897b048c772eb4087f854f46256132" +}; +repo.createRef(refSpec, function(err) {}); +``` + +Delete a reference. + +```js +repo.deleteRef('heads/gh-pages', function(err) {}); +``` + + +## User API + + +```js +var user = github.getUser(); +``` + +List all repositories of the authenticated user, including private repositories and repositories in which the user is a collaborator and not an owner. + +```js +user.repos(function(err, repos) {}); +``` + +List organizations the autenticated user belongs to. + +```js +user.orgs(function(err, orgs) {}); +``` + +List authenticated user's gists. + +```js +user.gists(username, function(err, gists) {}); +``` + +Show user information for a particular username. Also works for organizations. + +```js +user.show(username, function(err, user) {}); +``` + +List public repositories for a particular user. + +```js +user.userRepos(username, function(err, repos) {}); +``` + +List repositories for a particular organization. Includes private repositories if you are authorized. + +```js +user.orgRepos(orgname, function(err, repos) {}); +``` + +List all gists of a particular user. If username is ommitted gists of the current authenticated user are returned. + +```js +user.userGists(username, function(err, gists) {}); +``` + +## Gist API + +```js +var gist = github.getGist(3165654); +``` + +Read the contents of a Gist. + +```js +gist.read(function(err, gist) { + +}); +``` + +Updating the contents of a Git. Please consult the documentation on [GitHub](http://developer.github.com/v3/gists/). + +```js +var delta = { + "description": "the description for this gist", + "files": { + "file1.txt": { + "content": "updated file contents" + }, + "old_name.txt": { + "filename": "new_name.txt", + "content": "modified contents" + }, + "new_file.txt": { + "content": "a new file" + }, + "delete_this_file.txt": null + } +}; + +gist.update(delta, function(err, gist) { + +}); +``` + + +## Tests + +Github.js is automatically™ tested by the users of [Prose](http://prose.io). Because of that, we decided to save some time by not maintaining a test suite. Yes, you heard right. :) However, you can still consider it stable since it is used in production. + +##Setup + +Github.js has the following dependencies: + +- Underscore +- Base64 (for basic auth). You can leave this if you are not using basic auth. + +Include these before github.js : + +``` + +