Skip to content

Commit

Permalink
✨ Add support for the Protoblast environment properties
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Apr 26, 2024
1 parent b3633c1 commit 32420f9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Add `OperationalContext` class for keeping track of complex operations
* Use new `OperationalContext`-based classes for handling `Datasource` operations, getting rid of callbacks
* Use `OperationalContext.Schema` for resolving subschemas
* Add support for the Protoblast environment properties

## 1.4.0-alpha.3 (2024-02-25)

Expand Down
13 changes: 10 additions & 3 deletions lib/core/alchemy.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,11 +676,11 @@ Alchemy.setMethod(function loadSettings() {
this.setSetting('no_local_file', local_path);
}

// Default to the 'dev' environment
// Default to the environment Protoblast has found
if (!local.environment) {

if (process.env.ENV) {
local.environment = process.env.ENV;
local.environment = Blast.environment;
} else {
local.environment = 'dev';
}
Expand All @@ -693,6 +693,12 @@ Alchemy.setMethod(function loadSettings() {
this.printLog(this.INFO, ['Switching to environment', env]);
}

if (local.environment === 'development') {
local.environment = 'dev';
}

Blast.environment = local.environment;

// Generate the path to the environment settings file
let env_path = libpath.resolve(PATH_APP, 'config', local.environment, 'config');

Expand Down Expand Up @@ -935,7 +941,7 @@ Alchemy.setMethod(function ready(callback) {
*
* @author Jelle De Loecker <jelle@elevenways.be>
* @since 1.1.2
* @version 1.3.22
* @version 1.4.0
*/
Alchemy.setMethod(async function doPreload() {

Expand Down Expand Up @@ -965,6 +971,7 @@ Alchemy.setMethod(async function doPreload() {
create_source_map : this.settings.debugging.create_source_map,
enable_coverage : !!global.__coverage__,
debug : this.settings.debugging.debug,
environment : this.environment,
});
}
});
Expand Down
18 changes: 16 additions & 2 deletions lib/core/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,12 @@ Alchemy.setMethod(function minifyScript(path, options, callback) {
data = data.replaceAll('Blast.isNode', '__BLAST_IS_NODE');
data = data.replaceAll('Blast.isBrowser', '__BLAST_IS_BROWSER');

let env_info = Blast.parseEnvironmentName(alchemy.environment);
data = data.replaceAll('Blast.environment', '__BLAST_IS_ENVIRONMENT');
data = data.replaceAll('Blast.isProduction', '__BLAST_IS_PRODUCTION');
data = data.replaceAll('Blast.isDevelopment', '__BLAST_IS_DEVELOPMENT');
data = data.replaceAll('Blast.isStaging', '__BLAST_IS_STAGING');

let minify_options = {
compress: {
// Keep all function arguments
Expand Down Expand Up @@ -521,7 +527,11 @@ Alchemy.setMethod(function minifyScript(path, options, callback) {
global_defs : {
'__BLAST_IS_NODE' : false,
'__BLAST_IS_SERVER' : false,
'__BLAST_IS_BROWSER' : true
'__BLAST_IS_BROWSER' : true,
'__BLAST_IS_ENVIRONMENT' : alchemy.environment,
'__BLAST_IS_PRODUCTION' : env_info.is_production,
'__BLAST_IS_DEVELOPMENT' : env_info.is_development,
'__BLAST_IS_STAGING' : env_info.is_staging,
}
},
mangle: {
Expand Down Expand Up @@ -559,8 +569,12 @@ Alchemy.setMethod(function minifyScript(path, options, callback) {
// Restore some instances in case these weren't removed by Terser
// (Maybe because they're part of another variable or a string)
result = result.code.replaceAll('__BLAST_IS_SERVER', 'Blast.isServer');
result = result.code.replaceAll('__BLAST_IS_NODE', 'Blast.isNode');
result = result.replaceAll('__BLAST_IS_NODE', 'Blast.isNode');
result = result.replaceAll('__BLAST_IS_BROWSER', 'Blast.isBrowser');
result = result.replaceAll('__BLAST_IS_ENVIRONMENT', 'Blast.environment');
result = result.replaceAll('__BLAST_IS_PRODUCTION', 'Blast.isProduction');
result = result.replaceAll('__BLAST_IS_DEVELOPMENT', 'Blast.isDevelopment');
result = result.replaceAll('__BLAST_IS_STAGING', 'Blast.isStaging');
} else {
result = result.code;
}
Expand Down

0 comments on commit 32420f9

Please sign in to comment.