@eui/tools 5.3.69 → 5.3.71

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.
@@ -1 +1 @@
1
- 5.3.69
1
+ 5.3.71
package/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## 5.3.71 (2022-10-06)
2
+
3
+ ##### Chores
4
+
5
+ * **other:**
6
+ * refactored sprite generator based on ECL builder using svg-sprite adapted config - EUI-6557 [EUI-6557](https://webgate.ec.europa.eu/CITnet/jira/browse/EUI-6557) ([aec93722](https://webgate.ec.europa.eu/CITnet/stash/scm/csdr/eui-tools.git/commits/aec9372277ff41b2004b9c4a4d796c3201dc9d94))
7
+
8
+ * * *
9
+ * * *
10
+ ## 5.3.70 (2022-10-05)
11
+
12
+ ##### Chores
13
+
14
+ * **other:**
15
+ * adapt svg sprite generator script for eUI 15 - EUI-6448 [EUI-6448](https://webgate.ec.europa.eu/CITnet/jira/browse/EUI-6448) ([e5f8465e](https://webgate.ec.europa.eu/CITnet/stash/scm/csdr/eui-tools.git/commits/e5f8465ea9de6e2204983d45b97349e4439e07c7))
16
+
17
+ * * *
18
+ * * *
1
19
  ## 5.3.69 (2022-10-03)
2
20
 
3
21
  ##### Bug Fixes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eui/tools",
3
- "version": "5.3.69",
3
+ "version": "5.3.71",
4
4
  "tag": "latest",
5
5
  "license": "EUPL-1.1",
6
6
  "description": "eUI common tools and scripts",
@@ -45,6 +45,6 @@
45
45
  "sendmail": "1.6.1",
46
46
  "imagemin": "7.0.1",
47
47
  "imagemin-svgo": "9.0.0",
48
- "svgstore": "3.0.1"
48
+ "svg-sprite": "1.5.3"
49
49
  }
50
50
  }
@@ -195,10 +195,10 @@ module.exports.processSvgAssets = (project) => {
195
195
  return Promise.resolve()
196
196
  .then(() => {
197
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');
198
+ const svgsSpritePath = path.join(svgsInPath, sprites);
199
+ const svgsSpriteFile = 'sprite.svg';
200
200
 
201
- return svgUtils.generateSvgsSprite(svgsInPath, svgsOutPath, svgsSpritePath);
201
+ return svgUtils.generateSvgsSprite(svgsInPath, svgsSpritePath, svgsSpriteFile);
202
202
  })
203
203
 
204
204
  .catch((e) => {
@@ -2,13 +2,50 @@
2
2
 
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
-
6
5
  const tools = require('./tools');
7
6
 
8
- module.exports.generateSvgsSprite = (svgsInPath, svgsOutPath, svgsSpritePath) => {
7
+ const writeSprite = (srcPath, files, destPath, outputFile) => {
8
+ const SVGSpriter = require('svg-sprite');
9
+
10
+ const spriter = new SVGSpriter({
11
+ destPath,
12
+ svg: { dimensionAttributes: true },
13
+ mode: {
14
+ symbol: {
15
+ dest: '',
16
+ sprite: outputFile,
17
+ },
18
+ },
19
+ });
20
+
21
+ files.forEach((file) => {
22
+ const filePath = path.resolve(srcPath, file);
23
+ spriter.add(
24
+ filePath,
25
+ file,
26
+ fs.readFileSync(filePath, { encoding: 'utf-8' })
27
+ );
28
+ });
29
+
30
+ spriter.compile((error, result) => {
31
+ Object.keys(result).forEach((mode) => {
32
+ Object.keys(result[mode]).forEach((resource) => {
33
+ fs.writeFileSync(
34
+ path.join(destPath, outputFile),
35
+ result[mode][resource].contents
36
+ );
37
+ });
38
+ });
39
+ });
40
+ };
41
+
42
+
43
+
44
+ module.exports.generateSvgsSprite = (svgsInPath, svgsSpritePath, svgsSpriteFile) => {
9
45
  const imagemin = require('imagemin');
10
46
  const imageminSvgo = require('imagemin-svgo');
11
- const svgstore = require('svgstore');
47
+
48
+ const svgsOutPath = path.join(svgsInPath, 'temp');
12
49
 
13
50
  let svgFiles;
14
51
 
@@ -17,7 +54,7 @@ module.exports.generateSvgsSprite = (svgsInPath, svgsOutPath, svgsSpritePath) =>
17
54
  return tools.rimraf(svgsOutPath);
18
55
  })
19
56
  .then(() => {
20
- return tools.remove(svgsSpritePath);
57
+ return tools.remove(path.join(svgsSpritePath, svgsSpriteFile));
21
58
  })
22
59
  .then(() => {
23
60
  return tools.getFilesGlob(svgsInPath, '**/*.svg');
@@ -53,16 +90,18 @@ module.exports.generateSvgsSprite = (svgsInPath, svgsOutPath, svgsSpritePath) =>
53
90
 
54
91
  tools.logInfo('Creating svg sprite');
55
92
 
56
- const sprites = svgstore();
57
93
 
58
- svgFiles.forEach((f) => {
59
- sprites.add(
60
- f.substr(0, f.indexOf('.svg')),
61
- fs.readFileSync(path.join(svgsOutPath, f), 'utf8')
62
- );
94
+ writeSprite(svgsOutPath, svgFiles, svgsSpritePath, svgsSpriteFile);
95
+
96
+ // generating json output list
97
+ const outList = svgFiles.map((f) => {
98
+ return f.substr(0, f.indexOf('.svg'));
63
99
  });
64
100
 
65
- tools.writeFileContent(svgsSpritePath, sprites);
101
+ const svgsSpriteFileJson = svgsSpriteFile.substr(0, svgsSpriteFile.indexOf('.svg')) + '.json';
102
+ console.log(svgsSpriteFileJson);
103
+
104
+ tools.writeJsonFileSync(path.join(svgsSpritePath, svgsSpriteFileJson), outList);
66
105
 
67
106
  tools.logSuccess(`OK => ${svgsSpritePath} generated`);
68
107
  })
@@ -350,9 +350,13 @@ function move(from, to) {
350
350
 
351
351
  function mkdirFilePath(filename) {
352
352
  const metadataFilePath = path.dirname(filename);
353
-
354
- if (!this.isDirExists(metadataFilePath)) {
355
- fs.mkdirSync(metadataFilePath, { recursive: true })
353
+ try {
354
+ if (!this.isDirExists(metadataFilePath)) {
355
+ fs.mkdirSync(metadataFilePath, { recursive: true })
356
+ }
357
+ } catch(e) {
358
+ if (e.code === 'EEXIST') return;
359
+ throw e;
356
360
  }
357
361
  }
358
362