@videinfra/static-website-builder 2.3.2 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ ## [2.4.1] - 2026-04-23
8
+ ### Added
9
+ - Allow to specify additional static data for env variables in task config
10
+
11
+ ## [2.4.0] - 2026-04-23
12
+ ### Added
13
+ - Allow to specify builder config file path using `BUILDER_CONFIG_FILE` env variable
14
+
7
15
  ## [2.3.2] - 2026-04-13
8
16
  ### Fixed
9
17
  - Translation error output
package/gulpfile.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import { getConfigAsync } from './lib/get-config.js';
2
2
  import generateGulpTasks from './lib/generate-gulp-tasks.js';
3
+ import { getProjectPath } from './lib/get-path.js';
4
+ import dotenv from 'dotenv';
3
5
 
4
6
  // Set mode globally it can be used by tasks
5
7
  let hasProductionArg = false;
@@ -15,9 +17,27 @@ for (let i = 0; i < process.argv.length; i++) {
15
17
  global.production = global.production || hasProductionArg || process.env.NODE_ENV === 'production';
16
18
  global.development = !global.production;
17
19
 
18
- // Config file
19
- let builderConfigFile = process.env.BUILDER_CONFIG_FILE || 'config/config.js';
20
+ // Load environment variables from .env files
21
+ let builderConfigFile = 'config/config.js';
22
+
23
+ if (process.env.BUILDER_CONFIG_FILE) {
24
+ builderConfigFile = process.env.BUILDER_CONFIG_FILE;
25
+ } else {
26
+ const envVariables = {};
27
+ dotenv.config({
28
+ // dotenv file order is reversed, values in first file overwrite all other
29
+ // file values
30
+ path: ['../.env', '../.env.local'].map((path) => getProjectPath(path)).reverse(),
31
+ processEnv: envVariables,
32
+ quiet: true,
33
+ });
34
+
35
+ if (envVariables.BUILDER_CONFIG_FILE) {
36
+ builderConfigFile = envVariables.BUILDER_CONFIG_FILE;
37
+ }
38
+ }
20
39
 
40
+ // Config file
21
41
  if (process.argv.indexOf('--config') !== -1) {
22
42
  builderConfigFile = process.argv[process.argv.indexOf('--config') + 1];
23
43
  } else {
@@ -67,6 +67,11 @@ export const env = {
67
67
  'TYPE_EMPTY': 'typeEmpty',
68
68
  'NON_EXISTING': 'nonExisting',
69
69
  },
70
+
71
+ // Additional env variables
72
+ data: {
73
+ 'baz': 'bazValue',
74
+ },
70
75
  };
71
76
 
72
77
  export const translations = {
@@ -3,6 +3,7 @@ console.log('Hello from main page!');
3
3
  console.log('env.host ==', process.env.host);
4
4
  console.log('env.foo ==', process.env.foo);
5
5
  console.log('env.bar ==', process.env.bar);
6
+ console.log('env.baz ==', process.env.baz);
6
7
  console.log('env.typeBoolTrue ==', process.env.typeBoolTrue);
7
8
  console.log('env.typeBoolFalse ==', process.env.typeBoolFalse);
8
9
  console.log('env.typeNumber ==', process.env.typeNumber);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@videinfra/static-website-builder",
3
- "version": "2.3.2",
3
+ "version": "2.4.1",
4
4
  "description": "Customizable static site project builder",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -14,7 +14,10 @@ export const env = {
14
14
  // How env variable names should be remapped
15
15
  // Example:
16
16
  // map: { 'HOST': 'host', 'RECAPTCHA3_PUBLIC_KEY': 'recaptcha3_site_key' }
17
- map: {}
17
+ map: {},
18
+
19
+ // Additional data to add to env variables
20
+ data: {},
18
21
  };
19
22
 
20
23
  export const paths = {
@@ -88,16 +88,26 @@ const getEnvData = nanomemoize.nanomemoize(function () {
88
88
  const envOutVariables = {};
89
89
 
90
90
  // Remap property names
91
- const map = getTaskConfig('env', 'map');
91
+ const map = getTaskConfig('env', 'map') || {};
92
92
 
93
93
  Object.keys(map).forEach((key) => {
94
94
  const value = key in envVariables ? envVariables[key] : '';
95
- const camelCase = map[key];
96
- const kebabCase = map[key];
97
- twigVariables[camelCase] = normalizeTwigVariable(value);
98
- envOutVariables[camelCase] = value;
99
- jsVariables[`process.env.${camelCase}`] = escapeJSVariable(value);
100
- scssVariables.env[kebabCase] = value;
95
+ const mappedKey = map[key];
96
+ twigVariables[mappedKey] = normalizeTwigVariable(value);
97
+ envOutVariables[mappedKey] = value;
98
+ jsVariables[`process.env.${mappedKey}`] = escapeJSVariable(value);
99
+ scssVariables.env[mappedKey] = value;
100
+ });
101
+
102
+ // Add additional data
103
+ const data = getTaskConfig('env', 'data') || {};
104
+
105
+ Object.keys(data).forEach((key) => {
106
+ const value = data[key];
107
+ twigVariables[key] = normalizeTwigVariable(value);
108
+ envOutVariables[key] = value;
109
+ jsVariables[`process.env.${key}`] = escapeJSVariable(value);
110
+ scssVariables.env[key] = value;
101
111
  });
102
112
 
103
113
  return {
@@ -34,6 +34,14 @@ test('.env and .env.local files loaded', () => {
34
34
  ]);
35
35
  });
36
36
 
37
+ test('Additional ENV data is set', () => {
38
+ return Promise.all([
39
+ fsPromises.readFile(path.resolve(publicPath, 'assets/javascripts/main.js'), { encoding: 'utf8' }).then((js) => {
40
+ expect(js.indexOf('console.log(`env.baz ==`,`bazValue`)')).not.toBe(-1);
41
+ }),
42
+ ]);
43
+ });
44
+
37
45
  test('process.env available in html/data', () => {
38
46
  return fsPromises.readFile(path.resolve(publicPath, 'env.html'), { encoding: 'utf8' }).then((html) => {
39
47
  expect(html.indexOf('<p>HOST FROM GLOBAL JS: https://test-local.tld</p>')).not.toBe(-1);