@videinfra/static-website-builder 1.15.1 → 1.15.2
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/src/html/data/global.js +1 -0
- package/init/test/src/html/env.twig +1 -0
- package/init/test/src/stylesheets/env-test.scss +1 -1
- package/package.json +1 -1
- package/tasks/data/get-data.js +6 -1
- package/tasks/env/get-env.js +5 -3
- package/tests/build/build.test.js +6 -0
- package/tests/sass-stringify.test.js +24 -0
- package/vendor/gulp-sass/index.js +2 -13
- package/vendor/gulp-sass/sass-stringify.js +32 -0
package/package.json
CHANGED
package/tasks/data/get-data.js
CHANGED
|
@@ -16,6 +16,11 @@ function getData () {
|
|
|
16
16
|
const loaders = getConfig.getTaskConfig('data', 'loaders');
|
|
17
17
|
const ignore = getConfig.getTaskConfig('data', 'ignore');
|
|
18
18
|
const group = getConfig.getTaskConfig('data', 'groupByFileName');
|
|
19
|
+
const envData = getEnvData();
|
|
20
|
+
|
|
21
|
+
// Merge into process.env before loading data because these may be used
|
|
22
|
+
// in data
|
|
23
|
+
merge(process.env, envData.env);
|
|
19
24
|
|
|
20
25
|
const data = reduce(folders, (data, folder) => {
|
|
21
26
|
getFileNamesSync(folder).forEach(fileName => {
|
|
@@ -62,7 +67,7 @@ function getData () {
|
|
|
62
67
|
}, {});
|
|
63
68
|
|
|
64
69
|
// Merge with env variables
|
|
65
|
-
return merge(data,
|
|
70
|
+
return merge(data, envData.twig);
|
|
66
71
|
}
|
|
67
72
|
|
|
68
73
|
|
package/tasks/env/get-env.js
CHANGED
|
@@ -14,12 +14,12 @@ function escapeJSVariable (value) {
|
|
|
14
14
|
function getEnvData () {
|
|
15
15
|
const envVariables = {};
|
|
16
16
|
const twigVariables = {};
|
|
17
|
-
const scssVariables = {};
|
|
17
|
+
const scssVariables = { env: {} };
|
|
18
18
|
const jsVariables = {};
|
|
19
|
+
const envOutVariables = {};
|
|
19
20
|
|
|
20
21
|
const envFiles = paths.getPathConfig().env.map((path) => paths.getProjectPath(path));
|
|
21
22
|
|
|
22
|
-
|
|
23
23
|
dotenv.config({
|
|
24
24
|
// dotenv file order is reversed, values in first file overwrite all other
|
|
25
25
|
// file values
|
|
@@ -36,8 +36,9 @@ function getEnvData () {
|
|
|
36
36
|
const camelCase = map[key];
|
|
37
37
|
const kebabCase = map[key].replace(/([a-z])([A-Z])/g, '$1-$2').replace(/_([a-z])/ig, '-$1').toLowerCase();
|
|
38
38
|
twigVariables[camelCase] = value;
|
|
39
|
+
envOutVariables[camelCase] = value;
|
|
39
40
|
jsVariables[`process.env.${ camelCase }`] = escapeJSVariable(value);
|
|
40
|
-
scssVariables[
|
|
41
|
+
scssVariables.env[kebabCase] = value;
|
|
41
42
|
}
|
|
42
43
|
});
|
|
43
44
|
|
|
@@ -45,6 +46,7 @@ function getEnvData () {
|
|
|
45
46
|
twig: twigVariables,
|
|
46
47
|
sass: scssVariables,
|
|
47
48
|
js: jsVariables,
|
|
49
|
+
env: envOutVariables,
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
52
|
|
|
@@ -109,6 +109,12 @@ test('.env and .env.local files loaded', () => {
|
|
|
109
109
|
]);
|
|
110
110
|
});
|
|
111
111
|
|
|
112
|
+
test('process.env available in html/data', () => {
|
|
113
|
+
return fsPromises.readFile(path.resolve(publicPath, 'env.html'), {'encoding': 'utf8'}).then((html) => {
|
|
114
|
+
expect(html.indexOf('<p>HOST FROM GLOBAL JS: https://test-local.tld</p>')).not.toBe(-1);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
112
118
|
test('icons generated', () => {
|
|
113
119
|
return fsPromises.readFile(path.resolve(publicPath, 'assets/images/icons.svg'), {'encoding': 'utf8'}).then((svg) => {
|
|
114
120
|
expect(svg.indexOf('<symbol id="example-arrow">')).not.toBe(-1);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const sassStingify = require('../vendor/gulp-sass/sass-stringify');
|
|
2
|
+
|
|
3
|
+
test('SASS stringify boolean', () => {
|
|
4
|
+
expect(sassStingify(true)).toEqual('true');
|
|
5
|
+
expect(sassStingify(false)).toEqual('false');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
test('SASS stringify number', () => {
|
|
9
|
+
expect(sassStingify(0)).toEqual('0');
|
|
10
|
+
expect(sassStingify(-123)).toEqual('-123');
|
|
11
|
+
expect(sassStingify(123.456)).toEqual('123.456');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test('SASS stringify falsy', () => {
|
|
15
|
+
expect(sassStingify(null)).toEqual('false');
|
|
16
|
+
expect(sassStingify(undefined)).toEqual('false');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('SASS stringify object', () => {
|
|
20
|
+
const obj1 = {env: {key1: 'value1', key2: null, key3: undefined, arr: ['a', 123, true] }};
|
|
21
|
+
const out1 = "$env: (key1: 'value1', key2: false, key3: false, arr: ('a',123,true));";
|
|
22
|
+
|
|
23
|
+
expect(sassStingify(obj1)).toEqual(out1);
|
|
24
|
+
});
|
|
@@ -9,6 +9,7 @@ const replaceExtension = require('replace-ext');
|
|
|
9
9
|
const stripAnsi = require('strip-ansi');
|
|
10
10
|
const clonedeep = require('lodash.clonedeep');
|
|
11
11
|
const applySourceMap = require('vinyl-sourcemaps-apply');
|
|
12
|
+
const sassStingify = require('./sass-stringify')
|
|
12
13
|
|
|
13
14
|
const PLUGIN_NAME = 'gulp-sass';
|
|
14
15
|
|
|
@@ -129,19 +130,7 @@ const gulpSass = (options, sync) => {
|
|
|
129
130
|
|
|
130
131
|
// Stringiyfy variables
|
|
131
132
|
if (options.data) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (typeof options.data === 'string') {
|
|
135
|
-
// Assume it's valid SCSS
|
|
136
|
-
scssVariables.push(options.data);
|
|
137
|
-
} else {
|
|
138
|
-
for (let key in options.data) {
|
|
139
|
-
const value = escapeSCSSVariable(options.data[key]);
|
|
140
|
-
scssVariables.push(`$${key}: ${value};`);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
opts.data = scssVariables.join('') + opts.data;
|
|
133
|
+
opts.data = sassStingify(options.data) + opts.data;
|
|
145
134
|
}
|
|
146
135
|
|
|
147
136
|
// We set the file path here so that libsass can correctly resolve import paths
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module.exports = function sassStingify (data, isDeep = false) {
|
|
2
|
+
if (data === null || data === undefined) {
|
|
3
|
+
return 'false';
|
|
4
|
+
} else if (data !== '' && (data === true || data === false || !isNaN(data))) {
|
|
5
|
+
// Convert to simple value
|
|
6
|
+
return String(data);
|
|
7
|
+
} else if (Array.isArray(data)) {
|
|
8
|
+
const out = data.map((item) => sassStingify(item, true));
|
|
9
|
+
return `(${ out })`;
|
|
10
|
+
} else if (data && typeof data === 'object') {
|
|
11
|
+
const out = [];
|
|
12
|
+
for (let key in data) {
|
|
13
|
+
out.push(`${key}: ${sassStingify(data[key], true)}`);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (out.length) {
|
|
17
|
+
if (isDeep) {
|
|
18
|
+
return `(${ out.join(', ') })`;
|
|
19
|
+
} else {
|
|
20
|
+
return `$${ out.join(';$') };`;
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
return '';
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
// Convert to string
|
|
27
|
+
return "'" + data.toString()
|
|
28
|
+
.replace(/\\/g, '\\\\')
|
|
29
|
+
.replace(/'/g, '\\\'')
|
|
30
|
+
.replace(/\n/g, '\\n') + "'";
|
|
31
|
+
}
|
|
32
|
+
};
|