-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add
Blast.environment
string property and isProduction
, `isDeve…
…lopment` and `isStaging` booleans
- Loading branch information
Showing
3 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -272,14 +272,64 @@ function BlastInit(modifyPrototype) { | |
// Get the debug environment variable | ||
// This is not meant to debug protoblast | ||
if (typeof process != 'undefined') { | ||
Blast.DEBUG = !!process.env.DEBUG; | ||
const env = process.env; | ||
Blast.DEBUG = !!env.DEBUG; | ||
Blast.environment = env.APP_ENV || env.NODE_ENV || env.ENV || 'development'; | ||
} else { | ||
Blast.DEBUG = !!Blast.Globals.DEBUG; | ||
} | ||
|
||
//_PROTOBLAST_ENV_// | ||
|
||
// PROTOBLAST START CUT | ||
// Get version information of this protoblast instance | ||
if (Blast.isNode) { | ||
|
||
/** | ||
* See what kind of environment this is | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.9.3 | ||
* @version 0.9.3 | ||
* | ||
* @param {string} environment | ||
* | ||
* @return {Object} | ||
*/ | ||
Blast.parseEnvironmentName = function parseEnvironmentName(environment = '') { | ||
|
||
let result = { | ||
is_production : false, | ||
is_development : false, | ||
is_staging : false, | ||
}; | ||
|
||
switch (environment.toLowerCase()) { | ||
case 'production': | ||
case 'live': | ||
case 'prod': | ||
result.is_production = true; | ||
break; | ||
|
||
case 'development': | ||
case 'dev': | ||
result.is_development = true; | ||
break; | ||
|
||
case 'staging': | ||
case 'preview': | ||
result.is_staging = true; | ||
break; | ||
} | ||
|
||
return result; | ||
}; | ||
|
||
let env_info = Blast.parseEnvironmentName(Blast.environment); | ||
Blast.isProduction = env_info.is_production; | ||
Blast.isDevelopment = env_info.is_development; | ||
Blast.isStaging = env_info.is_staging; | ||
|
||
r_package = require(__dirname + '/../package.json'); | ||
|
||
// And the path package | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ module.exports = function serverFunctions(Blast, extras) { | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.1.1 | ||
* @version 0.8.0 | ||
* @version 0.9.3 | ||
* | ||
* @param {Object} options | ||
* | ||
|
@@ -125,6 +125,10 @@ module.exports = function serverFunctions(Blast, extras) { | |
id += '_cov'; | ||
} | ||
|
||
if (options.environment) { | ||
id += '_env_' + options.environment; | ||
} | ||
|
||
if (client_file_cache[id] && !refresh) { | ||
return client_file_cache[id]; | ||
} | ||
|
@@ -447,6 +451,21 @@ module.exports = function serverFunctions(Blast, extras) { | |
template = tokens.join(''); | ||
} | ||
|
||
// See if we need to register any env variables | ||
if (options.environment) { | ||
let index = template.indexOf('//_PROTOBLAST_ENV_//'); | ||
|
||
if (index > -1) { | ||
let env_info = Blast.parseEnvironmentName(options.environment); | ||
let env = 'Blast.environment = ' + JSON.stringify(options.environment) + ';'; | ||
env += 'Blast.isProduction = ' + (env_info.is_production ? 'true' : 'false') + ';'; | ||
env += 'Blast.isDevelopment = ' + (env_info.is_development ? 'true' : 'false') + ';'; | ||
env += 'Blast.isStaging = ' + (env_info.is_staging ? 'true' : 'false') + ';'; | ||
|
||
template = template.slice(0, index) + env + template.slice(index + 20); | ||
} | ||
} | ||
|
||
let cut_rx = /\/\/\s?PROTOBLAST\s?START\s?CUT([\s\S]*?)(\/\/\s?PROTOBLAST\s?END\s?CUT)/gm; | ||
|
||
// Remove everything between "PROTOBLAST START CUT" and "PROTOBLAST END CUT" (with slashes) | ||
|