Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

injecting into the browser working, now to simplify

  • Loading branch information...
commit 8d2de701555d1da125b72f3f1b935443dde2e76a 1 parent 2f3ab88
@lancejpollard authored
View
4 README.md
@@ -14,7 +14,7 @@ Here is the [example app](https://github.com/viatropos/design.io-example) for th
npm install design.io -g
```
-**Note**: Design.io uses Ruby to watch files on a Mac, using Mac's FSEvents. FSEvents are a very efficient way of getting notified when a file changes, the other solution is to iterate over the project file tree every <n> milliseconds, but that quickly becomes a problem with decently sized projects. The reason design.io uses Ruby to do this is because the Node.js `fs.watch` command does not work correctly across different versions of node and even sometimes on different versions of the Mac OS. There are several issues posted about this: https://github.com/joyent/node/issues/search?q=fs.watch. If you know of a better workaround, please let me know - this is only temporary, but Mac comes with Ruby and this solution works very well. Do note though, if you don't have [RVM (Ruby Version Manager)](https://rvm.beginrescueend.com/rvm/install/) installed, you most likely have to install design.io with `sudo npm install design.io -g`.
+**Note**: Design.io uses Ruby to watch files on a Mac, using Mac's FSEvents. FSEvents is the most efficient way of getting notified when a file changes on a Mac. The other solution is to iterate over the project file tree every <n> milliseconds, but that quickly becomes a problem with decently sized projects. The reason design.io uses Ruby to do this is because the Node.js `fs.watch` command does not work correctly across different versions of node and even sometimes on different versions of the Mac OS. There are several issues posted about this: https://github.com/joyent/node/issues/search?q=fs.watch. If you know of a better workaround, please let me know - this is only temporary, but Mac comes with Ruby and this solution works very well. Do note though, if you don't have [RVM (Ruby Version Manager)](https://rvm.beginrescueend.com/rvm/install/) installed, you most likely have to install design.io with `sudo npm install design.io -g`.
## Run
@@ -159,7 +159,7 @@ watch /\.md$/ # some custom one...
(The MIT License)
-Copyright &copy; 2011 [Lance Pollard](http://twitter.com/viatropos) &lt;lancejpollard@gmail.com&gt;
+Copyright &copy; 2011 - 2012 [Lance Pollard](http://twitter.com/viatropos) &lt;lancejpollard@gmail.com&gt;
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
View
8 lib/design.io/command.js
@@ -1,8 +1,10 @@
(function() {
- var command, forever;
+ var command, forever, fs;
global._console || (global._console = require("underscore.logger"));
+ fs = require('fs');
+
forever = require("forever");
command = function(argv) {
@@ -48,7 +50,9 @@
});
}
})();
- child.on("start", function() {});
+ child.on("start", function(data) {
+ return console.log(data);
+ });
child.on("exit", function() {});
child.on("stop", function() {});
child.on("stdout", function(data) {});
View
33 lib/design.io/command/start.js
@@ -17,15 +17,15 @@
Project = require("../project");
- io.set('log level', 1);
+ io.set('log level', 2);
- io.on("connection", function(socket) {
+ io.sockets.on("connection", function(socket) {
socket.on("userAgent", function(data) {
socket.room = data.namespace;
socket.join(data.namespace);
return socket.set("userAgent", data, function() {
- socket.emit("ready");
- Project.find(data.namespace).connect();
+ var _this = this;
+ hook.emit("connect", function() {});
return true;
});
});
@@ -47,22 +47,35 @@
hook = new Hook({
name: "design.io-server",
- debug: false,
- silent: true,
+ debug: true,
+ silent: false,
m: false
});
- hook.on("hook::ready", function(data) {
+ hook.on("hook::ready", function(data, callback, event) {
return _console.info("Design.io started on port " + command.port);
});
- hook.on("*::exec", function(data, callback, event) {
+ hook.on("*::*::ready", function(data, callback, event) {});
+
+ hook.on("*::*::watch", function(data, callback, event) {
+ var object;
if (!event.name.match("design.io-watcher")) return;
- return io.sockets["in"](data.namespace).emit(data.action, JSON.stringify(data));
+ object = JSON.parse(data);
+ return io.sockets["in"](object.namespace).emit("watch", data);
+ });
+
+ hook.on("*::*::exec", function(data, callback, event) {
+ var object;
+ if (!event.name.match("design.io-watcher")) return;
+ object = JSON.parse(data);
+ return io.sockets["in"](object.namespace).emit("exec", data);
});
hook.start();
- app.get("design.io", function(request, response) {});
+ app.get("/design.io", function(request, response) {
+ return response.write("Design.io Connected!");
+ });
}).call(this);
View
11 lib/design.io/project.js
@@ -78,9 +78,9 @@
}
store[this.namespace] = this;
this.hook = new Hook({
- name: "design.io-watcher",
- debug: false,
- silent: true
+ name: "design.io-watcher::" + this.namespace,
+ debug: true,
+ silent: false
});
}
@@ -112,6 +112,10 @@
hook.on("design.io-server::stop", function() {
return hook.stop();
});
+ hook.on("design.io-server::connect", function(data, callback) {
+ _this.connect();
+ return callback();
+ });
hook.start();
return this;
};
@@ -196,6 +200,7 @@
if (callback) callback.call(this, null, null);
return;
}
+ data.namespace || (data.namespace = this.namespace);
data = JSON.stringify(data, this.replacer);
return this.hook.emit(action, data);
};
View
2  package.json
@@ -1,6 +1,6 @@
{
"name": "design.io",
- "version": "0.3.0-5",
+ "version": "0.3.0-6",
"description": "Design and Test Your App in Real-Time from TextMate",
"homepage": "http://github.com/viatropos/design.io",
"main": "lib/design.io.js",
View
4 src/design.io/command.coffee
@@ -1,4 +1,5 @@
global._console ||= require("underscore.logger")
+fs = require 'fs'
forever = require "forever"
@@ -45,7 +46,8 @@ command.run = (argv) ->
else
forever.start ["node", "#{process.cwd()}/node_modules/design.io/lib/design.io/command/watch.js"].concat(args), silent: false
- child.on "start", ->
+ child.on "start", (data) ->
+ console.log data
child.on "exit", ->
View
31 src/design.io/command/start.coffee
@@ -8,15 +8,15 @@ connect = require('connect')
app = express.createServer()
io = require('socket.io').listen(app)
Project = require("../project")
-io.set 'log level', 1
+io.set 'log level', 2
-io.on "connection", (socket) ->
+io.sockets.on "connection", (socket) ->
socket.on "userAgent", (data) ->
socket.room = data.namespace
socket.join(data.namespace)
socket.set "userAgent", data, ->
- socket.emit "ready"
- Project.find(data.namespace).connect()
+ hook.emit "connect", =>
+ #Project.find(data.namespace).connect()
true
socket.on "log", (data) ->
@@ -31,18 +31,31 @@ app.listen(command.port)
app.use express.static(__dirname + '/../..')
app.use connect.bodyParser()
-hook = new Hook(name: "design.io-server", debug: false, silent: true, m: false)
+hook = new Hook(name: "design.io-server", debug: true, silent: false, m: false)
-hook.on "hook::ready", (data) ->
+hook.on "hook::ready", (data, callback, event) ->
_console.info "Design.io started on port #{command.port}"
-hook.on "*::exec", (data, callback, event) ->
+hook.on "*::*::ready", (data, callback, event) ->
+ #new Project(event.name.split("::")[1])
+
+hook.on "*::*::watch", (data, callback, event) ->
+ return unless event.name.match("design.io-watcher")
+ # updated, new Date, /Users/..., cwd, "my-project"
+ # {action, timestamp, previous, current, path, namespace} = data
+ # emit to browser
+ object = JSON.parse(data)
+ io.sockets.in(object.namespace).emit "watch", data
+
+hook.on "*::*::exec", (data, callback, event) ->
return unless event.name.match("design.io-watcher")
# updated, new Date, /Users/..., cwd, "my-project"
# {action, timestamp, previous, current, path, namespace} = data
# emit to browser
- io.sockets.in(data.namespace).emit data.action, JSON.stringify(data)
+ object = JSON.parse(data)
+ io.sockets.in(object.namespace).emit "exec", data
hook.start()
-app.get "design.io", (request, response) ->
+app.get "/design.io", (request, response) ->
+ response.write "Design.io Connected!"
View
9 src/design.io/project.coffee
@@ -62,7 +62,7 @@ class Project
throw new Error("Only one project per namespace") if store.hasOwnProperty(@namespace)
store[@namespace] = @
- @hook = new Hook(name: "design.io-watcher", debug: false, silent: true)
+ @hook = new Hook(name: "design.io-watcher::#{@namespace}", debug: true, silent: false)
watch: ->
hook = @hook
@@ -74,7 +74,6 @@ class Project
new (require('./listener/mac')) root: @root, ignore: @ignoredPaths, (path, options) =>
options.namespace = @namespace
options.paths = if path instanceof Array then path else [path]
-
for path in options.paths
@changed(path, options)
@
@@ -82,6 +81,10 @@ class Project
hook.on "design.io-server::stop", =>
hook.stop()
+ hook.on "design.io-server::connect", (data, callback) =>
+ @connect()
+ callback()
+
hook.start()
@
@@ -156,8 +159,8 @@ class Project
callback.call(@, null, null) if callback
return
+ data.namespace ||= @namespace
data = JSON.stringify(data, @replacer)
- # url = "#{@url}/design.io/#{action}"
@hook.emit action, data
Please sign in to comment.
Something went wrong with that request. Please try again.