node vs browser env check is now working

This commit is contained in:
Phil Kunz
2015-12-25 00:22:28 +01:00
parent acc0e5221b
commit 101e7a86cd
10 changed files with 24948 additions and 12 deletions

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()));

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']);