@ecoportal/icons 0.0.2 → 1.0.1
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/README.md +25 -0
- package/dist/index.js +1 -1
- package/package.json +5 -7
- package/src/icons.js +69 -0
- package/tsconfig.json +1 -1
- package/webpack.config.js +29 -1
- package/dist/images.d.ts +0 -8
- package/dist/index.d.ts +0 -15
- package/src/index.ts +0 -6
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecoportal/icons",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Icons for the EcoPortal design system",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "webpack",
|
|
8
|
+
"build": "rm -rf dist && mkdir dist && cp -r ./src/types ./dist/types && tsc && webpack",
|
|
9
|
+
"icons": "yarn node src/icons.js",
|
|
9
10
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
10
11
|
},
|
|
11
12
|
"keywords": [
|
|
@@ -20,6 +21,7 @@
|
|
|
20
21
|
"@babel/plugin-transform-react-jsx": "^7.0.0",
|
|
21
22
|
"@babel/preset-env": "^7.21.4",
|
|
22
23
|
"@babel/preset-react": "^7.18.6",
|
|
24
|
+
"@svgr/webpack": "^7.0.0",
|
|
23
25
|
"@types/react": "^18.0.37",
|
|
24
26
|
"babel-loader": "^9.1.2",
|
|
25
27
|
"babel-plugin-react-svg": "^3.0.0",
|
|
@@ -30,9 +32,5 @@
|
|
|
30
32
|
"webpack-cli": "^5.0.1"
|
|
31
33
|
},
|
|
32
34
|
"author": "EcoPortal",
|
|
33
|
-
"license": "ISC"
|
|
34
|
-
"dependencies": {
|
|
35
|
-
"@ecoportal/icons": "0.0.1",
|
|
36
|
-
"@svgr/webpack": "^7.0.0"
|
|
37
|
-
}
|
|
35
|
+
"license": "ISC"
|
|
38
36
|
}
|
package/src/icons.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { promisify } = require('util');
|
|
6
|
+
const readdir = promisify(fs.readdir);
|
|
7
|
+
const writeFile = promisify(fs.writeFile);
|
|
8
|
+
|
|
9
|
+
function toCamelCase(str) {
|
|
10
|
+
let words = str
|
|
11
|
+
.replace(/[^a-zA-Z0-9]/g, ' ')
|
|
12
|
+
.toLowerCase()
|
|
13
|
+
.split(' ');
|
|
14
|
+
let camelCase = words
|
|
15
|
+
.map((word, index) => {
|
|
16
|
+
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
17
|
+
})
|
|
18
|
+
.join('');
|
|
19
|
+
return camelCase;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const formatName = (filename, category) => {
|
|
23
|
+
// Remove - (dash) from filename
|
|
24
|
+
let name = toCamelCase(path.parse(filename).name);
|
|
25
|
+
// capitalize first letter
|
|
26
|
+
name = category + name.charAt(0).toUpperCase() + name.substring(1);
|
|
27
|
+
|
|
28
|
+
// Needed for strings that start with number
|
|
29
|
+
name = /^\d/.test(name) ? `A${name}` : name;
|
|
30
|
+
return `Ep${name}`;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const getImportTemplate = (filename, category) => {
|
|
34
|
+
return `import ${formatName(
|
|
35
|
+
filename,
|
|
36
|
+
category
|
|
37
|
+
)} from './icons/${category}/${filename}'\n`;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const joinLines = (importsArray, exportsArray) => {
|
|
41
|
+
let result = importsArray.join('');
|
|
42
|
+
result += '\nexport {\n';
|
|
43
|
+
result += exportsArray.join(',\n');
|
|
44
|
+
result += '\n}';
|
|
45
|
+
return result;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const createFileFrom = async (source, target) => {
|
|
49
|
+
const importsArray = [];
|
|
50
|
+
const exportsArray = [];
|
|
51
|
+
// read dir with categories folders
|
|
52
|
+
const categories = await readdir(source);
|
|
53
|
+
await Promise.all(
|
|
54
|
+
categories.map(async (category) => {
|
|
55
|
+
const files = await readdir(`${source}/${category}`);
|
|
56
|
+
files.forEach((file) => {
|
|
57
|
+
importsArray.push(getImportTemplate(file, category));
|
|
58
|
+
exportsArray.push(formatName(file, category));
|
|
59
|
+
});
|
|
60
|
+
})
|
|
61
|
+
);
|
|
62
|
+
const result = joinLines(
|
|
63
|
+
[...new Set(importsArray)],
|
|
64
|
+
[...new Set(exportsArray)]
|
|
65
|
+
);
|
|
66
|
+
await writeFile(target, result);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
createFileFrom('./src/icons', './src/index.ts');
|
package/tsconfig.json
CHANGED
package/webpack.config.js
CHANGED
|
@@ -16,7 +16,35 @@ module.exports = {
|
|
|
16
16
|
},
|
|
17
17
|
{
|
|
18
18
|
test: /\.svg$/,
|
|
19
|
-
use: [
|
|
19
|
+
use: [
|
|
20
|
+
{
|
|
21
|
+
loader: '@svgr/webpack',
|
|
22
|
+
options: {
|
|
23
|
+
prettier: false,
|
|
24
|
+
svgo: true,
|
|
25
|
+
svgoConfig: {
|
|
26
|
+
plugins: [
|
|
27
|
+
{ name: 'removeViewBox', active: false },
|
|
28
|
+
{
|
|
29
|
+
name: 'addAttributesToSVGElement',
|
|
30
|
+
params: {
|
|
31
|
+
attributes: [
|
|
32
|
+
{
|
|
33
|
+
viewBox: '0 0 24 24',
|
|
34
|
+
width: 24,
|
|
35
|
+
height: 24,
|
|
36
|
+
fill: 'currentColor',
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
titleProp: true,
|
|
44
|
+
ref: true,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
],
|
|
20
48
|
},
|
|
21
49
|
],
|
|
22
50
|
},
|
package/dist/images.d.ts
DELETED
package/dist/index.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import AncientGateFill from './src/icons/Buildings/ancient-gate-fill.svg';
|
|
3
|
-
import AncientPavilionFill from './icons/Buildings/ancient-pavilion-fill.svg';
|
|
4
|
-
export { AncientGateFill, AncientPavilionFill };
|
|
5
|
-
declare const _default: {
|
|
6
|
-
AncientGateFill: import('react').ForwardRefRenderFunction<
|
|
7
|
-
HTMLOrSVGElement,
|
|
8
|
-
import('react').SVGProps<SVGSVGElement>
|
|
9
|
-
>;
|
|
10
|
-
AncientPavilionFill: import('react').ForwardRefRenderFunction<
|
|
11
|
-
HTMLOrSVGElement,
|
|
12
|
-
import('react').SVGProps<SVGSVGElement>
|
|
13
|
-
>;
|
|
14
|
-
};
|
|
15
|
-
export default _default;
|
package/src/index.ts
DELETED