@videinfra/static-website-builder 2.0.2 → 2.0.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/.prettierrc +11 -11
- package/CHANGELOG.md +214 -210
- package/README.md +102 -102
- package/bin/builder.js +40 -40
- package/eslint.config.js +39 -39
- package/gulpfile.js +63 -63
- package/init/default/config/config.js +44 -44
- package/init/default/src/html/data/global.js +9 -9
- package/init/default/src/javascripts/_entries.js +14 -14
- package/init/index.js +63 -63
- package/init/test/.env +6 -6
- package/init/test/.env.local +3 -2
- package/init/test/config/config.js +71 -67
- package/init/test/src/html/404.twig +12 -12
- package/init/test/src/html/data/global.js +10 -10
- package/init/test/src/html/env.twig +21 -21
- package/init/test/src/html/layouts/base.twig +1 -1
- package/init/test/src/html/other.twig +9 -9
- package/init/test/src/html/preposition.twig +4 -4
- package/init/test/src/javascripts/_entries-alt.js +10 -10
- package/init/test/src/javascripts/_entries.js +19 -19
- package/init/test/src/javascripts/common.js +13 -13
- package/init/test/src/javascripts/main.js +8 -8
- package/init/test/src/javascripts/something.ts +9 -9
- package/init/test/src/stylesheets/autoprefixer-test.scss +3 -3
- package/init/test/src/stylesheets/env-test.scss +28 -28
- package/init/test/src/stylesheets/ignore-test.scss +4 -4
- package/init/test/src/stylesheets/nested-calc-test.scss +3 -3
- package/init/test/src/stylesheets/sub-folder/import-test.scss +2 -2
- package/lib/camelize-file-name.js +21 -21
- package/lib/generate-gulp-tasks.js +85 -85
- package/lib/get-config.js +203 -204
- package/lib/get-file-names.js +23 -23
- package/lib/get-path.js +102 -102
- package/lib/globs-helper.js +243 -243
- package/lib/gulp/dynamic-task.js +8 -8
- package/lib/gulp/resolve-dynamic-task.js +11 -11
- package/lib/gulp/task-before-dest.js +8 -8
- package/lib/gulp/task-end.js +10 -10
- package/lib/gulp/task-start.js +12 -12
- package/lib/gulp/task-watch.js +66 -66
- package/lib/init/copy-folder.js +50 -50
- package/lib/init/folder-exists.js +10 -10
- package/lib/init/get-folder-list.js +16 -16
- package/lib/init/merge-package.js +17 -17
- package/lib/init/read-package.js +17 -17
- package/lib/log-error.js +15 -15
- package/lib/merge.js +27 -27
- package/lib/run-preprocess.js +32 -32
- package/lib/task-order.js +19 -19
- package/package.json +68 -68
- package/plugins/example/preprocess-config.js +17 -17
- package/plugins/example/task.js +55 -55
- package/plugins/example.js +38 -38
- package/plugins/sass-engine/preprocess-config.js +59 -59
- package/plugins/sass.js +41 -41
- package/plugins/twig/lodash-filters/filters.js +91 -91
- package/plugins/twig/lodash-filters.js +14 -14
- package/plugins/twig/symfony-filters/filters.js +102 -102
- package/plugins/twig/symfony-filters/preposition_nbsp.js +77 -77
- package/plugins/twig/symfony-filters.js +14 -14
- package/plugins/twig/symfony-functions/functions.js +31 -31
- package/plugins/twig/symfony-functions.js +14 -14
- package/plugins/twig-engine/preprocess-config.js +53 -53
- package/plugins/twig.js +74 -74
- package/tasks/browser-sync/config.js +39 -39
- package/tasks/browser-sync/preprocess-config.js +32 -32
- package/tasks/browser-sync/task.js +9 -9
- package/tasks/clean/config.js +20 -20
- package/tasks/clean/preprocess-config.js +19 -19
- package/tasks/clean/task.js +7 -7
- package/tasks/data/config.js +34 -34
- package/tasks/data/data-loader-js.js +14 -14
- package/tasks/data/data-loader-json.js +5 -5
- package/tasks/data/get-data.js +96 -96
- package/tasks/env/config.js +26 -23
- package/tasks/env/get-env.js +113 -81
- package/tasks/fonts/config.js +24 -24
- package/tasks/fonts/task.js +47 -47
- package/tasks/global/config.js +7 -7
- package/tasks/html/config.js +42 -42
- package/tasks/html/task.js +91 -91
- package/tasks/icons/config.js +47 -47
- package/tasks/icons/preprocess-config.js +60 -60
- package/tasks/icons/task.js +56 -56
- package/tasks/images/config.js +27 -27
- package/tasks/images/task.js +46 -46
- package/tasks/javascripts/config.js +69 -69
- package/tasks/javascripts/preprocess-config.js +109 -109
- package/tasks/javascripts/task.js +86 -86
- package/tasks/sitemap/config.js +48 -48
- package/tasks/sitemap/preprocess-config.js +18 -18
- package/tasks/sitemap/task.js +69 -69
- package/tasks/sizereport/config.js +23 -23
- package/tasks/sizereport/task.js +16 -16
- package/tasks/static/config.js +27 -27
- package/tasks/static/task.js +46 -46
- package/tasks/stylesheets/config.js +85 -85
- package/tasks/stylesheets/preprocess-config.js +41 -41
- package/tasks/stylesheets/task.js +73 -73
- package/tests/build/build.test.js +153 -153
- package/tests/camelize-file-name.test.js +11 -11
- package/tests/generate-gulp-tasks.test.js +78 -78
- package/tests/glob-helper.test.js +99 -99
- package/tests/merge.test.js +10 -10
- package/tests/preposition_nbsp.test.js +50 -50
- package/tests/run-preprocess.test.js +90 -90
- package/tests/sass-stringify.test.js +24 -24
- package/tests/sitemap.test.js +12 -12
- package/vendor/gulp-rolldown/index.js +151 -151
- package/vendor/gulp-rolldown/plugin-raw.js +17 -17
- package/vendor/gulp-rolldown/plugin-virtual-entry.js +30 -30
- package/vendor/gulp-sass/CHANGELOG.md +168 -168
- package/vendor/gulp-sass/LICENSE +20 -20
- package/vendor/gulp-sass/README.md +187 -187
- package/vendor/gulp-sass/index.js +208 -208
- package/vendor/gulp-sass/package.json +61 -61
- package/vendor/gulp-sass/sass-stringify.js +32 -32
- package/vendor/gulp-twig/LICENSE +20 -20
- package/vendor/gulp-twig/README.md +167 -167
- package/vendor/gulp-twig/index.js +138 -138
- package/vendor/gulp-twig/package.json +44 -44
package/tasks/data/config.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import dataLoaderJs from './data-loader-js.js';
|
|
2
|
-
import dataLoaderJson from './data-loader-json.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Data loading for HTML task
|
|
6
|
-
* This task doesn't have actual task, instead it's used by 'html' task
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export const data = {
|
|
10
|
-
extensions: ['js', 'json'],
|
|
11
|
-
|
|
12
|
-
// Data loaders for extensions, allows to add custom loaders
|
|
13
|
-
loaders: {
|
|
14
|
-
js: dataLoaderJs,
|
|
15
|
-
json: dataLoaderJson,
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
// Glob list of files, which to ignore, relative to the data source folder
|
|
19
|
-
// see https://gulpjs.com/docs/en/getting-started/explaining-globs/
|
|
20
|
-
ignore: [],
|
|
21
|
-
|
|
22
|
-
// Group data by filename (without extension + cammelCase)
|
|
23
|
-
// eg, person-names.js -> {'personNames': ...}
|
|
24
|
-
groupByFileName: false,
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Paths relative to the global src and dest folders
|
|
29
|
-
*/
|
|
30
|
-
export const paths = {
|
|
31
|
-
data: {
|
|
32
|
-
src: 'html/data',
|
|
33
|
-
},
|
|
34
|
-
};
|
|
1
|
+
import dataLoaderJs from './data-loader-js.js';
|
|
2
|
+
import dataLoaderJson from './data-loader-json.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Data loading for HTML task
|
|
6
|
+
* This task doesn't have actual task, instead it's used by 'html' task
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export const data = {
|
|
10
|
+
extensions: ['js', 'json'],
|
|
11
|
+
|
|
12
|
+
// Data loaders for extensions, allows to add custom loaders
|
|
13
|
+
loaders: {
|
|
14
|
+
js: dataLoaderJs,
|
|
15
|
+
json: dataLoaderJson,
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
// Glob list of files, which to ignore, relative to the data source folder
|
|
19
|
+
// see https://gulpjs.com/docs/en/getting-started/explaining-globs/
|
|
20
|
+
ignore: [],
|
|
21
|
+
|
|
22
|
+
// Group data by filename (without extension + cammelCase)
|
|
23
|
+
// eg, person-names.js -> {'personNames': ...}
|
|
24
|
+
groupByFileName: false,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Paths relative to the global src and dest folders
|
|
29
|
+
*/
|
|
30
|
+
export const paths = {
|
|
31
|
+
data: {
|
|
32
|
+
src: 'html/data',
|
|
33
|
+
},
|
|
34
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';
|
|
2
|
-
const require = createRequire(import.meta.url);
|
|
3
|
-
|
|
4
|
-
export default function dataLoaderJS (fileName) {
|
|
5
|
-
// Re-load script each time this function is called
|
|
6
|
-
delete require.cache[require.resolve(fileName)];
|
|
7
|
-
const data = require(fileName);
|
|
8
|
-
|
|
9
|
-
if (data && Object.prototype.toString.call(data) === '[object Module]') {
|
|
10
|
-
return data.default;
|
|
11
|
-
} else {
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
|
|
4
|
+
export default function dataLoaderJS (fileName) {
|
|
5
|
+
// Re-load script each time this function is called
|
|
6
|
+
delete require.cache[require.resolve(fileName)];
|
|
7
|
+
const data = require(fileName);
|
|
8
|
+
|
|
9
|
+
if (data && Object.prototype.toString.call(data) === '[object Module]') {
|
|
10
|
+
return data.default;
|
|
11
|
+
} else {
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
|
|
3
|
-
export default function dataLoaderJSON(fileName) {
|
|
4
|
-
return JSON.parse(fs.readFileSync(fileName, 'utf8'));
|
|
5
|
-
}
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
|
|
3
|
+
export default function dataLoaderJSON(fileName) {
|
|
4
|
+
return JSON.parse(fs.readFileSync(fileName, 'utf8'));
|
|
5
|
+
}
|
package/tasks/data/get-data.js
CHANGED
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import reduce from 'lodash/reduce.js';
|
|
3
|
-
import micromatch from 'micromatch'; // gulp dependency
|
|
4
|
-
|
|
5
|
-
import merge from '../../lib/merge.js';
|
|
6
|
-
import { getSourcePaths, getPathConfig } from '../../lib/get-path.js';
|
|
7
|
-
import { getTaskConfig } from '../../lib/get-config.js';
|
|
8
|
-
import logError from '../../lib/log-error.js';
|
|
9
|
-
import getFileNamesSync from '../../lib/get-file-names.js';
|
|
10
|
-
import camelizeFileName from '../../lib/camelize-file-name.js';
|
|
11
|
-
import getEnvData from '../env/get-env.js';
|
|
12
|
-
|
|
13
|
-
function getData() {
|
|
14
|
-
const folders = getSourcePaths('data');
|
|
15
|
-
const extensions = getTaskConfig('data', 'extensions');
|
|
16
|
-
const loaders = getTaskConfig('data', 'loaders');
|
|
17
|
-
const ignore = getTaskConfig('data', 'ignore');
|
|
18
|
-
const group = 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);
|
|
24
|
-
|
|
25
|
-
const data = reduce(
|
|
26
|
-
folders,
|
|
27
|
-
(data, folder) => {
|
|
28
|
-
getFileNamesSync(folder).forEach((fileName) => {
|
|
29
|
-
// Ignore files matching 'ignore' list
|
|
30
|
-
if (ignore.length && micromatch.isMatch(fileName, ignore)) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Ignore files starting with underscore
|
|
35
|
-
if (fileName[0] !== '_') {
|
|
36
|
-
const extension = fileName.split('.').pop();
|
|
37
|
-
|
|
38
|
-
if (extension && extensions.indexOf(extension) !== -1) {
|
|
39
|
-
if (extension in loaders) {
|
|
40
|
-
try {
|
|
41
|
-
const fullFilePath = path.resolve(folder, fileName);
|
|
42
|
-
const fileData = loaders[extension](fullFilePath);
|
|
43
|
-
|
|
44
|
-
if (group) {
|
|
45
|
-
// Group data
|
|
46
|
-
const name = camelizeFileName(fileName);
|
|
47
|
-
data = merge(data, { [name]: fileData });
|
|
48
|
-
} else {
|
|
49
|
-
// Merge together
|
|
50
|
-
data = merge(data, fileData);
|
|
51
|
-
}
|
|
52
|
-
} catch (err) {
|
|
53
|
-
logError({
|
|
54
|
-
message: `Failed to parse "${path.join(getPathConfig().src, getPathConfig().data.src, fileName)}"`,
|
|
55
|
-
plugin: 'data',
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
} else {
|
|
59
|
-
logError({
|
|
60
|
-
message: `Data loader for files with "${extension}" extension is not defined in configuration data.loaders property`,
|
|
61
|
-
plugin: 'data',
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
return data;
|
|
69
|
-
},
|
|
70
|
-
{},
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
// Merge with env variables
|
|
74
|
-
return merge(data, envData.twig);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
let cache = null;
|
|
78
|
-
|
|
79
|
-
export default function (options) {
|
|
80
|
-
const build = options && !!options.build;
|
|
81
|
-
|
|
82
|
-
return function () {
|
|
83
|
-
if (build) {
|
|
84
|
-
// Cache during full build
|
|
85
|
-
if (!cache) {
|
|
86
|
-
cache = getData();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return cache;
|
|
90
|
-
} else {
|
|
91
|
-
// Don't cache during watch build
|
|
92
|
-
cache = null;
|
|
93
|
-
return getData();
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
}
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import reduce from 'lodash/reduce.js';
|
|
3
|
+
import micromatch from 'micromatch'; // gulp dependency
|
|
4
|
+
|
|
5
|
+
import merge from '../../lib/merge.js';
|
|
6
|
+
import { getSourcePaths, getPathConfig } from '../../lib/get-path.js';
|
|
7
|
+
import { getTaskConfig } from '../../lib/get-config.js';
|
|
8
|
+
import logError from '../../lib/log-error.js';
|
|
9
|
+
import getFileNamesSync from '../../lib/get-file-names.js';
|
|
10
|
+
import camelizeFileName from '../../lib/camelize-file-name.js';
|
|
11
|
+
import getEnvData from '../env/get-env.js';
|
|
12
|
+
|
|
13
|
+
function getData() {
|
|
14
|
+
const folders = getSourcePaths('data');
|
|
15
|
+
const extensions = getTaskConfig('data', 'extensions');
|
|
16
|
+
const loaders = getTaskConfig('data', 'loaders');
|
|
17
|
+
const ignore = getTaskConfig('data', 'ignore');
|
|
18
|
+
const group = 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);
|
|
24
|
+
|
|
25
|
+
const data = reduce(
|
|
26
|
+
folders,
|
|
27
|
+
(data, folder) => {
|
|
28
|
+
getFileNamesSync(folder).forEach((fileName) => {
|
|
29
|
+
// Ignore files matching 'ignore' list
|
|
30
|
+
if (ignore.length && micromatch.isMatch(fileName, ignore)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Ignore files starting with underscore
|
|
35
|
+
if (fileName[0] !== '_') {
|
|
36
|
+
const extension = fileName.split('.').pop();
|
|
37
|
+
|
|
38
|
+
if (extension && extensions.indexOf(extension) !== -1) {
|
|
39
|
+
if (extension in loaders) {
|
|
40
|
+
try {
|
|
41
|
+
const fullFilePath = path.resolve(folder, fileName);
|
|
42
|
+
const fileData = loaders[extension](fullFilePath);
|
|
43
|
+
|
|
44
|
+
if (group) {
|
|
45
|
+
// Group data
|
|
46
|
+
const name = camelizeFileName(fileName);
|
|
47
|
+
data = merge(data, { [name]: fileData });
|
|
48
|
+
} else {
|
|
49
|
+
// Merge together
|
|
50
|
+
data = merge(data, fileData);
|
|
51
|
+
}
|
|
52
|
+
} catch (err) {
|
|
53
|
+
logError({
|
|
54
|
+
message: `Failed to parse "${path.join(getPathConfig().src, getPathConfig().data.src, fileName)}"`,
|
|
55
|
+
plugin: 'data',
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
logError({
|
|
60
|
+
message: `Data loader for files with "${extension}" extension is not defined in configuration data.loaders property`,
|
|
61
|
+
plugin: 'data',
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return data;
|
|
69
|
+
},
|
|
70
|
+
{},
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
// Merge with env variables
|
|
74
|
+
return merge(data, envData.twig);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
let cache = null;
|
|
78
|
+
|
|
79
|
+
export default function (options) {
|
|
80
|
+
const build = options && !!options.build;
|
|
81
|
+
|
|
82
|
+
return function () {
|
|
83
|
+
if (build) {
|
|
84
|
+
// Cache during full build
|
|
85
|
+
if (!cache) {
|
|
86
|
+
cache = getData();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return cache;
|
|
90
|
+
} else {
|
|
91
|
+
// Don't cache during watch build
|
|
92
|
+
cache = null;
|
|
93
|
+
return getData();
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
package/tasks/env/config.js
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Enviromental variable loading configuration
|
|
3
|
-
* Environment variables are loaded from .env files and remapped so that they can
|
|
4
|
-
* be used in TWIG, SASS and JavaScript:
|
|
5
|
-
* in TWIG `host` is accessible as `host`
|
|
6
|
-
* in SCSS `host` is accessible as `map-get($env, host)`
|
|
7
|
-
* in JS `host` is accessible as `process.env.host`
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
export const env = {
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Enviromental variable loading configuration
|
|
3
|
+
* Environment variables are loaded from .env files and remapped so that they can
|
|
4
|
+
* be used in TWIG, SASS and JavaScript:
|
|
5
|
+
* in TWIG `host` is accessible as `host`
|
|
6
|
+
* in SCSS `host` is accessible as `map-get($env, host)`
|
|
7
|
+
* in JS `host` is accessible as `process.env.host`
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export const env = {
|
|
11
|
+
// Write ASSET_VERSION to .env file to enable cache busting
|
|
12
|
+
writeAssetVersion: false,
|
|
13
|
+
|
|
14
|
+
// How env variable names should be remapped
|
|
15
|
+
// Example:
|
|
16
|
+
// map: { 'HOST': 'host', 'RECAPTCHA3_PUBLIC_KEY': 'recaptcha3_site_key' }
|
|
17
|
+
map: {}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const paths = {
|
|
21
|
+
// Env files which to load relative to project folder
|
|
22
|
+
env: [
|
|
23
|
+
'../.env',
|
|
24
|
+
'../.env.local',
|
|
25
|
+
],
|
|
26
|
+
};
|
package/tasks/env/get-env.js
CHANGED
|
@@ -1,81 +1,113 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
*
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import dotenv from 'dotenv';
|
|
3
|
+
import nanomemoize from 'nano-memoize';
|
|
4
|
+
import { getPathConfig, getProjectPath } from '../../lib/get-path.js';
|
|
5
|
+
import { getTaskConfig } from '../../lib/get-config.js';
|
|
6
|
+
|
|
7
|
+
function escapeJSVariable(value) {
|
|
8
|
+
if (value === 'true' || value === 'false' || value === true || value === false || !isNaN(value)) {
|
|
9
|
+
return value;
|
|
10
|
+
} else {
|
|
11
|
+
// Convert to string
|
|
12
|
+
return "'" + value.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/\n/g, '\\n') + "'";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function normalizeTwigVariable(value) {
|
|
17
|
+
if (value === 'true') {
|
|
18
|
+
return true;
|
|
19
|
+
} else if (value === 'false') {
|
|
20
|
+
return false;
|
|
21
|
+
} else if (value !== '' && !isNaN(value)) {
|
|
22
|
+
return parseFloat(value);
|
|
23
|
+
} else {
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
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
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Load data from the .env files
|
|
56
|
+
* @returns {object} List of environment variables
|
|
57
|
+
*/
|
|
58
|
+
export const loadEnvData = nanomemoize.nanomemoize(function () {
|
|
59
|
+
const envVariables = {};
|
|
60
|
+
const envFiles = getPathConfig().env.map((path) => getProjectPath(path));
|
|
61
|
+
|
|
62
|
+
dotenv.config({
|
|
63
|
+
// dotenv file order is reversed, values in first file overwrite all other
|
|
64
|
+
// file values
|
|
65
|
+
path: envFiles.reverse(),
|
|
66
|
+
processEnv: envVariables,
|
|
67
|
+
quiet: true,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Set assets version if it doesn't exist
|
|
71
|
+
if (!envVariables['ASSETS_VERSION'] || getTaskConfig('env', 'writeAssetVersion')) {
|
|
72
|
+
envVariables['ASSETS_VERSION'] = String(Math.floor(Date.now() / 1000));
|
|
73
|
+
writeEnvFileAssetVersion(envVariables['ASSETS_VERSION']);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return envVariables;
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Returns environment variables mapped to the specified names
|
|
81
|
+
* @returns {object} Mapped environment variables
|
|
82
|
+
*/
|
|
83
|
+
const getEnvData = nanomemoize.nanomemoize(function () {
|
|
84
|
+
const envVariables = loadEnvData();
|
|
85
|
+
const twigVariables = {};
|
|
86
|
+
const scssVariables = { env: { _tmp: 1 } }; // _tmp is used to avoid SCSS error if object is empty
|
|
87
|
+
const jsVariables = {};
|
|
88
|
+
const envOutVariables = {};
|
|
89
|
+
|
|
90
|
+
// Remap property names
|
|
91
|
+
const map = getTaskConfig('env', 'map');
|
|
92
|
+
|
|
93
|
+
Object.keys(map).forEach((key) => {
|
|
94
|
+
if (key in envVariables) {
|
|
95
|
+
const value = envVariables[key];
|
|
96
|
+
const camelCase = map[key];
|
|
97
|
+
const kebabCase = map[key];
|
|
98
|
+
twigVariables[camelCase] = normalizeTwigVariable(value);
|
|
99
|
+
envOutVariables[camelCase] = value;
|
|
100
|
+
jsVariables[`process.env.${camelCase}`] = escapeJSVariable(value);
|
|
101
|
+
scssVariables.env[kebabCase] = value;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
twig: twigVariables,
|
|
107
|
+
sass: scssVariables,
|
|
108
|
+
js: jsVariables,
|
|
109
|
+
env: envOutVariables,
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
export default getEnvData;
|
package/tasks/fonts/config.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import * as fontTask from './task.js';
|
|
2
|
-
|
|
3
|
-
export const fonts = {
|
|
4
|
-
// Glob list of files, which to ignore, relative to the font source folder
|
|
5
|
-
// see https://gulpjs.com/docs/en/getting-started/explaining-globs/
|
|
6
|
-
ignore: [],
|
|
7
|
-
|
|
8
|
-
// Font file extensions
|
|
9
|
-
extensions: ['woff2', 'woff', 'eot', 'ttf', 'svg', 'otf'],
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export const tasks = {
|
|
13
|
-
fonts: [fontTask],
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Paths relative to the global src and dest folders
|
|
18
|
-
*/
|
|
19
|
-
export const paths = {
|
|
20
|
-
fonts: {
|
|
21
|
-
src: 'fonts',
|
|
22
|
-
dest: 'assets/fonts',
|
|
23
|
-
},
|
|
24
|
-
};
|
|
1
|
+
import * as fontTask from './task.js';
|
|
2
|
+
|
|
3
|
+
export const fonts = {
|
|
4
|
+
// Glob list of files, which to ignore, relative to the font source folder
|
|
5
|
+
// see https://gulpjs.com/docs/en/getting-started/explaining-globs/
|
|
6
|
+
ignore: [],
|
|
7
|
+
|
|
8
|
+
// Font file extensions
|
|
9
|
+
extensions: ['woff2', 'woff', 'eot', 'ttf', 'svg', 'otf'],
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const tasks = {
|
|
13
|
+
fonts: [fontTask],
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Paths relative to the global src and dest folders
|
|
18
|
+
*/
|
|
19
|
+
export const paths = {
|
|
20
|
+
fonts: {
|
|
21
|
+
src: 'fonts',
|
|
22
|
+
dest: 'assets/fonts',
|
|
23
|
+
},
|
|
24
|
+
};
|