Skip to content
This repository was archived by the owner on Sep 23, 2020. It is now read-only.

Commit 6bbca67

Browse files
Initial Commit Version 0.0.1
1 parent 84cd2b9 commit 6bbca67

File tree

3 files changed

+199
-0
lines changed

3 files changed

+199
-0
lines changed

main.js

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright (c) 2013 Bernhard Sirlinger. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
* DEALINGS IN THE SOFTWARE.
21+
*
22+
*/
23+
24+
25+
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4,
26+
maxerr: 50, browser: true */
27+
/*global $, define, brackets */
28+
29+
define(function (require, exports, module) {
30+
"use strict";
31+
32+
var AppInit = brackets.getModule("utils/AppInit"),
33+
Commands = brackets.getModule("command/Commands"),
34+
CommandManager = brackets.getModule("command/CommandManager"),
35+
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
36+
FileUtils = brackets.getModule("file/FileUtils"),
37+
LiveDevServerManager = brackets.getModule("LiveDevelopment/LiveDevServerManager"),
38+
NodeConnection = brackets.getModule("utils/NodeConnection"),
39+
ProjectManager = brackets.getModule("project/ProjectManager");
40+
41+
/**
42+
* @const
43+
* Amount of time to wait before automatically rejecting the connection
44+
* deferred. If we hit this timeout, we'll never have a node connection
45+
* for the static server in this run of Brackets.
46+
*/
47+
var NODE_CONNECTION_TIMEOUT = 5000; // 5 seconds
48+
49+
/**
50+
* @private
51+
* @type{jQuery.Deferred.<NodeConnection>}
52+
* A deferred which is resolved with a NodeConnection or rejected if
53+
* we are unable to connect to Node.
54+
*/
55+
var _nodeConnectionDeferred = new $.Deferred();
56+
57+
/**
58+
* @private
59+
* @type {NodeConnection}
60+
*/
61+
var _nodeConnection = new NodeConnection();
62+
63+
function initExtension() {
64+
var connectionTimeout = setTimeout(function () {
65+
console.error("[FileWatcher] Timed out while trying to connect to node");
66+
_nodeConnectionDeferred.reject();
67+
}, NODE_CONNECTION_TIMEOUT);
68+
69+
_nodeConnection.connect(true).then(function () {
70+
_nodeConnection.loadDomains(
71+
[ExtensionUtils.getModulePath(module, "node/FileWatcherDomain")],
72+
true
73+
).done(
74+
function () {
75+
$(_nodeConnection).on("fileWatcher.fileSystemChange", function (event, orgEvent, type) {
76+
if (orgEvent !== "change") {
77+
CommandManager.execute(Commands.FILE_REFRESH);
78+
}
79+
});
80+
81+
clearTimeout(connectionTimeout);
82+
83+
_nodeConnectionDeferred.resolveWith(null, [_nodeConnection]);
84+
}).fail(
85+
function () { // Failed to connect
86+
console.error("[FileWatcher] Failed to connect to node", arguments);
87+
_nodeConnectionDeferred.reject();
88+
}
89+
);
90+
});
91+
92+
return _nodeConnectionDeferred.promise();
93+
}
94+
95+
AppInit.htmlReady(function () {
96+
_nodeConnectionDeferred.done(function (nodeConnection) {
97+
//nodeConnection.fileWatcher.startWatching(ProjectManager.getProjectRoot().fullPath, 1000);
98+
$(ProjectManager).on("projectOpen", function () {
99+
_nodeConnection.domains.fileWatcher.startWatching(ProjectManager.getProjectRoot().fullPath);
100+
});
101+
});
102+
});
103+
104+
exports.initExtension = initExtension;
105+
});

node/FileWatcherDomain.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright (c) 2012 Bernhard Sirlinger. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
* DEALINGS IN THE SOFTWARE.
21+
*
22+
*/
23+
24+
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50, node: true */
25+
/*global */
26+
27+
(function () {
28+
"use strict";
29+
30+
var watch = require("directory-tree-watcher");
31+
32+
var _domainManager;
33+
34+
function emitEvents(file, event) {
35+
_domainManager.emitEvent("fileWatcher", "fileSystemChange", [event, file]);
36+
}
37+
38+
function startWatching(dir) {
39+
watch(dir, function(event, file) {
40+
emitEvents(file, event);
41+
}, function (error, Watcher) {
42+
43+
});
44+
}
45+
46+
/**
47+
* Initializes the StaticServer domain with its commands.
48+
* @param {DomainManager} domainManager The DomainManager for the server
49+
*/
50+
function init(domainManager) {
51+
_domainManager = domainManager;
52+
if (!domainManager.hasDomain("fileWatcher")) {
53+
domainManager.registerDomain("fileWatcher", {major: 0, minor: 1});
54+
}
55+
56+
_domainManager.registerCommand(
57+
"fileWatcher",
58+
"startWatching",
59+
startWatching,
60+
false,
61+
"",
62+
[{
63+
name: "dir",
64+
type: "string",
65+
description: "absolute filesystem path for the watcher entry node"
66+
}]
67+
);
68+
69+
_domainManager.registerEvent(
70+
"fileWatcher",
71+
"fileSystemChange",
72+
[{
73+
name: "event",
74+
type: "{type: string, path: string, dir: boolean}",
75+
description: ""
76+
}]
77+
);
78+
}
79+
80+
exports.init = init;
81+
82+
}());

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "bsirlinger.bracketsFileWatcher",
3+
"title": "FileWatcher",
4+
"description": "Adds file watching for the current Project.",
5+
"homepage": "https://github.com/cfjedimaster/brackets-csslint",
6+
"version": "0.0.1",
7+
"author": "Bernhard Sirlinger <bernhard@sirlinger.de> (https://github.com/WebsiteDeveloper)",
8+
"license": "MIT",
9+
"engines": {
10+
"brackets": ">=0.27.0"
11+
}
12+
}

0 commit comments

Comments
 (0)