@utrecht/web-component-library-stencil 1.0.0-alpha.274 → 1.0.0-alpha.275
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,9 +1,9 @@
|
|
|
1
1
|
/* eslint-env node */
|
|
2
|
-
const fs = require('fs');
|
|
3
2
|
const lodash = require('lodash');
|
|
4
3
|
const argv = require('minimist')(process.argv.slice(2), {
|
|
5
4
|
string: ['prefix', 'path'],
|
|
6
5
|
});
|
|
6
|
+
const { readdir, readFile, writeFile, mkdir } = require('node:fs/promises');
|
|
7
7
|
const path = require('path');
|
|
8
8
|
const { component, test, generateIconsName, style, iconContainerComponent } = require('./component_templates.js');
|
|
9
9
|
|
|
@@ -11,70 +11,73 @@ const { kebabCase } = lodash;
|
|
|
11
11
|
const componentPrefix = `${argv.prefix}-`;
|
|
12
12
|
const componentsPath = argv.path;
|
|
13
13
|
const iconRapperComponent = `${componentPrefix}container`;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const directoryPath = path.join(__dirname, '../tmp/optimized-svgs');
|
|
26
|
-
|
|
27
|
-
fs.readdir(directoryPath, function (err, files) {
|
|
28
|
-
//handling error
|
|
29
|
-
if (err) {
|
|
30
|
-
console.error('Unable to scan directory: ' + err);
|
|
31
|
-
return;
|
|
14
|
+
const cwd = path.resolve(process.cwd(), 'tmp/optimized-svgs');
|
|
15
|
+
|
|
16
|
+
const readSVGDir = async () => {
|
|
17
|
+
let files;
|
|
18
|
+
try {
|
|
19
|
+
files = await readdir(cwd);
|
|
20
|
+
return files;
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.error(error);
|
|
32
23
|
}
|
|
24
|
+
return files;
|
|
25
|
+
};
|
|
33
26
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (err) {
|
|
46
|
-
console.error(err);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// throw an error if the file already exists
|
|
51
|
-
if (fs.existsSync(dir)) throw new Error('A component with that name already exists.');
|
|
52
|
-
|
|
53
|
-
// create the folder
|
|
54
|
-
fs.mkdirSync(dir);
|
|
55
|
-
fs.writeFile(
|
|
56
|
-
`${dir}/${formattedName}.stencil.tsx`,
|
|
57
|
-
component(fileName, svg, iconRapperComponent),
|
|
58
|
-
writeFileErrorHandler,
|
|
27
|
+
const getIconData = async () => {
|
|
28
|
+
let svgData;
|
|
29
|
+
|
|
30
|
+
const files = await readSVGDir();
|
|
31
|
+
try {
|
|
32
|
+
if (files && files.length > 0) {
|
|
33
|
+
svgData = await Promise.all(
|
|
34
|
+
files.map((file) => ({
|
|
35
|
+
id: `${componentPrefix}${kebabCase(path.parse(file).name)}`,
|
|
36
|
+
src: file,
|
|
37
|
+
})),
|
|
59
38
|
);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return stats ? stats.isDirectory() : false;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const outputDir = path.resolve(__dirname, '../dist/');
|
|
39
|
+
}
|
|
40
|
+
} catch (error) {
|
|
41
|
+
console.error(error);
|
|
42
|
+
}
|
|
43
|
+
return svgData;
|
|
44
|
+
};
|
|
70
45
|
|
|
71
|
-
|
|
72
|
-
|
|
46
|
+
const writeComponentFile = async () => {
|
|
47
|
+
try {
|
|
48
|
+
const files = await readSVGDir();
|
|
49
|
+
if (files && files.length > 0) {
|
|
50
|
+
for (const file of files) {
|
|
51
|
+
const fileBasename = path.parse(file).name;
|
|
52
|
+
const fileName = `${componentPrefix}${kebabCase(fileBasename)}`;
|
|
53
|
+
const formattedName = kebabCase(fileName);
|
|
54
|
+
const svg = await readFile(`${cwd}/${file}`, 'utf-8');
|
|
55
|
+
|
|
56
|
+
await mkdir(`${componentsPath}/${formattedName}`, { recursive: true });
|
|
57
|
+
await writeFile(
|
|
58
|
+
`${componentsPath}/${formattedName}/${formattedName}.stencil.tsx`,
|
|
59
|
+
component(fileName, svg, iconRapperComponent),
|
|
60
|
+
'utf-8',
|
|
61
|
+
);
|
|
62
|
+
await writeFile(`${componentsPath}/${formattedName}/${formattedName}.spec.tsx`, test(fileName), 'utf-8');
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
console.log('There is no SVG files');
|
|
66
|
+
}
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error(error);
|
|
73
69
|
}
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
};
|
|
71
|
+
writeComponentFile();
|
|
72
|
+
|
|
73
|
+
const generateIconsNameFile = async () => {
|
|
74
|
+
const data = await getIconData();
|
|
75
|
+
await mkdir('dist', { recursive: true });
|
|
76
|
+
await writeFile(path.resolve(process.cwd(), 'dist/index.json'), generateIconsName(data), 'utf-8');
|
|
77
|
+
};
|
|
78
|
+
generateIconsNameFile();
|
|
76
79
|
|
|
77
|
-
const createIconWrapperComponent = () => {
|
|
80
|
+
const createIconWrapperComponent = async () => {
|
|
78
81
|
const dir = `${componentsPath}/${iconRapperComponent}`;
|
|
79
82
|
const cssValue = `.${iconRapperComponent} {
|
|
80
83
|
display: inline-block;
|
|
@@ -82,13 +85,13 @@ const createIconWrapperComponent = () => {
|
|
|
82
85
|
width: var(--${componentPrefix}size);
|
|
83
86
|
height: var(--${componentPrefix}size);
|
|
84
87
|
}`;
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
await mkdir(dir, { recursive: true });
|
|
89
|
+
await writeFile(
|
|
87
90
|
`${dir}/${iconRapperComponent}.stencil.tsx`,
|
|
88
91
|
iconContainerComponent(iconRapperComponent, '<slot/>'),
|
|
89
|
-
|
|
92
|
+
'utf-8',
|
|
90
93
|
);
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
await writeFile(`${dir}/${iconRapperComponent}.space.tsx`, test(iconRapperComponent), 'utf-8');
|
|
95
|
+
await writeFile(`${dir}/${iconRapperComponent}.scss`, style(cssValue), 'utf-8');
|
|
93
96
|
};
|
|
94
97
|
createIconWrapperComponent();
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.0-alpha.
|
|
2
|
+
"version": "1.0.0-alpha.275",
|
|
3
3
|
"author": "Community for NL Design System",
|
|
4
4
|
"description": "Stencil component library bundle for the Municipality of Utrecht based on the NL Design System architecture",
|
|
5
5
|
"license": "EUPL-1.2",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"watch:stencil": "chokidar --follow-symlinks --initial --command \"npm run build:stencil\" \"../../components/**/*.(js|jsx|ts|tsx)\"",
|
|
56
56
|
"generate": "stencil generate"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "69293ba78ef6d673f82ef2dce10a8e7650c87ac3"
|
|
59
59
|
}
|