From 3f2dd4cf25afdf9fffba169cf1573e1d0459b475 Mon Sep 17 00:00:00 2001 From: Lennart Kats Date: Thu, 5 Mar 2015 09:54:49 +0100 Subject: [PATCH] Revert "Revert "Merge pull request +6023 from c9/profile-integration"" This reverts commit e6fc5d467dc6a4c8f8d962ff0c2930b805d4d2e2. --- node_modules/c9/git.js | 34 ++----------------- node_modules/c9/git_test.js | 2 +- node_modules/c9/git_url_parse.js | 36 ++++++++++++++++++++ node_modules/vfs-local/localfs.js | 32 +++++++++++------- plugins/c9.ide.watcher/watcher.js | 56 +++++++++++++++++-------------- plugins/c9.static/build.js | 7 +--- scripts/makestatic.js | 8 +++++ 7 files changed, 100 insertions(+), 75 deletions(-) create mode 100644 node_modules/c9/git_url_parse.js diff --git a/node_modules/c9/git.js b/node_modules/c9/git.js index dcbf0328..307d5402 100644 --- a/node_modules/c9/git.js +++ b/node_modules/c9/git.js @@ -1,44 +1,16 @@ "use strict"; -var Url = require("url"); +require("amd-loader"); + var Fs = require("fs"); var Path = require("path"); var exec = require("child_process").exec; +exports.parse = require("./git_url_parse"); exports.isValidUrl = function(url) { return !!exports.parse(url); }; -exports.parse = function(url) { - var m = url.match(/^(git)@([\w\.\d\-\_]+)(?:\/|:)([\w\.\d\-\_\/]+)/); - if (m) { - return { - protocol: "ssh:", - auth: m[1], - hostname: m[2], - pathname: m[3] - }; - } - - var parsed = Url.parse(url); - if ( - parsed && - parsed.protocol && - parsed.protocol.match(/^(git|http|https):$/) && - parsed.hostname && - parsed.slashes && - parsed.pathname - ) - return { - protocol: parsed.protocol, - auth: parsed.auth || "", - hostname: parsed.hostname, - pathname: parsed.pathname.replace(/^\/+/, ""), - full: url - }; - else - return null; -}; exports.getHeadRevision = function(path, callback) { exec("git rev-parse HEAD", { diff --git a/node_modules/c9/git_test.js b/node_modules/c9/git_test.js index fae73a2b..04234bfc 100644 --- a/node_modules/c9/git_test.js +++ b/node_modules/c9/git_test.js @@ -62,7 +62,7 @@ module.exports = { assert.equal(rev.length, 40); next(); - }, + }, "test get head branch": function(next) { git.getHeadBranch(__dirname, function(err, rev) { diff --git a/node_modules/c9/git_url_parse.js b/node_modules/c9/git_url_parse.js new file mode 100644 index 00000000..e701228a --- /dev/null +++ b/node_modules/c9/git_url_parse.js @@ -0,0 +1,36 @@ +define(function(require, exports, module) { + "use strict"; + + var Url = require("url"); + + module.exports = function(url) { + var m = url.match(/^(git)@([\w\.\d\-\_]+)(?:\/|:)([\w\.\d\-\_\/]+)/); + if (m) { + return { + protocol: "ssh:", + auth: m[1], + hostname: m[2], + pathname: m[3] + }; + } + + var parsed = Url.parse(url); + if ( + parsed && + parsed.protocol && + parsed.protocol.match(/^(git|http|https):$/) && + parsed.hostname && + parsed.slashes && + parsed.pathname + ) + return { + protocol: parsed.protocol, + auth: parsed.auth || "", + hostname: parsed.hostname, + pathname: parsed.pathname.replace(/^\/+/, ""), + full: url + }; + else + return null; + }; +}); \ No newline at end of file diff --git a/node_modules/vfs-local/localfs.js b/node_modules/vfs-local/localfs.js index 36d0f3aa..f5262624 100644 --- a/node_modules/vfs-local/localfs.js +++ b/node_modules/vfs-local/localfs.js @@ -1157,6 +1157,7 @@ module.exports = function setup(fsOptions) { } try { + removeFromList(); fileWatchers[path] = fileWatchers[path] || []; fileWatchers[path].push(_self); @@ -1234,14 +1235,15 @@ module.exports = function setup(fsOptions) { } } - function handleWatchEvent(event, filename) { - console.log("watch event", event, filename, path); + var handleWatchEvent = this.handleWatchEvent = function(event, filename, isVfsWrite) { // it is a temp file if (filename && filename.substr(-1) == "~" && filename.charAt(0) == ".") return; createStatEntry(pathBasename(path), path, function(entry) { + entry.vfsWrite = isVfsWrite || false; + if (entry.err) { event = "delete"; close(); @@ -1292,7 +1294,7 @@ module.exports = function setup(fsOptions) { } var sendToAllListeners = this.sendToAllListeners = function(event, filename, entry, files) { - listeners.forEach(function(fn){ + listeners.forEach(function(fn) { fn(event, filename, entry, files); }); }; @@ -1368,27 +1370,33 @@ module.exports = function setup(fsOptions) { function writeToWatchedFile(path, callback) { if (!fileWatchers[path]) return callback(function(c) { c(); }); + var watchers = fileWatchers[path].slice(); + var parentDir = dirname(path) + "/"; + var dirWatchers = (fileWatchers[parentDir] || []).slice(); + watchers.forEach(function(w) { w.pause(); }); callback(done); - function done(callback) { + function loop(watchers, path, event, callback) { if (!watchers.length) return callback(); - - // Notify each watcher of changes and reactivate it + var watcher = watchers.pop(); - fs.stat(path, function(err, stat) { - if (err || !stat) return; - stat.vfsWrite = true; - watcher.sendToAllListeners("change", basename(path), stat); - }); + watcher.handleWatchEvent(event, basename(path), true); + watcher.resume(function() { - done(callback); + loop(watchers, path, event, callback); }); } + + function done(callback) { + loop(watchers, path, "change", function() { + loop(dirWatchers, parentDir, "directory", callback); + }); + } } function connect(port, options, callback) { diff --git a/plugins/c9.ide.watcher/watcher.js b/plugins/c9.ide.watcher/watcher.js index eb02680e..48207171 100644 --- a/plugins/c9.ide.watcher/watcher.js +++ b/plugins/c9.ide.watcher/watcher.js @@ -175,33 +175,39 @@ define(function(require, exports, module) { if (WAIT_FOR_SIGNAL) ignore(path, 200); // console.warn("[watchers] ignored event for", path, stat.vfsWrite ? "(was vfsWrite)" : "(was on ignore list)"); - return; + + fireWatcherEvent(".all"); + } else { + fireWatcherEvent(""); + fireWatcherEvent(".all"); } - if (event == "error") { - // console.error("[watchers] received error for", path, err, stat); - } - else if (event == "delete") { - fs.unwatch(path, handler); - delete handlers[path]; - // console.log("[watchers] received", event, "event for", path, stat); - emit("delete", { path : path }); - } - else if (event == "directory") { - emit("directory", { - path: path, - files: files, - stat: stat - }); - } - else { - // console.log("[watchers] received", event, "event for", path, stat); - emit("change", { - type: event, //change || rename - filename: filename, - path: path, - stat: stat - }); + function fireWatcherEvent(eventSuffix) { + if (event == "error") { + // console.error("[watchers] received error for", path, err, stat); + } + else if (event == "delete") { + fs.unwatch(path, handler); + delete handlers[path]; + // console.log("[watchers] received", event, "event for", path, stat); + emit("delete" + eventSuffix, { path : path }); + } + else if (event == "directory") { + emit("directory" + eventSuffix, { + path: path, + files: files, + stat: stat + }); + } + else { + // console.log("[watchers] received", event, "event for", path, stat); + emit("change" + eventSuffix, { + type: event, // change || rename + filename: filename, + path: path, + stat: stat + }); + } } }); } diff --git a/plugins/c9.static/build.js b/plugins/c9.static/build.js index b33a5db0..e93d4662 100644 --- a/plugins/c9.static/build.js +++ b/plugins/c9.static/build.js @@ -206,12 +206,7 @@ function main(options, imports, register) { function sharedModules() { return [ - "lib/architect/architect", - "ace/mode/html", - "ace/mode/javascript", - "ace/mode/css", - "ace/mode/c9search", - "ace/multi_select" + "lib/architect/architect" ]; } diff --git a/scripts/makestatic.js b/scripts/makestatic.js index 5c40cd54..d640ac78 100755 --- a/scripts/makestatic.js +++ b/scripts/makestatic.js @@ -20,6 +20,8 @@ if (!module.parent) { .boolean("symlink") .describe("compress", "Compress output files") .boolean("compress") + .describe("react-style", "compile react less CSS") + .boolean("react-style") .describe("dest", "destination folder for the static files") .boolean("help") .describe("help", "Show command line options."); @@ -106,6 +108,12 @@ function main(config, settings, options, callback) { app.services.makestatic.getMounts(options.dest, callback); else if (options.symlink) app.services.makestatic.symlink(options.dest, callback); + else if (options["react-style"]) + app.services["react.style"].compile(function(err, code) { + if (err) return callback(err); + console.log(code); + callback(); + }); else app.services.makestatic.copy(options.dest, callback); });