Compare commits

..

10 Commits

Author SHA1 Message Date
bfb9ebb994 0.0.15 2015-12-25 00:24:02 +01:00
84c25f3a67 cleaned up 2015-12-25 00:23:53 +01:00
1f4ffaff2a 0.0.14 2015-12-25 00:22:43 +01:00
101e7a86cd node vs browser env check is now working 2015-12-25 00:22:28 +01:00
acc0e5221b 0.0.13 2015-12-10 15:52:25 +01:00
a6839420f1 added merge and replace operations for objectstorage 2015-12-10 15:52:14 +01:00
2df7cf1467 0.0.12 2015-12-06 21:55:56 +01:00
bae4305dec update dependencies 2015-12-06 21:55:49 +01:00
1737075753 0.0.11 2015-12-06 21:50:05 +01:00
1a74ee8bb6 switched params for smartenv.obs.add() 2015-12-06 21:49:57 +01:00
15 changed files with 199 additions and 67 deletions

2
.gitignore vendored
View File

@ -8,3 +8,5 @@ npm-debug.log
ts/*.js
ts/*.js.map
test/browser/browserified/

View File

@ -9,9 +9,9 @@ var Environment = (function () {
this.isNode = true;
this.nodeVersion = process.version;
}
else {
else if (runtimeEnvArg == "browser") {
this.isBrowser = true;
this.isNode = true;
this.isNode = false;
this.nodeVersion = "undefined";
}
}
@ -35,15 +35,16 @@ var SmartenvEnvironment;
(function () {
var localRunTimeEnv = "undefined";
var localUserAgent = "undefined";
if (typeof window !== 'undefined') {
if (typeof window !== "undefined") {
localRunTimeEnv = 'browser';
localUserAgent = navigator.userAgent;
}
else if (typeof process !== 'undefined') {
else if (typeof process !== "undefined") {
localRunTimeEnv = 'node';
}
environment = new Environment(localRunTimeEnv, localUserAgent);
})();
envDetermined = true; // ensure code above only runs once
}
;
return environment;
@ -53,10 +54,12 @@ var SmartenvEnvironment;
*/
var printEnv = function () {
if (this.getEnv().isNode) {
plugins.beautylog.ok("running on NODE");
var smartenvVersion = require("./package.json").version;
plugins.beautylog.log("node version is " + this.getEnv().nodeVersion + " and smartenv version is " + smartenvVersion);
}
else {
plugins.beautylog.ok("running on BROWSER");
plugins.beautylog.log("browser is " + this.getEnv().userAgent);
}
plugins.beautylog.log("the smartenv registration store currently holds the following properties:");
@ -71,26 +74,48 @@ var SmartenvEnvironment;
var SmartenvObjectStorage;
(function (SmartenvObjectStorage) {
function init() {
var obs = {};
var obsItems = {};
obs.add = function (objectArg, paramName) {
if (paramName === void 0) { paramName = "undefined"; }
if (paramName == "undefined") {
plugins.beautylog.error("paramName is undefined");
return;
var obs = {
add: function (paramNameArg, objectArg) {
if (paramNameArg === void 0) { paramNameArg = "undefined"; }
if (objectArg === void 0) { objectArg = "undefined"; }
if (paramNameArg == "undefined") {
plugins.beautylog.error("paramName is undefined");
return;
}
if (objectArg == "undefined") {
plugins.beautylog.error("objectArg is undefined");
}
if (typeof obsItems[paramNameArg] === "undefined") {
obsItems[paramNameArg] = objectArg;
}
else {
plugins.beautylog.error("object is already present, so add operation has failed.");
}
return obsItems[paramNameArg];
},
replace: function (paramNameArg, objectArg) {
obsItems[paramNameArg] = objectArg;
},
merge: function (paramNameArg, objectArg) {
if (!(typeof obsItems[paramNameArg] === "undefined")) {
obsItems[paramNameArg] = plugins._.assign(obsItems[paramNameArg], objectArg);
}
else {
plugins.beautylog.error("object is not present, so there is nothing to merge");
}
},
get: function (keyName) {
return obsItems[keyName];
},
getAll: function () {
return obsItems;
},
addComplete: function (itemsArg) {
obsItems = plugins._.assign(obsItems, itemsArg);
return obsItems;
}
obsItems[paramName] = objectArg;
};
obs.get = function (keyName) {
return obsItems[keyName];
};
obs.getAll = function () {
return obsItems;
};
obs.addComplete = function (itemsArg) {
obsItems = plugins._.assign(obsItems, itemsArg);
return obsItems;
};
var obsItems = {};
return obs;
}
SmartenvObjectStorage.init = init;

View File

@ -1,13 +1,15 @@
{
"name": "smartenv",
"version": "0.0.10",
"version": "0.0.15",
"description": "store things about your environment and let them travel across modules",
"main": "index.js",
"scripts": {
"test": "(cd ts/compile && node compile.js) && (node test.js)",
"testbrowser": "(npm test) && (node testbrowser.js)",
"reinstall": "(rm -r node_modules && npm install)",
"release": "(git pull origin master && npm version patch && git push origin master && git checkout release && git merge master && git push origin release && git checkout master)",
"startdev": "(git checkout master && git pull origin master && npm install)"
"update": "(git checkout master && git pull origin master && npm install)",
"upgrade": "(npm run update) && (ncu upgradeAll && npm install)"
},
"repository": {
"type": "git",
@ -23,11 +25,13 @@
},
"homepage": "https://github.com/pushrocks/smartenv",
"dependencies": {
"beautylog": "^1.0.4",
"beautylog": "^1.0.7",
"lodash": "^3.10.1"
},
"devDependencies": {
"easyserve": "0.0.4",
"gulp": "^3.9.0",
"gulp-typescript": "^2.9.2"
"gulp-browser": "0.0.18",
"gulp-typescript": "^2.10.0"
}
}

17
test.js
View File

@ -4,11 +4,18 @@ var beautylog = require("beautylog")("os");
beautylog.info("Now testing the smartenv module");
smartenv.printEnv();
beautylog.info("Now testing the smartenv module");
smartenv.obs.add({ key1: "Peter" }, "docit");
//test smartenv.obs.add
smartenv.obs.add("myTestObject", { key1: "Peter" });
smartenv.obs.add("myTestObject", { key1: "Klaus" }); //now trying to add a second
smartenv.printEnv();
beautylog.log(smartenv.obs.get("docit").key1);
beautylog.log(smartenv.obs.get("docit").key1);
beautylog.log(smartenv.obs.get("myTestObject").key1); // this should be Peter
//test smartenv.obs.replace
smartenv.obs.replace("myTestObject", { key1: "Klaus" });
beautylog.log(smartenv.obs.get("myTestObject").key1); // this should be Klaus
//test smartenv.obs.merge
smartenv.obs.merge("myTestObject", { key2: "Peter" });
beautylog.log(smartenv.obs.get("myTestObject").key1 + smartenv.obs.get("myTestObject").key2); // this should be KlausPeter
var key2 = "hello";
smartenv.obs.get("docit").key2 = key2;
beautylog.log(smartenv.obs.get("docit").key2);
smartenv.obs.get("myTestObject").key2 = key2;
beautylog.log(smartenv.obs.get("myTestObject").key2);
beautylog.success("Success!");

6
test/browser/index.html Normal file
View File

@ -0,0 +1,6 @@
<head>
<script async src="browserified/index.js"></script>
</head>
<body>
</body>

2
test/browser/index.js Normal file
View File

@ -0,0 +1,2 @@
var smartenv = require("./index.js");
smartenv.printEnv();

18
testbrowser.js Normal file
View File

@ -0,0 +1,18 @@
/// <reference path="typings/tsd.d.ts" />
var plugins = {
beautylog: require("beautylog")("os"),
gulp: require("gulp"),
gulpBrowser: require("gulp-browser"),
easyserve: require("easyserve")
};
plugins.gulp.task('compileBrowserJS', function () {
var stream = plugins.gulp.src('test/browser/index.js')
.pipe(plugins.gulpBrowser.browserify())
.pipe(plugins.gulp.dest("test/browser/browserified/"));
return stream;
});
plugins.gulp.task('default', ['compileBrowserJS'], function () {
plugins.beautylog.success('browserJS has been browserified');
plugins.easyserve("test/browser/");
});
plugins.gulp.start.apply(plugins.gulp, ['default']);

View File

@ -21,7 +21,16 @@ gulp.task('compileTestTS', function() {
return stream;
});
gulp.task('default',['compileTS','compileTestTS'], function() {
gulp.task('compileTestBrowserTS', function() {
var stream = gulp.src('../testbrowser.ts')
.pipe(gulpTypescript({
out: "testbrowser.js"
}))
.pipe(gulp.dest("../../"));
return stream;
});
gulp.task('default',['compileTS','compileTestTS','compileTestBrowserTS'], function() {
bl.success('Typescript compiled');
});

View File

@ -5,16 +5,16 @@ class Environment {
public nodeVersion:string;
public isBrowser:boolean;
public isNode:boolean;
constructor(runtimeEnvArg,userAgentArg = "undefined") {
constructor(runtimeEnvArg:string,userAgentArg:string = "undefined") {
this.runtimeEnv = runtimeEnvArg;
this.userAgent = userAgentArg;
if(runtimeEnvArg == "node"){
this.isBrowser = false;
this.isNode = true;
this.nodeVersion = process.version;
} else {
} else if (runtimeEnvArg == "browser") {
this.isBrowser = true;
this.isNode = true;
this.isNode = false;
this.nodeVersion = "undefined";
}
};

View File

@ -16,14 +16,15 @@ module SmartenvEnvironment {
(function() {
var localRunTimeEnv = "undefined";
var localUserAgent = "undefined";
if (typeof window !== 'undefined') {
if (typeof window !== "undefined") {
localRunTimeEnv = 'browser';
localUserAgent = navigator.userAgent;
} else if (typeof process !== 'undefined') {
} else if (typeof process !== "undefined") {
localRunTimeEnv = 'node';
}
environment = new Environment(localRunTimeEnv,localUserAgent);
})();
envDetermined = true; // ensure code above only runs once
};
return environment;
};
@ -33,10 +34,12 @@ module SmartenvEnvironment {
*/
var printEnv = function() {
if (this.getEnv().isNode) {
plugins.beautylog.ok("running on NODE");
var smartenvVersion = require("./package.json").version;
plugins.beautylog.log("node version is " + this.getEnv().nodeVersion + " and smartenv version is " + smartenvVersion);
} else {
plugins.beautylog.log("browser is " + this.getEnv().userAgent)
plugins.beautylog.ok("running on BROWSER");
plugins.beautylog.log("browser is " + this.getEnv().userAgent);
}
plugins.beautylog.log("the smartenv registration store currently holds the following properties:");
console.log(Object.getOwnPropertyNames(smartenv.obs.getAll()));

View File

@ -1,26 +1,44 @@
/// <reference path="index.ts" />
module SmartenvObjectStorage {
export function init() {
var obs:any = {};
var obsItems:any = {};
obs.add = function(objectArg,paramName = "undefined") {
if (paramName == "undefined"){
plugins.beautylog.error("paramName is undefined");
return;
var obs:any = {
add: function(paramNameArg = "undefined",objectArg = "undefined") {
if (paramNameArg == "undefined"){
plugins.beautylog.error("paramName is undefined");
return;
}
if (objectArg == "undefined"){
plugins.beautylog.error("objectArg is undefined");
}
if (typeof obsItems[paramNameArg] === "undefined"){
obsItems[paramNameArg] = objectArg;
} else {
plugins.beautylog.error("object is already present, so add operation has failed.");
}
return obsItems[paramNameArg];
},
replace: function(paramNameArg,objectArg){
obsItems[paramNameArg] = objectArg;
},
merge: function(paramNameArg,objectArg){
if(!(typeof obsItems[paramNameArg] === "undefined")){
obsItems[paramNameArg] = plugins._.assign(obsItems[paramNameArg],objectArg);
} else {
plugins.beautylog.error("object is not present, so there is nothing to merge");
}
},
get: function(keyName) {
return obsItems[keyName];
},
getAll: function () {
return obsItems;
},
addComplete: function(itemsArg) {
obsItems = plugins._.assign(obsItems,itemsArg);
return obsItems;
}
obsItems[paramName] = objectArg;
};
obs.get = function(keyName) {
return obsItems[keyName];
};
obs.getAll = function () {
return obsItems;
}
obs.addComplete = function(itemsArg) {
obsItems = plugins._.assign(obsItems,itemsArg);
return obsItems;
};
var obsItems:any = {};
return obs;
}
}

View File

@ -4,12 +4,19 @@ var beautylog = require("beautylog")("os");
beautylog.info("Now testing the smartenv module");
smartenv.printEnv();
beautylog.info("Now testing the smartenv module");
smartenv.obs.add({ key1: "Peter" }, "docit");
//test smartenv.obs.add
smartenv.obs.add("myTestObject", { key1: "Peter" });
smartenv.obs.add("myTestObject", { key1: "Klaus" }); //now trying to add a second
smartenv.printEnv();
beautylog.log(smartenv.obs.get("docit").key1);
beautylog.log(smartenv.obs.get("docit").key1);
beautylog.log(smartenv.obs.get("myTestObject").key1); // this should be Peter
//test smartenv.obs.replace
smartenv.obs.replace("myTestObject", { key1: "Klaus" });
beautylog.log(smartenv.obs.get("myTestObject").key1); // this should be Klaus
//test smartenv.obs.merge
smartenv.obs.merge("myTestObject", { key2: "Peter" });
beautylog.log(smartenv.obs.get("myTestObject").key1 + smartenv.obs.get("myTestObject").key2); // this should be KlausPeter
var key2 = "hello";
smartenv.obs.get("docit").key2 = key2;
beautylog.log(smartenv.obs.get("docit").key2);
smartenv.obs.get("myTestObject").key2 = key2;
beautylog.log(smartenv.obs.get("myTestObject").key2);
beautylog.success("Success!");
//# sourceMappingURL=test.js.map

View File

@ -1 +1 @@
{"version":3,"file":"test.js","sourceRoot":"","sources":["test.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,IAAI,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AACrC,IAAI,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC;AAC3C,SAAS,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;AAClD,QAAQ,CAAC,QAAQ,EAAE,CAAC;AACpB,SAAS,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;AAClD,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAC,IAAI,EAAC,OAAO,EAAC,EAAC,OAAO,CAAC,CAAC;AACzC,QAAQ,CAAC,QAAQ,EAAE,CAAC;AACpB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG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,IAAI,EAAC,OAAO,EAAC,CAAC,CAAC;AACpD,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,uBAAuB;AAE7E,yBAAyB;AACzB,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,cAAc,EAAC,EAAC,IAAI,EAAC,OAAO,EAAC,CAAC,CAAC;AAClD,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,4BAA4B;AAE1H,IAAI,IAAI,GAAG,OAAO,CAAC;AACnB,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC;AAC7C,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,CAAC;AAErD,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC"}

View File

@ -4,13 +4,23 @@ var beautylog = require("beautylog")("os");
beautylog.info("Now testing the smartenv module");
smartenv.printEnv();
beautylog.info("Now testing the smartenv module");
smartenv.obs.add({key1:"Peter"},"docit");
//test smartenv.obs.add
smartenv.obs.add("myTestObject",{key1:"Peter"});
smartenv.obs.add("myTestObject",{key1:"Klaus"}); //now trying to add a second
smartenv.printEnv();
beautylog.log(smartenv.obs.get("docit").key1);
beautylog.log(smartenv.obs.get("docit").key1);
beautylog.log(smartenv.obs.get("myTestObject").key1); // this should be Peter
//test smartenv.obs.replace
smartenv.obs.replace("myTestObject",{key1:"Klaus"});
beautylog.log(smartenv.obs.get("myTestObject").key1); // this should be Klaus
//test smartenv.obs.merge
smartenv.obs.merge("myTestObject",{key2:"Peter"});
beautylog.log(smartenv.obs.get("myTestObject").key1 + smartenv.obs.get("myTestObject").key2); // this should be KlausPeter
var key2 = "hello";
smartenv.obs.get("docit").key2 = key2;
beautylog.log(smartenv.obs.get("docit").key2);
smartenv.obs.get("myTestObject").key2 = key2;
beautylog.log(smartenv.obs.get("myTestObject").key2);
beautylog.success("Success!");

21
ts/testbrowser.ts Normal file
View File

@ -0,0 +1,21 @@
/// <reference path="typings/tsd.d.ts" />
var plugins = {
beautylog: require("beautylog")("os"),
gulp: require("gulp"),
gulpBrowser: require("gulp-browser"),
easyserve: require("easyserve")
};
plugins.gulp.task('compileBrowserJS', function() {
var stream = plugins.gulp.src('test/browser/index.js')
.pipe(plugins.gulpBrowser.browserify())
.pipe(plugins.gulp.dest("test/browser/browserified/"));
return stream;
});
plugins.gulp.task('default',['compileBrowserJS'], function() {
plugins.beautylog.success('browserJS has been browserified');
plugins.easyserve("test/browser/");
});
plugins.gulp.start.apply(plugins.gulp, ['default']);