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

Commit

Permalink
use the same build folder for node and the browser
Browse files Browse the repository at this point in the history
  • Loading branch information
flosse committed Dec 4, 2012
1 parent c43f0cd commit 0d3aed6
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 89 deletions.
4 changes: 4 additions & 0 deletions .npmignore
Expand Up @@ -2,9 +2,13 @@ src/
spec/
build/
bundles/
lib/
Cakefile
grunt.js
buster.js
.gitignore
.npmignore
.travis.yml
*.log
*.swp
*.coffee
64 changes: 20 additions & 44 deletions dist/scaleApp.js
@@ -1,13 +1,13 @@

/*
scaleapp - v0.3.9 - 2012-11-29
scaleapp - v0.3.9 - 2012-12-04
This program is distributed under the terms of the MIT license.
Copyright (c) 2011-2012 Markus Kohlhase <mail@markus-kohlhase.de>
*/


(function() {
var FUNCTION, Mediator, OBJECT, STRING, Sandbox, VERSION, addModule, checkType, clone, core, coreKeywords, createInstance, doForAll, error, getArgumentNames, getInstanceOptions, instanceOpts, instances, k, ls, mediator, modules, onInstantiate, onInstantiateFunctions, plugins, register, registerPlugin, runSeries, runWaterfall, sandboxKeywords, setInstanceOptions, start, startAll, stop, stopAll, uniqueId, unregister, unregisterAll, util, v,
var Mediator, Sandbox, VERSION, addModule, checkType, clone, core, coreKeywords, createInstance, doForAll, error, getArgumentNames, getInstanceOptions, instanceOpts, instances, k, ls, mediator, modules, onInstantiate, onInstantiateFunctions, plugins, register, registerPlugin, runSeries, runWaterfall, sandboxKeywords, setInstanceOptions, start, startAll, stop, stopAll, uniqueId, unregister, unregisterAll, util, v,
__slice = [].slice,
__hasProp = {}.hasOwnProperty,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
Expand Down Expand Up @@ -187,14 +187,6 @@ Copyright (c) 2011-2012 Markus Kohlhase <mail@markus-kohlhase.de>
uniqueId: uniqueId
};

if ((typeof module !== "undefined" && module !== null ? module.exports : void 0) != null) {
module.exports = util;
}

if (((typeof module !== "undefined" && module !== null ? module.exports : void 0) != null) && typeof require === "function") {
util = require("./Util");
}

Mediator = (function() {

function Mediator(obj, cascadeChannels) {
Expand Down Expand Up @@ -376,10 +368,6 @@ Copyright (c) 2011-2012 Markus Kohlhase <mail@markus-kohlhase.de>

})();

if ((typeof module !== "undefined" && module !== null ? module.exports : void 0) != null) {
module.exports = Mediator;
}

Sandbox = (function() {

function Sandbox(core, instanceId, options) {
Expand Down Expand Up @@ -407,24 +395,12 @@ Copyright (c) 2011-2012 Markus Kohlhase <mail@markus-kohlhase.de>

VERSION = "0.3.9";

FUNCTION = "function";

STRING = "string";

OBJECT = "object";

checkType = function(type, val, name) {
if (typeof val !== type) {
throw new TypeError("" + name + " has to be a " + type);
}
};

if (((typeof module !== "undefined" && module !== null ? module.exports : void 0) != null) && typeof require === FUNCTION && !(require.amd != null)) {
Mediator = require("./Mediator");
Sandbox = require("./Sandbox");
util = require("./Util");
}

modules = {};

instances = {};
Expand All @@ -445,12 +421,12 @@ Copyright (c) 2011-2012 Markus Kohlhase <mail@markus-kohlhase.de>

onInstantiate = function(fn, moduleId) {
var entry;
checkType(FUNCTION, fn, "parameter");
checkType("function", fn, "parameter");
entry = {
context: this,
callback: fn
};
if (typeof moduleId === STRING) {
if (typeof moduleId === "string") {
if (onInstantiateFunctions[moduleId] == null) {
onInstantiateFunctions[moduleId] = [];
}
Expand Down Expand Up @@ -528,13 +504,13 @@ Copyright (c) 2011-2012 Markus Kohlhase <mail@markus-kohlhase.de>

addModule = function(moduleId, creator, opt) {
var modObj;
checkType(STRING, moduleId, "module ID");
checkType(FUNCTION, creator, "creator");
checkType(OBJECT, opt, "option parameter");
checkType("string", moduleId, "module ID");
checkType("function", creator, "creator");
checkType("object", opt, "option parameter");
modObj = new creator();
checkType(OBJECT, modObj, "the return value of the creator");
checkType(FUNCTION, modObj.init, "'init' of the module");
checkType(FUNCTION, modObj.destroy, "'destroy' of the module ");
checkType("object", modObj, "the return value of the creator");
checkType("function", modObj.init, "'init' of the module");
checkType("function", modObj.destroy, "'destroy' of the module ");
if (modules[moduleId] != null) {
throw new TypeError("module " + moduleId + " was already registered");
}
Expand All @@ -560,8 +536,8 @@ Copyright (c) 2011-2012 Markus Kohlhase <mail@markus-kohlhase.de>

setInstanceOptions = function(instanceId, opt) {
var k, v, _ref, _results;
checkType(STRING, instanceId, "instance ID");
checkType(OBJECT, opt, "option parameter");
checkType("string", instanceId, "instance ID");
checkType("object", opt, "option parameter");
if ((_ref = instanceOpts[instanceId]) == null) {
instanceOpts[instanceId] = {};
}
Expand Down Expand Up @@ -596,8 +572,8 @@ Copyright (c) 2011-2012 Markus Kohlhase <mail@markus-kohlhase.de>
opt = {};
}
try {
checkType(STRING, moduleId, "module ID");
checkType(OBJECT, opt, "second parameter");
checkType("string", moduleId, "module ID");
checkType("object", opt, "second parameter");
if (modules[moduleId] == null) {
throw new Error("module doesn't exist");
}
Expand Down Expand Up @@ -760,10 +736,10 @@ Copyright (c) 2011-2012 Markus Kohlhase <mail@markus-kohlhase.de>
var RESERVED_ERROR, k, v, _ref, _ref1;
RESERVED_ERROR = new Error("plugin uses reserved keyword");
try {
checkType(OBJECT, plugin, "plugin");
checkType(STRING, plugin.id, "'id' of plugin");
if (typeof plugin.sandbox === FUNCTION) {
for (k in new plugin.sandbox(new Sandbox(core, ""))) {
checkType("object", plugin, "plugin");
checkType("string", plugin.id, "'id' of plugin");
if (typeof plugin.sandbox === "function") {
for (k in new plugin.sandbox(new Sandbox(core, ''))) {
if (__indexOf.call(sandboxKeywords, k) >= 0) {
throw RESERVED_ERROR;
}
Expand All @@ -774,7 +750,7 @@ Copyright (c) 2011-2012 Markus Kohlhase <mail@markus-kohlhase.de>
Sandbox.prototype[k] = v;
}
}
if (typeof plugin.core === OBJECT) {
if (typeof plugin.core === "object") {
for (k in plugin.core) {
if (__indexOf.call(coreKeywords, k) >= 0) {
throw RESERVED_ERROR;
Expand All @@ -789,7 +765,7 @@ Copyright (c) 2011-2012 Markus Kohlhase <mail@markus-kohlhase.de>
}
}
}
if (typeof plugin.onInstantiate === FUNCTION) {
if (typeof plugin.onInstantiate === "function") {
onInstantiate(plugin.onInstantiate);
}
plugins[plugin.id] = plugin;
Expand Down
2 changes: 1 addition & 1 deletion dist/scaleApp.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions grunt.js
Expand Up @@ -32,16 +32,16 @@ module.exports = function(grunt) {
coffee: {
compile: {
files: {
"dist/scaleApp.js": 'dist/scaleApp.coffee',
"dist/scaleApp.js": 'dist/scaleApp.coffee',
"dist/plugins/*.js": 'src/plugins/*.coffee',
"dist/modules/*.js": 'src/modules/*.coffee'
}
},
}
},
copy: {
dist: {
files: {
"dist/modules/":"src/modules/*.css",
"dist/modules/":"src/modules/*.css"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion spec/Mediator.spec.coffee
Expand Up @@ -4,7 +4,7 @@ describe "Mediator", ->

before ->
if typeof(require) is "function"
@Mediator = require "../src/Mediator"
@Mediator = require("../dist/scaleApp").Mediator
else if window?
@Mediator = window.scaleApp.Mediator
@paul = new @Mediator
Expand Down
2 changes: 1 addition & 1 deletion spec/Util.spec.coffee
Expand Up @@ -4,7 +4,7 @@ describe "Util", ->

before ->
if typeof(require) is "function"
@util = require "../src/Util"
@util = require("../dist/scaleApp").util
else if window?
@util = window.scaleApp.util

Expand Down
12 changes: 11 additions & 1 deletion spec/scaleApp.spec.coffee
Expand Up @@ -9,7 +9,7 @@ describe "scaleApp core", ->
before ->

if typeof(require) is "function"
@scaleApp = require "../src/scaleApp"
@scaleApp = require "../dist/scaleApp"
else if window?
@scaleApp = window.scaleApp

Expand Down Expand Up @@ -137,6 +137,16 @@ describe "scaleApp core", ->
@scaleApp.start "myId"
(expect @scaleApp.start "myId").toBeFalsy()

it "passes the options", (done) ->
mod = (sb) ->
init: (opt) ->
(expect typeof opt).toEqual "object"
(expect opt.foo).toEqual "bar"
done()
destroy: ->
@scaleApp.register "foo", mod
@scaleApp.start "foo", options: {foo: "bar"}

it "calls the callback function after the initialization", (done) ->

x = 0
Expand Down
5 changes: 0 additions & 5 deletions src/Mediator.coffee
@@ -1,6 +1,3 @@
if module?.exports? and typeof require is "function"
util = require "./Util"

class Mediator

constructor: (obj, @cascadeChannels=false) ->
Expand Down Expand Up @@ -114,5 +111,3 @@ class Mediator
else
s.context isnt o
))

module.exports = Mediator if module?.exports?
2 changes: 0 additions & 2 deletions src/Util.coffee
Expand Up @@ -79,5 +79,3 @@ util =
clone: clone
getArgumentNames: getArgumentNames
uniqueId: uniqueId

if module?.exports? then module.exports = util
6 changes: 3 additions & 3 deletions src/plugins/scaleApp.i18n.coffee
@@ -1,4 +1,4 @@
Mediator = window?.scaleApp?.Mediator or require? "../Mediator"
scaleApp = window?.scaleApp or require? "../scaleApp"

baseLanguage = "en"

Expand All @@ -9,7 +9,7 @@ getBrowserLanguage = ->
# By default the browsers language is used.
lang = getBrowserLanguage()

mediator = new Mediator
mediator = new scaleApp.Mediator

channelName = "i18n"

Expand Down Expand Up @@ -69,6 +69,6 @@ plugin =
unsubscribe: unsubscribe
setGlobal: setGlobal

window?.scaleApp.registerPlugin plugin if window?.scaleApp?
window.scaleApp.registerPlugin plugin if window?.scaleApp?
module.exports = plugin if module?.exports?
(define -> plugin) if define?.amd?
2 changes: 0 additions & 2 deletions src/plugins/scaleApp.permission.coffee
@@ -1,5 +1,3 @@
Mediator = window?.scaleApp?.Mediator or require? "../Mediator"

permissions = {}

addPermission = (id, action, channels) ->
Expand Down
44 changes: 18 additions & 26 deletions src/scaleApp.coffee
@@ -1,17 +1,9 @@
# constants
VERSION = "0.3.9"
FUNCTION = "function"
STRING = "string"
OBJECT = "object"

checkType = (type, val, name) ->
throw new TypeError "#{name} has to be a #{type}" unless typeof val is type

if module?.exports? and typeof require is FUNCTION and not require.amd?
Mediator = require "./Mediator"
Sandbox = require "./Sandbox"
util = require "./Util"

modules = {}
instances = {}
instanceOpts = {}
Expand All @@ -24,10 +16,10 @@ onInstantiateFunctions = _always: []

# registers a function that gets executed when a module gets instantiated.
onInstantiate = (fn, moduleId) ->
checkType FUNCTION, fn, "parameter"
checkType "function", fn, "parameter"
entry = { context: @, callback: fn }

if typeof moduleId is STRING
if typeof moduleId is "string"
onInstantiateFunctions[moduleId] = [] unless onInstantiateFunctions[moduleId]?
onInstantiateFunctions[moduleId].push entry
else if not moduleId?
Expand Down Expand Up @@ -78,15 +70,15 @@ createInstance = (moduleId, instanceId=moduleId, opt) ->

addModule = (moduleId, creator, opt) ->

checkType STRING, moduleId, "module ID"
checkType FUNCTION, creator, "creator"
checkType OBJECT, opt, "option parameter"
checkType "string", moduleId, "module ID"
checkType "function", creator, "creator"
checkType "object", opt, "option parameter"

modObj = new creator()

checkType OBJECT, modObj, "the return value of the creator"
checkType FUNCTION, modObj.init, "'init' of the module"
checkType FUNCTION, modObj.destroy, "'destroy' of the module "
checkType "object", modObj, "the return value of the creator"
checkType "function", modObj.init, "'init' of the module"
checkType "function", modObj.destroy, "'destroy' of the module "

throw new TypeError "module #{moduleId} was already registered" if modules[moduleId]?

Expand All @@ -104,8 +96,8 @@ register = (moduleId, creator, opt = {}) ->
false

setInstanceOptions = (instanceId, opt) ->
checkType STRING, instanceId, "instance ID"
checkType OBJECT, opt, "option parameter"
checkType "string", instanceId, "instance ID"
checkType "object", opt, "option parameter"
instanceOpts[instanceId] ?= {}
instanceOpts[instanceId][k] = v for k,v of opt

Expand All @@ -120,8 +112,8 @@ unregisterAll = (type) -> unregister id, type for id of type
start = (moduleId, opt={}) ->

try
checkType STRING, moduleId, "module ID"
checkType OBJECT, opt, "second parameter"
checkType "string", moduleId, "module ID"
checkType "object", opt, "second parameter"
throw new Error "module doesn't exist" unless modules[moduleId]?

instance = createInstance moduleId, opt.instanceId, opt.options
Expand Down Expand Up @@ -210,22 +202,22 @@ registerPlugin = (plugin) ->
RESERVED_ERROR = new Error "plugin uses reserved keyword"

try
checkType OBJECT, plugin, "plugin"
checkType STRING, plugin.id, "'id' of plugin"
checkType "object", plugin, "plugin"
checkType "string", plugin.id, "'id' of plugin"

if typeof plugin.sandbox is FUNCTION
for k of new plugin.sandbox new Sandbox core, ""
if typeof plugin.sandbox is "function"
for k of new plugin.sandbox new Sandbox core, ''
throw RESERVED_ERROR if k in sandboxKeywords
Sandbox::[k] = v for k, v of plugin.sandbox::

if typeof plugin.core is OBJECT
if typeof plugin.core is "object"
for k of plugin.core
throw RESERVED_ERROR if k in coreKeywords
for k,v of plugin.core
core[k] = v
exports?[k] = v

if typeof plugin.onInstantiate is FUNCTION
if typeof plugin.onInstantiate is "function"
onInstantiate plugin.onInstantiate

plugins[plugin.id] = plugin
Expand Down

0 comments on commit 0d3aed6

Please sign in to comment.