Skip to content

Commit

Permalink
Demonstrate loading Brackets modules from Node context
Browse files Browse the repository at this point in the history
  • Loading branch information
petetnt committed Dec 20, 2015
1 parent 21ca996 commit 0838a03
Show file tree
Hide file tree
Showing 305 changed files with 39 additions and 19,783 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"acord": "^1.0.0",
"classnames": "^2.2.1",
"codemirror": "github:codemirror/CodeMirror#61ca2db",
"connect": "^2.9.0",
"i18n": "github:requirejs/i18n",
"immutable": "^3.7.6",
"jquery": "^2.1.4",
Expand Down
6 changes: 4 additions & 2 deletions src/extensions/default/StaticServer/StaticServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ define(function (require, exports, module) {
var BaseServer = brackets.getModule("LiveDevelopment/Servers/BaseServer").BaseServer,
LiveDevelopmentUtils = brackets.getModule("LiveDevelopment/LiveDevelopmentUtils"),
PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
Strings = brackets.getModule("strings");
Strings = brackets.getModule("strings"),
FileUtils = brackets.getModule("file/FileUtils");


/**
Expand Down Expand Up @@ -62,7 +63,6 @@ define(function (require, exports, module) {
function StaticServer(config) {
this._nodeDomain = config.nodeDomain;
this._onRequestFilter = this._onRequestFilter.bind(this);

BaseServer.call(this, config);
}

Expand Down Expand Up @@ -135,6 +135,8 @@ define(function (require, exports, module) {
}

var port = sanitizePort(_prefs.get("port"));
var nodeModulesPath = FileUtils.getNativeBracketsDirectoryPath() + "/../node_modules/";
this._nodeDomain.exec("_loadNodeModules", nodeModulesPath);

this._nodeDomain.exec("getServer", self._root, port)
.done(function (address) {
Expand Down
36 changes: 31 additions & 5 deletions src/extensions/default/StaticServer/node/StaticServerDomain.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@

(function () {
"use strict";

var http = require("http"),
pathJoin = require("path").join,
connect = require("connect"),
utils = require("connect/lib/utils"),
mime = require("connect/node_modules/send/node_modules/mime"),
parse = utils.parseUrl;
connect = null,
utils = null,
mime = null,
parse = null;

var _domainManager;

Expand Down Expand Up @@ -107,6 +106,18 @@
function getPathKey(path) {
return PATH_KEY_PREFIX + normalizeRootPath(path);
}

/**
* @private
* Loads third party dependencies using the global context
* @param {string} srcPath - absolute path to global brackets node folder
*/
function _cmdLoadNodeModules(srcPath) {
connect = require(srcPath + "connect");
utils = require(srcPath + "connect/lib/utils");
mime = require(srcPath + "mime");
parse = utils.parseUrl;
}

/**
* @private
Expand Down Expand Up @@ -365,6 +376,21 @@
if (!domainManager.hasDomain("staticServer")) {
domainManager.registerDomain("staticServer", {major: 0, minor: 1});
}

_domainManager.registerCommand(
"staticServer",
"_loadNodeModules",
_cmdLoadNodeModules,
false,
"Loads node modules from Brackets modules",
[{
name: "srcPath",
type: "string",
description: "Absolute path to the src-folder"
}],
[]
);

_domainManager.registerCommand(
"staticServer",
"_setRequestFilterTimeout",
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 0838a03

Please sign in to comment.