@videinfra/static-website-builder 2.0.2 → 2.0.3

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,10 @@ 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.0.3] - 2026-02-03
8
+ ### Added
9
+ - Allow writing ASSETS_VERSION to .env file
10
+
7
11
  ## [2.0.0] - 2026-01-27
8
12
  ### Added
9
13
  - Replaced webpack with rolldown
@@ -1,2 +1,3 @@
1
1
  HOST=https://test-local.tld
2
2
  BAR=bar-local
3
+ ASSETS_VERSION=12345678
@@ -41,6 +41,10 @@ export const plugins = [
41
41
  ];
42
42
 
43
43
  export const env = {
44
+ // Write ASSET_VERSION to .env file to enable cache busting
45
+ // writeAssetVersion: './init/test/.env.local',
46
+
47
+ // How env variable names should be remapped
44
48
  map: {
45
49
  'HOST': 'host',
46
50
  'FOO': 'foo',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@videinfra/static-website-builder",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "Customizable static site project builder",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -22,7 +22,7 @@
22
22
  "scripts": {
23
23
  "start": "cross-env BUILDER_MODE=development gulp watch",
24
24
  "build": "cross-env BUILDER_MODE=production gulp build",
25
- "test": "gulp build --silent --config=init/test/config/config.js && node --experimental-vm-modules node_modules/jest/bin/jest.js",
25
+ "test": "gulp build --silent --config=init/test/config/config.js && node --disable-warning=ExperimentalWarning --experimental-vm-modules node_modules/jest/bin/jest.js",
26
26
  "test-watch": "gulp watch --config=init/test/config/config.js",
27
27
  "test-builder": "node bin/builder.js build --config=init/test/config/config.js"
28
28
  },
@@ -8,6 +8,9 @@
8
8
  */
9
9
 
10
10
  export const env = {
11
+ // Write ASSET_VERSION to .env file to enable cache busting
12
+ writeAssetVersion: false,
13
+
11
14
  // How env variable names should be remapped
12
15
  // Example:
13
16
  // map: { 'HOST': 'host', 'RECAPTCHA3_PUBLIC_KEY': 'recaptcha3_site_key' }
@@ -1,3 +1,4 @@
1
+ import fs from 'node:fs';
1
2
  import dotenv from 'dotenv';
2
3
  import nanomemoize from 'nano-memoize';
3
4
  import { getPathConfig, getProjectPath } from '../../lib/get-path.js';
@@ -24,6 +25,32 @@ function normalizeTwigVariable(value) {
24
25
  }
25
26
  }
26
27
 
28
+ /**
29
+ * Write asset version to the env file
30
+ * @param {string} assetVersion Asset version string
31
+ */
32
+ function writeEnvFileAssetVersion(assetVersion) {
33
+ const envFilePath = getTaskConfig('env', 'writeAssetVersion');
34
+ if (envFilePath) {
35
+ const envFile = getProjectPath(envFilePath);
36
+
37
+ try {
38
+ let envContent = fs.readFileSync(envFile, 'utf8');
39
+
40
+ // Replace ASSETS_VERSION if it exists
41
+ if (envContent.includes('ASSETS_VERSION=')) {
42
+ envContent = envContent.replace(/ASSETS_VERSION=.*/, `ASSETS_VERSION=${assetVersion}`);
43
+ } else {
44
+ envContent += `\nASSETS_VERSION=${assetVersion}`;
45
+ }
46
+
47
+ fs.writeFileSync(envFile, envContent);
48
+ } catch (error) {
49
+ console.error(`Error writing env file "${envFile}"`, error);
50
+ }
51
+ }
52
+ }
53
+
27
54
  /**
28
55
  * Load data from the .env files
29
56
  * @returns {object} List of environment variables
@@ -41,7 +68,10 @@ export const loadEnvData = nanomemoize.nanomemoize(function () {
41
68
  });
42
69
 
43
70
  // Set assets version if it doesn't exist
44
- envVariables['ASSETS_VERSION'] = envVariables['ASSETS_VERSION'] || String(Math.floor(Date.now() / 1000));
71
+ if (!envVariables['ASSETS_VERSION'] || getTaskConfig('env', 'writeAssetVersion')) {
72
+ envVariables['ASSETS_VERSION'] = String(Math.floor(Date.now() / 1000));
73
+ writeEnvFileAssetVersion(envVariables['ASSETS_VERSION']);
74
+ }
45
75
 
46
76
  return envVariables;
47
77
  });
@@ -50,7 +80,7 @@ export const loadEnvData = nanomemoize.nanomemoize(function () {
50
80
  * Returns environment variables mapped to the specified names
51
81
  * @returns {object} Mapped environment variables
52
82
  */
53
- export default function getEnvData() {
83
+ const getEnvData = nanomemoize.nanomemoize(function () {
54
84
  const envVariables = loadEnvData();
55
85
  const twigVariables = {};
56
86
  const scssVariables = { env: { _tmp: 1 } }; // _tmp is used to avoid SCSS error if object is empty
@@ -78,4 +108,6 @@ export default function getEnvData() {
78
108
  js: jsVariables,
79
109
  env: envOutVariables,
80
110
  };
81
- }
111
+ });
112
+
113
+ export default getEnvData;