update to commonjs module structure
This commit is contained in:
@ -1,37 +0,0 @@
|
||||
// import gulp
|
||||
var gulp = require("gulp");
|
||||
var gulpTypescript = require("gulp-typescript");
|
||||
var bl = require("beautylog")("os");
|
||||
|
||||
gulp.task('compileTS', function() {
|
||||
var stream = gulp.src('../index.ts')
|
||||
.pipe(gulpTypescript({
|
||||
out: "index.js"
|
||||
}))
|
||||
.pipe(gulp.dest("../../"));
|
||||
return stream;
|
||||
});
|
||||
|
||||
gulp.task('compileTestTS', function() {
|
||||
var stream = gulp.src('../test.ts')
|
||||
.pipe(gulpTypescript({
|
||||
out: "test.js"
|
||||
}))
|
||||
.pipe(gulp.dest("../../"));
|
||||
return stream;
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
|
||||
gulp.start.apply(gulp, ['default']);
|
@ -1,2 +0,0 @@
|
||||
# How to compile.
|
||||
Make sure gulp and gulp-taypescript from npm are available. Then run the gulpfile in this directory.
|
20
ts/index.ts
20
ts/index.ts
@ -1,16 +1,10 @@
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
/// <reference path="smartenv.classes.ts" />
|
||||
/// <reference path="smartenv.environment.ts" />
|
||||
/// <reference path="smartenv.objectstorage.ts" />
|
||||
var plugins = {
|
||||
beautylog: require("beautylog")("os"),
|
||||
_: require("lodash")
|
||||
}
|
||||
/// <reference path="typings/main.d.ts" />
|
||||
|
||||
import SmartenvEnvironment = require("./smartenv.environment");
|
||||
import SmartenvObjectStorage = require("./smartenv.objectstorage");
|
||||
|
||||
var smartenv:any = {}; //create smartenv object
|
||||
|
||||
SmartenvEnvironment.init(smartenv);
|
||||
smartenv.obs = SmartenvObjectStorage.init();
|
||||
smartenv.obs = SmartenvObjectStorage.obs;
|
||||
|
||||
|
||||
|
||||
module.exports = smartenv;
|
||||
export = smartenv;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/// <reference path="index.ts" />
|
||||
class Environment {
|
||||
/// <reference path="typings/main.d.ts" />
|
||||
export class Environment {
|
||||
public runtimeEnv:string;
|
||||
public userAgent:string;
|
||||
public nodeVersion:string;
|
||||
|
@ -1,52 +1,54 @@
|
||||
/// <reference path="index.ts" />
|
||||
/// <reference path="typings/main.d.ts" />
|
||||
/**
|
||||
* Deals with the environment the current JS script is running in.
|
||||
*/
|
||||
module SmartenvEnvironment {
|
||||
import plugins = require("./smartenv.plugins");
|
||||
import SmartenvClasses = require("./smartenv.classes");
|
||||
import SmartenvObjectStorage = require("./smartenv.objectstorage");
|
||||
|
||||
var environment:Environment;
|
||||
var envDetermined:boolean = false;
|
||||
|
||||
/**
|
||||
* returns the environment
|
||||
* @returns {Environment}
|
||||
*/
|
||||
var getEnv = function(){
|
||||
if (!envDetermined) {
|
||||
(function() {
|
||||
var localRunTimeEnv = "undefined";
|
||||
var localUserAgent = "undefined";
|
||||
if (typeof window !== "undefined") {
|
||||
localRunTimeEnv = 'browser';
|
||||
localUserAgent = navigator.userAgent;
|
||||
} else if (typeof process !== "undefined") {
|
||||
localRunTimeEnv = 'node';
|
||||
}
|
||||
environment = new Environment(localRunTimeEnv,localUserAgent);
|
||||
})();
|
||||
envDetermined = true; // ensure code above only runs once
|
||||
};
|
||||
return environment;
|
||||
var environment:SmartenvClasses.Environment;
|
||||
var envDetermined:boolean = false;
|
||||
|
||||
/**
|
||||
* returns the environment
|
||||
* @returns {Environment}
|
||||
*/
|
||||
var getEnv = function(){
|
||||
if (!envDetermined) {
|
||||
(function() {
|
||||
var localRunTimeEnv = "undefined";
|
||||
var localUserAgent = "undefined";
|
||||
if (typeof window !== "undefined") {
|
||||
localRunTimeEnv = 'browser';
|
||||
localUserAgent = navigator.userAgent;
|
||||
} else if (typeof process !== "undefined") {
|
||||
localRunTimeEnv = 'node';
|
||||
}
|
||||
environment = new SmartenvClasses.Environment(localRunTimeEnv,localUserAgent);
|
||||
})();
|
||||
envDetermined = true; // ensure code above only runs once
|
||||
};
|
||||
return environment;
|
||||
};
|
||||
|
||||
/**
|
||||
* prints the environment to console
|
||||
*/
|
||||
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:");
|
||||
console.log(Object.getOwnPropertyNames(smartenv.obs.getAll()));
|
||||
/**
|
||||
* prints the environment to console
|
||||
*/
|
||||
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:");
|
||||
console.log(Object.getOwnPropertyNames(SmartenvObjectStorage.obs.getAll()));
|
||||
};
|
||||
|
||||
export var init = function(objectArg) {
|
||||
objectArg.getEnv = getEnv;
|
||||
objectArg.printEnv = printEnv;
|
||||
}
|
||||
}
|
||||
export var init = function(objectArg) {
|
||||
objectArg.getEnv = getEnv;
|
||||
objectArg.printEnv = printEnv;
|
||||
};
|
@ -1,44 +1,41 @@
|
||||
/// <reference path="index.ts" />
|
||||
module SmartenvObjectStorage {
|
||||
export function init() {
|
||||
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;
|
||||
}
|
||||
};
|
||||
var obsItems:any = {};
|
||||
return obs;
|
||||
/// <reference path="typings/main.d.ts" />
|
||||
import plugins = require("./smartenv.plugins");
|
||||
|
||||
export 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;
|
||||
}
|
||||
}
|
||||
};
|
||||
export var obsItems:any = {};
|
3
ts/smartenv.plugins.ts
Normal file
3
ts/smartenv.plugins.ts
Normal file
@ -0,0 +1,3 @@
|
||||
/// <reference path="typings/main.d.ts" />
|
||||
export var beautylog = require("beautylog");
|
||||
export var _ = require("lodash");
|
26
ts/test.ts
26
ts/test.ts
@ -1,26 +0,0 @@
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
var smartenv = require("./index.js");
|
||||
var beautylog = require("beautylog")("os");
|
||||
beautylog.info("Now testing the smartenv module");
|
||||
smartenv.printEnv();
|
||||
beautylog.info("Now testing the smartenv module");
|
||||
|
||||
//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("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("myTestObject").key2 = key2;
|
||||
beautylog.log(smartenv.obs.get("myTestObject").key2);
|
||||
|
||||
beautylog.success("Success!");
|
@ -1,21 +0,0 @@
|
||||
/// <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']);
|
12
ts/tsd.json
12
ts/tsd.json
@ -1,12 +0,0 @@
|
||||
{
|
||||
"version": "v4",
|
||||
"repo": "borisyankov/DefinitelyTyped",
|
||||
"ref": "master",
|
||||
"path": "typings",
|
||||
"bundle": "typings/tsd.d.ts",
|
||||
"installed": {
|
||||
"node/node.d.ts": {
|
||||
"commit": "efa0c1196d7280640e624ac1e7fa604502e7bd63"
|
||||
}
|
||||
}
|
||||
}
|
5
ts/typings.json
Normal file
5
ts/typings.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"ambientDependencies": {
|
||||
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts"
|
||||
}
|
||||
}
|
1
ts/typings/browser.d.ts
vendored
Normal file
1
ts/typings/browser.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
/// <reference path="browser/ambient/node/node.d.ts" />
|
2196
ts/typings/browser/ambient/node/node.d.ts
vendored
Normal file
2196
ts/typings/browser/ambient/node/node.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
ts/typings/main.d.ts
vendored
Normal file
1
ts/typings/main.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
/// <reference path="main/ambient/node/node.d.ts" />
|
2196
ts/typings/main/ambient/node/node.d.ts
vendored
Normal file
2196
ts/typings/main/ambient/node/node.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user