Skip to content

Commit

Permalink
Update Configuration
Browse files Browse the repository at this point in the history
Currently we use an environment file for configuration.
This is fine, but there are a couple shortcomings

1) the environment file is read directly
2) the environment file is for your own local changes, which is not the
same as shared development features
3) it would not be obvious how to add production flags. This PR adds a
development.json file, but it would be easy to add a production.php file
and read from it when in production.
4) lastly, there aren't any nice helpers. This PR adds an isEnabled
feature, but ultimately it would be nice to improve it to support path
notation and maybe other functionaality as well.
  • Loading branch information
Jason Laster committed May 2, 2016
1 parent bd771b9 commit 2906d2c
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.DS_Store
build
node_modules
environment.json
public/js/configs/development.local.json
npm-debug.log
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ Then open another browser and go to `http://localhost:8000`.

##### User Configuration

You can create an `environment.json` to set user environmental variables, like the firefox source path. Start by copying the [`environment.sample`](https://github.com/jlongster/debugger.html/blob/master/environment.sample) file and update the source code location. **This is only necessary if you want to run tests**.

* **firefoxSrcDir**: _absolute path to local firefox source code_
* **firefoxObjDir**: _absolute path to a local build of firefox_

**NOTE**: Firefox source code is available on github at [gecko-dev](https://github.com/mozilla/gecko-dev/). For a faster download add the depth option to your git clone `git clone --depth=1 https://github.com/mozilla/gecko-dev.git` The MDN article [Working with Mozilla source code](https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Source_Code) has a number of other options.
You can create a `development.local.json` for local user settings in `public/js/configs`.

##### Remote Debugging
If you'd like to connect an existing Firefox browser to debugger.html, you can press `shift+F2` to open the developer toolbar and type `listen 6080` into the developer toolbar console.
3 changes: 0 additions & 3 deletions environment.sample

This file was deleted.

4 changes: 4 additions & 0 deletions public/js/configs/development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"development": true,
"logging": true
}
3 changes: 3 additions & 0 deletions public/js/configs/development.local.sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{

}
34 changes: 34 additions & 0 deletions public/js/configs/feature.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"use strict";

let config = {};

const developmentConfig = require("./development");

// Hack, to let local development files be ignored by git
let localDevelopmentConfig;
try {
localDevelopmentConfig = require("./development.local");
} catch (e) {
localDevelopmentConfig = {};
}

config = Object.assign({}, developmentConfig, localDevelopmentConfig);

// only used for testing purposes
function stubConfig(stub) {
config = stub;
}

function isEnabled(name) {
return config[name];
}

function isDevelopment() {
return isEnabled("development");
}

module.exports = {
isEnabled,
isDevelopment,
stubConfig
};
32 changes: 32 additions & 0 deletions public/js/configs/tests/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"globals": {
"after": true,
"afterEach": true,
"before": true,
"beforeEach": true,
"context": true,
"describe": true,
"it": true,
"mocha": true,
"setup": true,
"specify": true,
"suite": true,
"suiteSetup": true,
"suiteTeardown": true,
"teardown": true,
"test": true,
"xcontext": true,
"xdescribe": true,
"xit": true,
"xspecify": true,
"assert": true,
"expect": true,
"equal": true,
"ok": true
},
"rules": {
"camelcase": 0,
"no-unused-vars": [2, {"vars": "all", "args": "none", "varsIgnorePattern": "run_test"}],
"max-nested-callbacks": [2, 4],
}
}
31 changes: 31 additions & 0 deletions public/js/configs/tests/feature.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"use strict";

const { isDevelopment, isEnabled, stubConfig } = require("../feature");
const expect = require("expect.js");

describe("feature", () => {
it("isDevelopment", () => {
stubConfig({ development: true });
expect(isDevelopment()).to.be.truthy;
});

it("isDevelopment - not defined", () => {
stubConfig({ });
expect(isDevelopment()).to.be.falsey;
});

it("isEnabled - enabled", function() {
stubConfig({ featureA: true });
expect(isEnabled("featureA")).to.be.truthy;
});

it("isEnabled - disabled", function() {
stubConfig({ featureA: false });
expect(isEnabled("featureA")).to.be.falsey;
});

it("isEnabled - not present", function() {
stubConfig({});
expect(isEnabled("featureA")).to.be.undefined;
});
});
10 changes: 2 additions & 8 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@

const path = require("path");
const ExtractTextPlugin = require("extract-text-webpack-plugin");

let environment;
try {
environment = require("./environment");
} catch (e) {
environment = {};
}
const isEnabled = require("./public/js/configs/feature").isEnabled;

let config = {
entry: "./public/js/main.js",
Expand Down Expand Up @@ -41,7 +35,7 @@ let config = {

// NOTE: This is only needed to fix a bug with chrome devtools' debugger and
// destructuring params https://github.com/jlongster/debugger.html/issues/67
if (environment.transformParameters) {
if (isEnabled("transformParameters")) {
config.module.loaders.push({
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
Expand Down

0 comments on commit 2906d2c

Please sign in to comment.