node vs browser env check is now working
This commit is contained in:
parent
acc0e5221b
commit
101e7a86cd
11
index.js
11
index.js
@ -9,9 +9,9 @@ var Environment = (function () {
|
|||||||
this.isNode = true;
|
this.isNode = true;
|
||||||
this.nodeVersion = process.version;
|
this.nodeVersion = process.version;
|
||||||
}
|
}
|
||||||
else {
|
else if (runtimeEnvArg == "browser") {
|
||||||
this.isBrowser = true;
|
this.isBrowser = true;
|
||||||
this.isNode = true;
|
this.isNode = false;
|
||||||
this.nodeVersion = "undefined";
|
this.nodeVersion = "undefined";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,15 +35,16 @@ var SmartenvEnvironment;
|
|||||||
(function () {
|
(function () {
|
||||||
var localRunTimeEnv = "undefined";
|
var localRunTimeEnv = "undefined";
|
||||||
var localUserAgent = "undefined";
|
var localUserAgent = "undefined";
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== "undefined") {
|
||||||
localRunTimeEnv = 'browser';
|
localRunTimeEnv = 'browser';
|
||||||
localUserAgent = navigator.userAgent;
|
localUserAgent = navigator.userAgent;
|
||||||
}
|
}
|
||||||
else if (typeof process !== 'undefined') {
|
else if (typeof process !== "undefined") {
|
||||||
localRunTimeEnv = 'node';
|
localRunTimeEnv = 'node';
|
||||||
}
|
}
|
||||||
environment = new Environment(localRunTimeEnv, localUserAgent);
|
environment = new Environment(localRunTimeEnv, localUserAgent);
|
||||||
})();
|
})();
|
||||||
|
envDetermined = true; // ensure code above only runs once
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
return environment;
|
return environment;
|
||||||
@ -53,10 +54,12 @@ var SmartenvEnvironment;
|
|||||||
*/
|
*/
|
||||||
var printEnv = function () {
|
var printEnv = function () {
|
||||||
if (this.getEnv().isNode) {
|
if (this.getEnv().isNode) {
|
||||||
|
plugins.beautylog.ok("running on NODE");
|
||||||
var smartenvVersion = require("./package.json").version;
|
var smartenvVersion = require("./package.json").version;
|
||||||
plugins.beautylog.log("node version is " + this.getEnv().nodeVersion + " and smartenv version is " + smartenvVersion);
|
plugins.beautylog.log("node version is " + this.getEnv().nodeVersion + " and smartenv version is " + smartenvVersion);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
plugins.beautylog.ok("running on BROWSER");
|
||||||
plugins.beautylog.log("browser is " + this.getEnv().userAgent);
|
plugins.beautylog.log("browser is " + this.getEnv().userAgent);
|
||||||
}
|
}
|
||||||
plugins.beautylog.log("the smartenv registration store currently holds the following properties:");
|
plugins.beautylog.log("the smartenv registration store currently holds the following properties:");
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(cd ts/compile && node compile.js) && (node test.js)",
|
"test": "(cd ts/compile && node compile.js) && (node test.js)",
|
||||||
|
"testbrowser": "(npm test) && (node testbrowser.js)",
|
||||||
"reinstall": "(rm -r node_modules && npm install)",
|
"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)",
|
"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)",
|
||||||
"update": "(git checkout master && git pull origin master && npm install)",
|
"update": "(git checkout master && git pull origin master && npm install)",
|
||||||
@ -24,11 +25,13 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/pushrocks/smartenv",
|
"homepage": "https://github.com/pushrocks/smartenv",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"beautylog": "^1.0.6",
|
"beautylog": "^1.0.7",
|
||||||
"lodash": "^3.10.1"
|
"lodash": "^3.10.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"easyserve": "0.0.4",
|
||||||
"gulp": "^3.9.0",
|
"gulp": "^3.9.0",
|
||||||
|
"gulp-browser": "0.0.18",
|
||||||
"gulp-typescript": "^2.10.0"
|
"gulp-typescript": "^2.10.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
24871
test/browser/browserified/index.js
Normal file
24871
test/browser/browserified/index.js
Normal file
File diff suppressed because it is too large
Load Diff
6
test/browser/index.html
Normal file
6
test/browser/index.html
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<head>
|
||||||
|
<script async src="browserified/index.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
</body>
|
2
test/browser/index.js
Normal file
2
test/browser/index.js
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
var smartenv = require("./index.js");
|
||||||
|
smartenv.printEnv();
|
18
testbrowser.js
Normal file
18
testbrowser.js
Normal 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']);
|
@ -21,7 +21,16 @@ gulp.task('compileTestTS', function() {
|
|||||||
return stream;
|
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');
|
bl.success('Typescript compiled');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -5,16 +5,16 @@ class Environment {
|
|||||||
public nodeVersion:string;
|
public nodeVersion:string;
|
||||||
public isBrowser:boolean;
|
public isBrowser:boolean;
|
||||||
public isNode:boolean;
|
public isNode:boolean;
|
||||||
constructor(runtimeEnvArg,userAgentArg = "undefined") {
|
constructor(runtimeEnvArg:string,userAgentArg:string = "undefined") {
|
||||||
this.runtimeEnv = runtimeEnvArg;
|
this.runtimeEnv = runtimeEnvArg;
|
||||||
this.userAgent = userAgentArg;
|
this.userAgent = userAgentArg;
|
||||||
if(runtimeEnvArg == "node"){
|
if(runtimeEnvArg == "node"){
|
||||||
this.isBrowser = false;
|
this.isBrowser = false;
|
||||||
this.isNode = true;
|
this.isNode = true;
|
||||||
this.nodeVersion = process.version;
|
this.nodeVersion = process.version;
|
||||||
} else {
|
} else if (runtimeEnvArg == "browser") {
|
||||||
this.isBrowser = true;
|
this.isBrowser = true;
|
||||||
this.isNode = true;
|
this.isNode = false;
|
||||||
this.nodeVersion = "undefined";
|
this.nodeVersion = "undefined";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -16,14 +16,15 @@ module SmartenvEnvironment {
|
|||||||
(function() {
|
(function() {
|
||||||
var localRunTimeEnv = "undefined";
|
var localRunTimeEnv = "undefined";
|
||||||
var localUserAgent = "undefined";
|
var localUserAgent = "undefined";
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== "undefined") {
|
||||||
localRunTimeEnv = 'browser';
|
localRunTimeEnv = 'browser';
|
||||||
localUserAgent = navigator.userAgent;
|
localUserAgent = navigator.userAgent;
|
||||||
} else if (typeof process !== 'undefined') {
|
} else if (typeof process !== "undefined") {
|
||||||
localRunTimeEnv = 'node';
|
localRunTimeEnv = 'node';
|
||||||
}
|
}
|
||||||
environment = new Environment(localRunTimeEnv,localUserAgent);
|
environment = new Environment(localRunTimeEnv,localUserAgent);
|
||||||
})();
|
})();
|
||||||
|
envDetermined = true; // ensure code above only runs once
|
||||||
};
|
};
|
||||||
return environment;
|
return environment;
|
||||||
};
|
};
|
||||||
@ -33,10 +34,12 @@ module SmartenvEnvironment {
|
|||||||
*/
|
*/
|
||||||
var printEnv = function() {
|
var printEnv = function() {
|
||||||
if (this.getEnv().isNode) {
|
if (this.getEnv().isNode) {
|
||||||
|
plugins.beautylog.ok("running on NODE");
|
||||||
var smartenvVersion = require("./package.json").version;
|
var smartenvVersion = require("./package.json").version;
|
||||||
plugins.beautylog.log("node version is " + this.getEnv().nodeVersion + " and smartenv version is " + smartenvVersion);
|
plugins.beautylog.log("node version is " + this.getEnv().nodeVersion + " and smartenv version is " + smartenvVersion);
|
||||||
} else {
|
} 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:");
|
plugins.beautylog.log("the smartenv registration store currently holds the following properties:");
|
||||||
console.log(Object.getOwnPropertyNames(smartenv.obs.getAll()));
|
console.log(Object.getOwnPropertyNames(smartenv.obs.getAll()));
|
||||||
|
21
ts/testbrowser.ts
Normal file
21
ts/testbrowser.ts
Normal 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']);
|
Loading…
x
Reference in New Issue
Block a user