@eui/tools 5.3.66 → 5.3.68

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.
@@ -9,6 +9,7 @@ const injectionUtils = require('./injection/injection-utils');
9
9
  const translationUtils = require('./translations/translation-utils');
10
10
 
11
11
  const configUtils = require('../../csdr/config/config-utils');
12
+ const svgUtils = require('../svg-utils');
12
13
 
13
14
  let { openid, dryRun } = tools.getArgs();
14
15
 
@@ -153,12 +154,11 @@ module.exports.preBuild = (project, envTarget, build, configEnvTarget) => {
153
154
  module.exports.injectAppConfig = (project, configEnvTarget) => {
154
155
  return Promise.resolve()
155
156
  .then(() => {
156
- tools.logInfo(`Executing configuration replacement for : ${configEnvTarget} environment`);
157
-
158
157
  // set default if not envTarget provided
159
158
  let envFilePath = path.join(project.paths.angularPath, 'src/assets/config', `env-json-config.json`);;
160
159
 
161
160
  if (configEnvTarget) {
161
+ tools.logInfo(`Executing configuration replacement for : ${configEnvTarget} environment`);
162
162
  envFilePath = path.join(project.paths.angularPath, 'src/assets/config', `env-json-config-${configEnvTarget}.json`);
163
163
  }
164
164
 
@@ -190,3 +190,18 @@ module.exports.injectAppConfig = (project, configEnvTarget) => {
190
190
  })
191
191
  }
192
192
 
193
+
194
+ module.exports.processSvgAssets = (project) => {
195
+ return Promise.resolve()
196
+ .then(() => {
197
+ const svgsInPath = path.join(project.paths.rootPath, 'src', 'assets', 'svg');
198
+ const svgsOutPath = path.join(project.paths.rootPath, 'src', 'assets', 'svg', 'optimized');
199
+ const svgsSpritePath = path.join(svgsInPath, 'sprite.svg');
200
+
201
+ return svgUtils.generateSvgsSprite(svgsInPath, svgsOutPath, svgsSpritePath);
202
+ })
203
+
204
+ .catch((e) => {
205
+ throw e;
206
+ })
207
+ }
@@ -0,0 +1,81 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ const tools = require('./tools');
7
+
8
+ module.exports.generateSvgsSprite = (svgsInPath, svgsOutPath, svgsSpritePath) => {
9
+ const imagemin = require('imagemin');
10
+ const imageminSvgo = require('imagemin-svgo');
11
+ const svgstore = require('svgstore');
12
+
13
+ let svgFiles;
14
+
15
+ return Promise.resolve()
16
+ .then(() => {
17
+ return tools.rimraf(svgsOutPath);
18
+ })
19
+ .then(() => {
20
+ return tools.remove(svgsSpritePath);
21
+ })
22
+ .then(() => {
23
+ return tools.getFilesGlob(svgsInPath, '**/*.svg');
24
+ })
25
+ .then((files) => {
26
+ svgFiles = files;
27
+
28
+ tools.logInfo('Optimizing svg files');
29
+ tools.logInfo('Found :');
30
+ console.log(svgFiles);
31
+
32
+ const filesPaths = svgFiles.map(f => path.join(svgsInPath, f));
33
+
34
+ return imagemin(filesPaths, {
35
+ glob: false,
36
+ destination: svgsOutPath,
37
+ plugins: [
38
+ imageminSvgo({
39
+ plugins: [
40
+ { name: 'cleanupIDs', remove: false },
41
+ { name: 'cleanupNumericValues', floatPrecision: 2 },
42
+ { name: 'removeStyleElement', remove: true },
43
+ { name: 'removeTitle', remove: true },
44
+ ],
45
+ multipass: true
46
+ })
47
+ ]
48
+ })
49
+ })
50
+
51
+ .then((files) => {
52
+ tools.logSuccess(`${files.length} processed`);
53
+
54
+ tools.logInfo('Creating svg sprite');
55
+
56
+ const sprites = svgstore();
57
+
58
+ svgFiles.forEach((f) => {
59
+ sprites.add(
60
+ f.substr(0, f.indexOf('.svg')),
61
+ fs.readFileSync(path.join(svgsOutPath, f), 'utf8')
62
+ );
63
+ });
64
+
65
+ tools.writeFileContent(svgsSpritePath, sprites);
66
+
67
+ tools.logSuccess(`OK => ${svgsSpritePath} generated`);
68
+ })
69
+
70
+ .then(() => {
71
+ return tools.rimraf(svgsOutPath);
72
+ })
73
+
74
+ .then(() => {
75
+ tools.logSuccess(`${svgsOutPath} cleaned up`);
76
+ })
77
+
78
+ .catch((e) => {
79
+ throw e;
80
+ })
81
+ }