@spectrum-web-components/icons-workflow 1.0.1 → 1.0.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/bin/build.js DELETED
@@ -1,383 +0,0 @@
1
- /* eslint-disable @typescript-eslint/explicit-function-return-type */
2
- /*
3
- Copyright 2020 Adobe. All rights reserved.
4
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License. You may obtain a copy
6
- of the License at http://www.apache.org/licenses/LICENSE-2.0
7
-
8
- Unless required by applicable law or agreed to in writing, software distributed under
9
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
10
- OF ANY KIND, either express or implied. See the License for the specific language
11
- governing permissions and limitations under the License.
12
- */
13
-
14
- import fs from 'fs';
15
- import fg from 'fast-glob';
16
- import path from 'path';
17
- import { load } from 'cheerio';
18
- import prettier from 'prettier';
19
- import Case from 'case';
20
- import { fileURLToPath } from 'url';
21
-
22
- import systemsIconMapping from './icons-mapping.json' assert { type: 'json' };
23
-
24
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
25
-
26
- const rootDir = path.join(__dirname, '../../../');
27
-
28
- const disclaimer = `
29
- /*
30
- Copyright 2024 Adobe. All rights reserved.
31
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
32
- you may not use this file except in compliance with the License. You may obtain a copy
33
- of the License at http://www.apache.org/licenses/LICENSE-2.0
34
-
35
- Unless required by applicable law or agreed to in writing, software distributed under
36
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
37
- OF ANY KIND, either express or implied. See the License for the specific language
38
- governing permissions and limitations under the License.
39
- */`;
40
-
41
- const S1IConsPackageDir = '@adobe/spectrum-css-workflow-icons/dist/18';
42
- const S2IConsPackageDir =
43
- '@adobe/spectrum-css-workflow-icons-s2/dist/assets/svg';
44
- const keepColors = '';
45
-
46
- const ensureDirectoryExists = (dirPath) => {
47
- if (!fs.existsSync(dirPath)) {
48
- fs.mkdirSync(dirPath);
49
- }
50
- };
51
-
52
- const directories = [
53
- `${rootDir}packages/icons-workflow/src`,
54
- `${rootDir}packages/icons-workflow/src/icons`,
55
- `${rootDir}packages/icons-workflow/src/icons-s2`,
56
- `${rootDir}packages/icons-workflow/src/elements`,
57
- `${rootDir}packages/icons-workflow/icons`,
58
- ];
59
-
60
- directories.forEach(ensureDirectoryExists);
61
-
62
- fs.writeFileSync(
63
- path.join(rootDir, 'packages', 'icons-workflow', 'src', 'icons.ts'),
64
- disclaimer,
65
- 'utf-8'
66
- );
67
- fs.writeFileSync(
68
- path.join(rootDir, 'packages', 'icons-workflow', 'src', 'icons-s2.ts'),
69
- disclaimer,
70
- 'utf-8'
71
- );
72
- const manifestPath = path.join(
73
- rootDir,
74
- 'packages',
75
- 'icons-workflow',
76
- 'stories',
77
- 'icon-manifest.ts'
78
- );
79
- fs.writeFileSync(manifestPath, disclaimer, 'utf-8');
80
- let manifestImports = `import {
81
- html,
82
- TemplateResult
83
- } from '@spectrum-web-components/base';\r\n`;
84
- let manifestListings = `\r\nexport const iconManifest = [\r\n`;
85
-
86
- const defaultIconImport = `import { DefaultIcon as AlternateIcon } from '../DefaultIcon.js';\r\n`;
87
-
88
- // Temporary replacements for a few icon names that have different names in the new S2 icon set
89
- const replacements = {
90
- UnLink: 'Unlink',
91
- TextStrikeThrough: 'TextStrikethrough',
92
- ChevronDownSize300: 'ChevronDown',
93
- CheckmarkSize300: 'Checkmark',
94
- };
95
-
96
- // A function that process the raw svg name and returns the component name
97
- export const getComponentName = (i) => {
98
- let id = path
99
- .basename(i, '.svg')
100
- .replace(/^(S2_Icon_|S_)/, '')
101
- .replace(/(_20_N|_22x20_N|_18_N@2x)$/, '');
102
- if (i.startsWith('Ad')) {
103
- id = i.replace(/^Ad/, '') + 'Advert';
104
- }
105
- return Case.pascal(replacements[id] || id);
106
- };
107
-
108
- async function buildIcons(icons, tag, iconsNameList) {
109
- icons.forEach((i) => {
110
- const svg = fs.readFileSync(i, 'utf-8');
111
- let id = path
112
- .basename(i, '.svg')
113
- .replace('S2_Icon_', '')
114
- .replace('_20_N', '')
115
- .replace('_22x20_N', '');
116
- if (id.search(/^Ad[A-Z]/) !== -1) {
117
- id = id.replace(/^Ad/, '');
118
- id += 'Advert';
119
- }
120
-
121
- // use replacements for icons that have different names in the icon set and update the id
122
- id = replacements[id] || id;
123
-
124
- const ComponentName = Case.pascal(id);
125
-
126
- const $ = load(svg, {
127
- xmlMode: true,
128
- });
129
- const title = Case.capital(id);
130
- const fileName = `${id}.ts`;
131
- const location = path.join(
132
- rootDir,
133
- 'packages/icons-workflow/src',
134
- tag,
135
- fileName
136
- );
137
-
138
- if (!Number.isNaN(Number(ComponentName[0]))) {
139
- return;
140
- }
141
-
142
- $('*').each((index, el) => {
143
- if (el.name === 'svg') {
144
- $(el).attr('aria-hidden', '...');
145
- $(el).attr('role', 'img');
146
- if (keepColors !== 'keep') {
147
- $(el).attr('fill', 'currentColor');
148
- }
149
- $(el).attr('aria-label', '...');
150
- $(el).removeAttr('id');
151
- $(el).attr('width', '...');
152
- $(el).attr('height', '...');
153
- }
154
- if (el.name === 'defs') {
155
- $(el).remove();
156
- }
157
- Object.keys(el.attribs).forEach((x) => {
158
- if (x === 'class') {
159
- $(el).removeAttr(x);
160
- }
161
- if (keepColors !== 'keep' && x === 'stroke') {
162
- $(el).attr(x, 'currentColor');
163
- }
164
- if (keepColors !== 'keep' && x === 'fill') {
165
- $(el).attr(x, 'currentColor');
166
- }
167
- });
168
- });
169
-
170
- const iconLiteral = `
171
- ${disclaimer}
172
-
173
- import {tag as html, TemplateResult} from '../custom-tag.js';
174
-
175
- export {setCustomTemplateLiteralTag} from '../custom-tag.js';
176
- export const ${ComponentName}Icon = ({
177
- width = 24,
178
- height = 24,
179
- hidden = false,
180
- title = '${title}',
181
- } = {},): string | TemplateResult => {
182
- return html\`${$('svg')
183
- .toString()
184
- .replace(
185
- 'aria-hidden="..."',
186
- "aria-hidden=${hidden ? 'true' : 'false'}"
187
- )
188
- .replace('width="..."', 'width="${width}"')
189
- .replace('height="..."', 'height="${height}"')
190
- .replace('aria-label="..."', 'aria-label="${title}"')}\`;
191
- }
192
- `;
193
-
194
- prettier
195
- .format(iconLiteral, {
196
- printWidth: 100,
197
- tabWidth: 2,
198
- useTabs: false,
199
- semi: true,
200
- singleQuote: true,
201
- trailingComma: 'all',
202
- bracketSpacing: true,
203
- jsxBracketSameLine: false,
204
- arrowParens: 'avoid',
205
- parser: 'typescript',
206
- })
207
- .then((icon) => {
208
- fs.writeFileSync(location, icon, 'utf-8');
209
- });
210
-
211
- const exportString = `export {${ComponentName}Icon} from './${tag}/${id}.js';\r\n`;
212
- fs.appendFileSync(
213
- path.join(
214
- rootDir,
215
- 'packages',
216
- 'icons-workflow',
217
- 'src',
218
- tag + '.ts'
219
- ),
220
- exportString,
221
- 'utf-8'
222
- );
223
-
224
- const iconElementName = `sp-icon-${Case.kebab(ComponentName)}`;
225
-
226
- const currenVersionIconImport = `import { ${ComponentName}Icon as CurrentIcon } from '../${tag}/${id}.js';\r\n`;
227
-
228
- // check if the icon is present in the other version
229
- let otherVersionIconImport = defaultIconImport;
230
-
231
- const alternateTag = tag === 'icons' ? 'icons-s2' : 'icons';
232
- // if there is a mapping icon found from the above iconset update otherVersionIconImport
233
- if (systemsIconMapping[ComponentName]) {
234
- otherVersionIconImport = `import { ${systemsIconMapping[ComponentName]}Icon as AlternateIcon } from '../${alternateTag}/${systemsIconMapping[ComponentName]}.js';\r\n`;
235
- } else if (iconsNameList.includes(ComponentName)) {
236
- // if there is a no mapping icon found reset to DefaultIcon
237
- otherVersionIconImport = `import { ${ComponentName}Icon as AlternateIcon } from '../${alternateTag}/${id}.js';\r\n`;
238
- }
239
-
240
- const spectrumVersion = tag === 'icons' ? 1 : 2;
241
-
242
- const iconElement = `
243
- ${disclaimer}
244
-
245
- import {
246
- html,
247
- TemplateResult
248
- } from '@spectrum-web-components/base';
249
- import {
250
- IconBase
251
- } from '@spectrum-web-components/icon';
252
- import {
253
- setCustomTemplateLiteralTag
254
- } from '../custom-tag.js';
255
-
256
- ${currenVersionIconImport}
257
- ${otherVersionIconImport}
258
-
259
- /**
260
- * @element ${iconElementName}
261
- */
262
- export class Icon${ComponentName} extends IconBase {
263
- protected override render(): TemplateResult {
264
- setCustomTemplateLiteralTag(html);
265
-
266
- if(this.spectrumVersion === ${spectrumVersion}){
267
- return CurrentIcon({ hidden: !this.label, title: this.label }) as TemplateResult;
268
- }
269
- return AlternateIcon({ hidden: !this.label, title: this.label }) as TemplateResult;
270
-
271
- }
272
- }
273
- `;
274
-
275
- prettier
276
- .format(iconElement, {
277
- printWidth: 100,
278
- tabWidth: 2,
279
- useTabs: false,
280
- semi: true,
281
- singleQuote: true,
282
- trailingComma: 'all',
283
- bracketSpacing: true,
284
- jsxBracketSameLine: false,
285
- arrowParens: 'avoid',
286
- parser: 'typescript',
287
- })
288
- .then((iconElementFile) => {
289
- fs.writeFileSync(
290
- path.join(
291
- rootDir,
292
- 'packages',
293
- 'icons-workflow',
294
- 'src',
295
- 'elements',
296
- `Icon${id}.ts`
297
- ),
298
- iconElementFile,
299
- 'utf-8'
300
- );
301
- });
302
-
303
- const iconRegistration = `
304
- ${disclaimer}
305
-
306
- import { Icon${ComponentName} } from '../src/elements/Icon${id}.js';
307
- import { defineElement } from '@spectrum-web-components/base/src/define-element.js';
308
-
309
- defineElement('${iconElementName}', Icon${ComponentName});
310
-
311
- declare global {
312
- interface HTMLElementTagNameMap {
313
- '${iconElementName}': Icon${ComponentName};
314
- }
315
- }
316
- `;
317
-
318
- prettier
319
- .format(iconRegistration, {
320
- printWidth: 100,
321
- tabWidth: 2,
322
- useTabs: false,
323
- semi: true,
324
- singleQuote: true,
325
- trailingComma: 'all',
326
- bracketSpacing: true,
327
- jsxBracketSameLine: false,
328
- arrowParens: 'avoid',
329
- parser: 'typescript',
330
- })
331
- .then((iconRegistrationFile) => {
332
- fs.writeFileSync(
333
- path.join(
334
- rootDir,
335
- 'packages',
336
- 'icons-workflow',
337
- 'icons',
338
- `${iconElementName}.ts`
339
- ),
340
- iconRegistrationFile,
341
- 'utf-8'
342
- );
343
- });
344
-
345
- const importStatement = `\r\nimport '@spectrum-web-components/icons-workflow/icons/${iconElementName}.js';`;
346
- const metadata = `{name: '${Case.sentence(
347
- ComponentName
348
- )}', tag: '<${iconElementName}>', story: (size: string): TemplateResult => html\`<${iconElementName} size=\$\{size\}></${iconElementName}>\`},\r\n`;
349
- manifestImports += importStatement;
350
- manifestListings += metadata;
351
- });
352
- }
353
-
354
- const iconsV1 = (
355
- await fg(`${rootDir}/node_modules/${S1IConsPackageDir}/**.svg`)
356
- ).sort();
357
-
358
- const iconsV2 = (
359
- await fg(`${rootDir}/node_modules/${S2IConsPackageDir}/**.svg`)
360
- ).sort();
361
-
362
- const iconsV1NameList = iconsV1.map((i) => {
363
- return getComponentName(i);
364
- });
365
- const iconsV2NameList = iconsV2.map((i) => {
366
- return getComponentName(i);
367
- });
368
-
369
- await buildIcons(iconsV1, 'icons', iconsV2NameList);
370
- await buildIcons(iconsV2, 'icons-s2', iconsV1NameList);
371
-
372
- const exportString = `\r\nexport { setCustomTemplateLiteralTag } from './custom-tag.js';\r\n`;
373
- fs.appendFileSync(
374
- path.join(rootDir, 'packages', 'icons-workflow', 'src', 'icons.ts'),
375
- exportString,
376
- 'utf-8'
377
- );
378
-
379
- fs.appendFileSync(
380
- manifestPath,
381
- `${manifestImports}${manifestListings}];\r\n`,
382
- 'utf-8'
383
- );