Skip to content

Commit

Permalink
Merge pull request #44 from MKAbuMattar/canary
Browse files Browse the repository at this point in the history
modify: build
  • Loading branch information
MKAbuMattar authored Aug 21, 2022
2 parents 8b4f46d + ded221d commit 330202b
Show file tree
Hide file tree
Showing 14 changed files with 1,302 additions and 2,529 deletions.
6 changes: 4 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"presets": [
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript"
"babel-preset-minify"
],
"plugins": [
"@babel/plugin-transform-parameters"
]
}
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,12 @@ export default App
<p>Change size and color for icon</p>

```js
import { Aarch64Plain, ReactOriginal } from 'devicons-react'
import AndroidOriginal from 'devicons-react/lib/icons/AndroidOriginal'
import { Aarch64Plain } from 'devicons-react'

const App = () => {
return (
<>
<Aarch64Plain />
<ReactOriginal fill="red" height="500" width="500" />
<AndroidOriginal fill="#d35" height="128" width="128" />
<Aarch64Plain color="red" size="500" />
</>
)
}
Expand Down
47 changes: 17 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "devicons-react",
"version": "1.2.5-beta-0.0.3",
"version": "1.2.6-beta-0.0.1",
"description": "Devicons React is a collection of icons that symbolize programming languages, design tools, and development software.",
"keywords": [
"programming",
Expand Down Expand Up @@ -32,19 +32,16 @@
"clean:devicon": "rm -rf devicon",
"clean:svg": "rm -rf svg",
"clean:svg:devicon": "rm -rf ./svg/devicon-line-wordmark.svg ./svg/devicon-line.svg ./svg/devicon-original-wordmark.svg ./svg/devicon-original.svg ./svg/devicon-plain-wordmark.svg ./svg/devicon-plain.svg",
"clean:svgr:icons": "rm -rf build && mkdir build && touch build/index.ts",
"clean:svgr:index": "rm ./build/icons/index.ts",
"clean:lib": "rm -rf lib",
"clean": "yarn clean:devicon && yarn clean:svg && yarn clean:svgr:icons && yarn clean:lib",
"copy:svg:devicons-react": "cp ./src/assets/devicons-react-original.svg ./svg",
"build:config:clone": "yarn clean:devicon && node -r esbuild-runner/register src/config/gitclone.config.ts",
"build:config:recursive": "node -r esbuild-runner/register src/config/build.config.ts",
"build:generate:svg": "yarn clean:svg && node -r esbuild-runner/register src/generate/svg.generate.ts && yarn clean:svg:devicon && yarn copy:svg:devicons-react",
"build:generate:svgr": "yarn clean:svgr:icons && npx @svgr/cli --typescript --out-dir build/icons --index-template src/template/index.template.cjs -- svg && yarn clean:svgr:index",
"build:lib": "yarn clean:lib && rollup -c",
"build:clone:master": "yarn clean:devicon && node -r esbuild-runner/register src/config/gitclone.config.ts --master",
"build:clone:develop": "yarn clean:devicon && node -r esbuild-runner/register src/config/gitclone.config.ts --develop",
"build:svg:generate": "yarn clean:svg && node -r esbuild-runner/register src/generate/svg.generate.ts && yarn clean:svg:devicon && yarn copy:svg:devicons-react",
"build:jsx:script": "node -r esbuild-runner/register src/script/jsx.script.ts",
"build:data": "node -r esbuild-runner/register src/data/generate.data.ts",
"build:noclone": "yarn build:config:recursive && yarn build:generate:svg && yarn build:generate:svgr && yarn build:lib && yarn build:data",
"build": "yarn build:config:clone && yarn build:config:recursive && yarn build:generate:svg && yarn build:generate:svgr && yarn build:lib && yarn build:data",
"build:lib": "yarn clean:lib && babel build --out-dir lib --copy-files",
"build:dev": "yarn build:clone:develop && yarn build:svg:generate && yarn build:jsx:script && yarn build:data && yarn build:lib",
"build:prod": "yarn build:clone:master && yarn build:svg:generate && yarn build:jsx:script && yarn build:data && yarn build:lib",
"publish:lib:latest": "npm publish",
"publish:lib:beta": "npm publish --tag beta",
"publish:lib:canary": "npm publish --tag canary"
Expand All @@ -54,23 +51,18 @@
"react-dom": "^18.0.0"
},
"devDependencies": {
"@babel/cli": "7.18.10",
"@babel/core": "7.18.10",
"@babel/preset-env": "7.18.10",
"@babel/plugin-syntax-jsx": "7.18.6",
"@babel/plugin-transform-parameters": "7.18.8",
"@babel/preset-react": "7.18.6",
"@babel/preset-typescript": "7.18.6",
"@rollup/plugin-babel": "5.3.1",
"@rollup/plugin-commonjs": "22.0.2",
"@rollup/plugin-node-resolve": "13.3.0",
"@rollup/plugin-typescript": "8.3.4",
"@svgr/babel-plugin-remove-jsx-attribute": "6.3.1",
"@svgr/cli": "6.3.1",
"@types/fs-plus": "3.0.2",
"@types/node": "18.7.6",
"@types/jsdom": "20.0.0",
"@types/node": "18.7.9",
"@types/react": "18.0.17",
"@types/react-dom": "18.0.6",
"@typescript-eslint/eslint-plugin": "5.33.1",
"@typescript-eslint/parser": "5.33.1",
"babel-loader": "8.2.5",
"babel-preset-minify": "0.5.2",
"esbuild": "0.15.5",
"esbuild-runner": "2.2.1",
"eslint": "8.22.0",
Expand All @@ -79,17 +71,12 @@
"eslint-plugin-simple-import-sort": "7.0.0",
"eslint-plugin-unused-imports": "2.0.0",
"fs-plus": "3.1.1",
"husky": "8.0.1",
"postcss": "8.4.16",
"jsdom": "20.0.0",
"prettier": "2.7.1",
"react": "18.2.0",
"recursive-directory": "0.0.0-rc-0.0.4",
"rollup": "2.78.0",
"rollup-plugin-dts": "4.2.2",
"rollup-plugin-peer-deps-external": "2.2.4",
"rollup-plugin-postcss": "4.0.2",
"rollup-plugin-terser": "7.0.2",
"svg-to-jsx": "1.0.4",
"svgson": "5.2.1",
"tslib": "2.4.0",
"typescript": "4.7.4"
},
"sideEffects": false,
Expand Down
38 changes: 0 additions & 38 deletions rollup.config.js

This file was deleted.

15 changes: 0 additions & 15 deletions src/config/build.config.ts

This file was deleted.

16 changes: 10 additions & 6 deletions src/config/gitclone.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { exec } from 'child_process';

(() => {
const master = 'git clone https://github.com/devicons/devicon.git';
const develop =
'git clone -b develop https://github.com/devicons/devicon.git';

exec(develop, (error, stdout, stderr) => {
const gitClone = (url: string): void => {
exec(url, (error, stdout, stderr) => {
if (error) {
console.error(`error: ${error.message}`);
return;
Expand All @@ -16,4 +12,12 @@ import { exec } from 'child_process';
}
console.debug(`stdout: ${stdout}`);
});
};

(() => {
const master = 'git clone https://github.com/devicons/devicon.git';
const develop =
'git clone -b develop https://github.com/devicons/devicon.git';

process.argv[2] === '--master' ? gitClone(master) : gitClone(develop);
})();
6 changes: 4 additions & 2 deletions src/data/generate.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import DeviconData from '../../devicon/devicon.json';
const data: any = [];

fs.readdirSync(dir).forEach((file) => {
if (file.includes('.d.ts')) return;

name = file
.replace(/([A-Z])/g, ' $1')
.trim()
.replace('.tsx', '');
.replace('.jsx', '');

componentName = file.replace('.tsx', '');
componentName = file.replace('.jsx', '');

DeviconData.forEach((devicon) => {
if (
Expand Down
8 changes: 6 additions & 2 deletions src/generate/svg.generate.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import fs from 'fs-plus';
import path from 'path';
import { RecursiveDirectory, recursiveDirectory } from 'recursive-directory';
import { parse, stringify } from 'svgson';

import config from '../config/build.config.json';
(async () => {
const config: RecursiveDirectory = (await recursiveDirectory(
'./devicon/icons/',
true,
)) as RecursiveDirectory;

(() => {
const svgsComponentPath = path.join(process.cwd(), 'svg');

fs.removeSync(svgsComponentPath);
Expand Down
147 changes: 147 additions & 0 deletions src/script/jsx.script.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import fs from 'fs';
import fsAsync from 'fs/promises';
import { JSDOM } from 'jsdom';
import { RecursiveDirectory, recursiveDirectory } from 'recursive-directory';
import svgtojsx from 'svg-to-jsx';

import deviconData from '../../devicon/devicon.json';

type ObjConfig = {
fullpath: string;
filepath: string;
filename: string;
name: string;
dirname: string;
}[];

(async () => {
if (fs.existsSync(`${__dirname}/../../build`)) {
fs.rmSync(`${__dirname}/../../build`, { recursive: true });
}

const index: [string, string][] = [];
const objConfig: ObjConfig = [];

const config: RecursiveDirectory = (await recursiveDirectory(
'./svg/',
true,
)) as RecursiveDirectory;

config.forEach((item) => {
objConfig.push({
fullpath: item.fullpath,
filepath: item.filepath,
filename: item.filename,
name: item.filename
.split('-')
.map((el) => el.charAt(0).toUpperCase() + el.slice(1))
.join('')
.replace(/.svg/g, ''),
dirname: item.dirname,
});
});

await fsAsync.mkdir(`${__dirname}/../../build`);
await fsAsync.mkdir(`${__dirname}/../../build/icons`);

await Promise.all(
objConfig.map(async (entry) => {
const name = `${entry.name}`;

const icon = await fsAsync.readFile(
`${__dirname}/../../svg/${entry.filename}`,
);

const { document } = await new JSDOM(icon).window;

const dir = `${__dirname}/../../build/icons`;

const reactName = `${name}`;

index.push([reactName, `./icons/${reactName}`]);

const svg = document.getElementsByTagName('svg')[0];
svg.removeAttribute('width');
svg.removeAttribute('height');
svg.removeAttribute('xmlns:xlink');

const isPlain =
reactName.toLowerCase().includes('plain') ||
reactName.toLowerCase().includes('line');

let originalColor = '';

if (isPlain) {
deviconData.map((el) => {
if (entry.filename.toLowerCase().includes(el.name.toLowerCase())) {
originalColor = el.color;
}
});
}

if (isPlain) {
svg.removeAttribute('fill');
const elements = svg.getElementsByTagName('*');
for (let i = 0; i < elements.length; i++) {
const element = elements[i] as SVGElement;
element.removeAttribute('fill');
element.style.removeProperty('fill');
element.style.removeProperty('fill-rule');
element.style.removeProperty('fill-opacity');
}
}

const svgTemplate = `const React = require("react");
module.exports = function ${reactName}({size = "1rem", ${
isPlain ? `color = "${originalColor}",` : ''
} ...props}){
props = {
...props,
style: {
...(props.style ? props.style : {}),
width: size,
height: size,${
isPlain
? `
...(color ? { fill: color } : {} )`
: ''
}
}
}
return (${(await svgtojsx(svg.outerHTML)).replace(
'<svg',
'<svg {...props}',
)});
}`;

await fsAsync.writeFile(`${dir}/${reactName}.jsx`, svgTemplate);

const definitions = `import React from "react";
interface Props extends React.SVGProps<SVGElement> {
size?: number | string;${
isPlain
? `
color?: string;`
: ''
}
}
declare const ${reactName}: React.FunctionComponent<Props>;
export default ${reactName};`;

await fsAsync.writeFile(`${dir}/${reactName}.d.ts`, definitions);

await fsAsync.writeFile(
`${__dirname}/../../build/index.js`,
index.map((e) => `const ${e[0]} = require("${e[1]}")`).join(';\n') +
';\n' +
`module.exports = {${index.map((e) => e[0]).join(',')}}`,
);
await fsAsync.writeFile(
`${__dirname}/../../build/index.d.ts`,
index
.map((e) => `export { default as ${e[0]} } from "${e[1]}"`)
.join(';\n'),
);
}),
);
})();
Loading

1 comment on commit 330202b

@vercel
Copy link

@vercel vercel bot commented on 330202b Aug 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.