@synergy-design-system/assets 1.11.1 → 1.11.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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [@synergy-design-system/assets-v1.11.2](https://github.com/synergy-design-system/synergy-design-system/compare/assets/1.11.1...assets/1.11.2) (2024-12-02)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * 🐛 Assets release process ([#700](https://github.com/synergy-design-system/synergy-design-system/issues/700)) ([c28647f](https://github.com/synergy-design-system/synergy-design-system/commit/c28647fa3fbde952e649c67bf7d98df6060ac78b))
7
+
1
8
  # [@synergy-design-system/assets-v1.11.1](https://github.com/synergy-design-system/synergy-design-system/compare/assets/1.11.0...assets/1.11.1) (2024-12-02)
2
9
 
3
10
 
@@ -0,0 +1,9 @@
1
+ import { defaultIcons } from './default-icons.js';
2
+ type IconKeys = keyof typeof defaultIcons;
3
+ /**
4
+ * Creates a SVG sprite sheet with the given icons.
5
+ * @param icons The icon keys to use
6
+ * @returns String representation of the SVG sprite sheet
7
+ */
8
+ export declare const createSpriteSheet: (icons: IconKeys[]) => string;
9
+ export {};
@@ -0,0 +1,24 @@
1
+ import { defaultIcons } from './default-icons.js';
2
+ /**
3
+ * Creates a SVG sprite sheet with the given icons.
4
+ * @param icons The icon keys to use
5
+ * @returns String representation of the SVG sprite sheet
6
+ */
7
+ export const createSpriteSheet = (icons) => {
8
+ const foundIcons = Object
9
+ .entries(defaultIcons)
10
+ .filter(([key]) => icons.includes(key));
11
+ const symbols = foundIcons
12
+ // Make sure to sort the icons by key always.
13
+ // This may prevent problems when saving the sheet in the filesystem
14
+ // and new items are added to the icons object.
15
+ .sort(([a], [b]) => a.localeCompare(b))
16
+ .map(([key, value]) => value
17
+ .replace('<svg', `<symbol id="${key}"`)
18
+ .replace('</svg>', '</symbol>'));
19
+ return `
20
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
21
+ ${symbols.join('\n\t')}
22
+ </svg>
23
+ `.trim();
24
+ };
@@ -0,0 +1,2 @@
1
+ #! /usr/bin/env node
2
+ export {};
@@ -0,0 +1,59 @@
1
+ #! /usr/bin/env node
2
+ /* eslint-disable no-console */
3
+ import { createSpriteSheet } from './createSpritesheet.js';
4
+ import { defaultIcons } from './default-icons.js';
5
+ /**
6
+ * Creates a help message for the CLI.
7
+ * @returns Help message
8
+ */
9
+ const helpMessage = (usageError = '') => `Usage: syn-create-spritesheet --icons=icon1,icon2,icon3
10
+
11
+ Creates a spritesheet string from a list of icons.
12
+ Each icon identifier is a valid icon name for an icon in the synergy icon library.
13
+
14
+ Using to save the spritesheet string to a file:
15
+ syn-create-spritesheet --icons=a,b,c > icons.svg
16
+
17
+ Please have a look at https://synergy-design-system.github.io/?path=/docs/icon-search--docs for icon names
18
+ ${usageError && `
19
+ Error: ${usageError}`}
20
+ `;
21
+ const args = process.argv.slice(2);
22
+ // Sanitize the arguments
23
+ const argumentsObject = args.reduce((acc, arg) => {
24
+ const [originalKey, originalValue] = arg.trim().split('=');
25
+ // Skip if the option does not have a value
26
+ if (!originalValue) {
27
+ return acc;
28
+ }
29
+ const key = originalKey.trim().replace(/^--/, '');
30
+ const finalValue = originalValue.includes(',') || key === 'icons'
31
+ ? originalValue.split(',').map((icon) => icon.trim())
32
+ : originalValue.trim();
33
+ acc[key] = finalValue;
34
+ return acc;
35
+ }, {});
36
+ if (args.length === 0) {
37
+ console.log(helpMessage('Please provide at least one icon.'));
38
+ process.exit(1);
39
+ }
40
+ // Check if the icons are valid
41
+ const allowedIconNames = Object.keys(defaultIcons);
42
+ const { icons } = argumentsObject;
43
+ if (!icons || icons.length === 0) {
44
+ console.log(helpMessage('Please provide at least one icon.'));
45
+ process.exit(2);
46
+ }
47
+ const validIcons = icons.filter((icon) => allowedIconNames.includes(icon));
48
+ if (validIcons?.length !== icons.length) {
49
+ const invalidIcons = icons.filter((icon) => !allowedIconNames.includes(icon));
50
+ console.log(helpMessage(`
51
+ Some icons are not valid!
52
+ The following icons could not be detected:
53
+ - ${invalidIcons.join('\n\t- ')}
54
+
55
+ Please remove them and try again, e.g. by using the following command: syn-create-spritesheet --icons=${validIcons.join(',')}`));
56
+ process.exit(-3);
57
+ }
58
+ console.log(createSpriteSheet(validIcons));
59
+ process.exit(0);