@videinfra/static-website-builder 1.15.2 → 1.15.4
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/init/test/.env +4 -0
- package/init/test/config/config.js +4 -0
- package/init/test/src/html/env.twig +14 -0
- package/init/test/src/javascripts/main.js +3 -0
- package/init/test/src/stylesheets/env-test.scss +25 -0
- package/package.json +1 -1
- package/tasks/env/get-env.js +15 -3
- package/tests/build/build.test.js +10 -0
- package/vendor/gulp-sass/sass-stringify.js +1 -1
package/init/test/.env
CHANGED
|
@@ -4,4 +4,18 @@
|
|
|
4
4
|
{% block body %}
|
|
5
5
|
<p>HOST: {{ host }}</p>
|
|
6
6
|
<p>HOST FROM GLOBAL JS: {{ hostFromGlobalJS }}</p>
|
|
7
|
+
|
|
8
|
+
{% if typeBoolTrue %}
|
|
9
|
+
<p>TYPE_BOOL_TRUE: pass</p>
|
|
10
|
+
{% else %}
|
|
11
|
+
<p>TYPE_BOOL_TRUE: fail</p>
|
|
12
|
+
{% endif %}
|
|
13
|
+
|
|
14
|
+
{% if typeBoolFalse %}
|
|
15
|
+
<p>TYPE_BOOL_FALSE: fail</p>
|
|
16
|
+
{% else %}
|
|
17
|
+
<p>TYPE_BOOL_FALSE: pass</p>
|
|
18
|
+
{% endif %}
|
|
19
|
+
|
|
20
|
+
<p>TYPE_NUMBER: {{ typeNumber }}</p>
|
|
7
21
|
{% endblock %}
|
|
@@ -3,3 +3,6 @@ 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.typeBoolTrue ==', process.env.typeBoolTrue);
|
|
7
|
+
console.log('env.typeBoolFalse ==', process.env.typeBoolFalse);
|
|
8
|
+
console.log('env.typeNumber ==', process.env.typeNumber);
|
|
@@ -1,3 +1,28 @@
|
|
|
1
1
|
.env-test:before {
|
|
2
2
|
content: map-get($env, host);
|
|
3
3
|
}
|
|
4
|
+
|
|
5
|
+
:root {
|
|
6
|
+
#{ --env-test-type-number }: map-get($env, typeNumber);
|
|
7
|
+
#{ --env-test-type-empty }: map-get($env, typeEmpty);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@if map-get($env, typeBoolTrue) {
|
|
11
|
+
:root {
|
|
12
|
+
--env-test-bool-true: true;
|
|
13
|
+
}
|
|
14
|
+
} @else {
|
|
15
|
+
:root {
|
|
16
|
+
--env-test-bool-true: false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@if map-get($env, typeBoolFalse) {
|
|
21
|
+
:root {
|
|
22
|
+
--env-test-bool-false: true;
|
|
23
|
+
}
|
|
24
|
+
} @else {
|
|
25
|
+
:root {
|
|
26
|
+
--env-test-bool-false: false;
|
|
27
|
+
}
|
|
28
|
+
}
|
package/package.json
CHANGED
package/tasks/env/get-env.js
CHANGED
|
@@ -3,7 +3,7 @@ const dotenv = require('dotenv');
|
|
|
3
3
|
const getConfig = require('../../lib/get-config');
|
|
4
4
|
|
|
5
5
|
function escapeJSVariable (value) {
|
|
6
|
-
if (value === true || value === false || !isNaN(value)) {
|
|
6
|
+
if (value === 'true' || value === 'false' || value === true || value === false || !isNaN(value)) {
|
|
7
7
|
return value;
|
|
8
8
|
} else {
|
|
9
9
|
// Convert to string
|
|
@@ -11,6 +11,18 @@ function escapeJSVariable (value) {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
function normalizeTwigVariable (value) {
|
|
15
|
+
if (value === 'true') {
|
|
16
|
+
return true;
|
|
17
|
+
} else if (value === 'false') {
|
|
18
|
+
return false;
|
|
19
|
+
} else if (value !== '' && !isNaN(value)) {
|
|
20
|
+
return parseFloat(value);
|
|
21
|
+
} else {
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
14
26
|
function getEnvData () {
|
|
15
27
|
const envVariables = {};
|
|
16
28
|
const twigVariables = {};
|
|
@@ -34,8 +46,8 @@ function getEnvData () {
|
|
|
34
46
|
if (key in envVariables) {
|
|
35
47
|
const value = envVariables[key];
|
|
36
48
|
const camelCase = map[key];
|
|
37
|
-
const kebabCase = map[key]
|
|
38
|
-
twigVariables[camelCase] = value;
|
|
49
|
+
const kebabCase = map[key];
|
|
50
|
+
twigVariables[camelCase] = normalizeTwigVariable(value);
|
|
39
51
|
envOutVariables[camelCase] = value;
|
|
40
52
|
jsVariables[`process.env.${ camelCase }`] = escapeJSVariable(value);
|
|
41
53
|
scssVariables.env[kebabCase] = value;
|
|
@@ -99,12 +99,22 @@ test('.env and .env.local files loaded', () => {
|
|
|
99
99
|
expect(js.indexOf('console.log("env.host ==","https://test-local.tld")')).not.toBe(-1);
|
|
100
100
|
expect(js.indexOf('console.log("env.foo ==","foo-global")')).not.toBe(-1);
|
|
101
101
|
expect(js.indexOf('console.log("env.bar ==","bar-local")')).not.toBe(-1);
|
|
102
|
+
expect(js.indexOf('console.log("env.typeBoolTrue ==",!0)')).not.toBe(-1);
|
|
103
|
+
expect(js.indexOf('console.log("env.typeBoolFalse ==",!1)')).not.toBe(-1);
|
|
104
|
+
expect(js.indexOf('console.log("env.typeNumber ==",123.456)')).not.toBe(-1);
|
|
102
105
|
}),
|
|
103
106
|
fsPromises.readFile(path.resolve(publicPath, 'env.html'), {'encoding': 'utf8'}).then((html) => {
|
|
104
107
|
expect(html.indexOf('<p>HOST: https://test-local.tld</p>')).not.toBe(-1);
|
|
108
|
+
expect(html.indexOf('<p>TYPE_BOOL_TRUE: pass</p>')).not.toBe(-1);
|
|
109
|
+
expect(html.indexOf('<p>TYPE_BOOL_FALSE: pass</p>')).not.toBe(-1);
|
|
110
|
+
expect(html.indexOf('<p>TYPE_NUMBER: 123.456</p>')).not.toBe(-1);
|
|
105
111
|
}),
|
|
106
112
|
fsPromises.readFile(path.resolve(publicPath, 'assets/stylesheets/env-test.css'), {'encoding': 'utf8'}).then((css) => {
|
|
107
113
|
expect(css.indexOf('.env-test:before{content:"https://test-local.tld"}')).not.toBe(-1);
|
|
114
|
+
expect(css.indexOf('--env-test-bool-true:true')).not.toBe(-1);
|
|
115
|
+
expect(css.indexOf('--env-test-bool-false:false')).not.toBe(-1);
|
|
116
|
+
expect(css.indexOf('--env-test-type-number:123.456')).not.toBe(-1);
|
|
117
|
+
expect(css.indexOf('--env-test-type-empty:""')).not.toBe(-1);
|
|
108
118
|
}),
|
|
109
119
|
]);
|
|
110
120
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module.exports = function sassStingify (data, isDeep = false) {
|
|
2
2
|
if (data === null || data === undefined) {
|
|
3
3
|
return 'false';
|
|
4
|
-
} else if (data !== '' && (data === true || data === false || !isNaN(data))) {
|
|
4
|
+
} else if (data !== '' && (data === 'true' || data === 'false' || data === true || data === false || !isNaN(data))) {
|
|
5
5
|
// Convert to simple value
|
|
6
6
|
return String(data);
|
|
7
7
|
} else if (Array.isArray(data)) {
|