Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ee5d779
Add git ignore file
Oct 2, 2020
fb5ac91
Add package files
Oct 2, 2020
7ffbc05
Add React SVG prop type
Oct 2, 2020
20c982a
Add component generator
Oct 2, 2020
df815d6
Updated readme.md
Oct 2, 2020
a67a56b
Add license
Oct 2, 2020
295a8b4
Set axios as dev dependency
Oct 2, 2020
2e3757d
Add build instructor to readme.md
Oct 2, 2020
20f9e58
Add clean script to package.json
Oct 2, 2020
a8fc593
Add clean script description to readme.md
Oct 2, 2020
bd2bf5a
Add index generation to generator.js
Oct 2, 2020
e87258f
Add eslint config file to the project root
Oct 5, 2020
4d3513b
Add prettier config file to project root
Oct 5, 2020
5232fb9
Add jest config file to project root
Oct 5, 2020
497f760
Add typescript config file to project root
Oct 5, 2020
daac250
Updated git ignore file
Oct 5, 2020
e0f7e78
Renamed generator to bootstrapper.js and move it into source folder
Oct 5, 2020
815ef0a
Update files in package.json
Oct 5, 2020
0dcdee2
Updated readme.md with required changes
Oct 5, 2020
69c90f7
Removed unused tsconfig.json
Oct 5, 2020
202fe22
Removed static types.ts. Replaces with generated one
Oct 5, 2020
4574a61
Added additional build command to readme.md
Oct 5, 2020
26205f5
Fixed lint error
Oct 5, 2020
7b2369f
Renamed component generator from bootstrapper.js to generator.js
Oct 5, 2020
b185076
Add git ignore to keep src folder
Oct 5, 2020
0cff09d
Add typescript compiler config file
Oct 5, 2020
87e2b61
Cleanup readme.md
Oct 5, 2020
f10c073
Add react as peer dependency and changed some scripts
Oct 5, 2020
5fd82c9
Exclude tests in ts compiler config
Oct 5, 2020
291c9c6
Fixed typo in readme.md
Oct 5, 2020
89f8e52
Split keywords
Oct 5, 2020
9607952
Fixed typo in package.json
Oct 5, 2020
a1b412e
Fixed typo in readme.md
Oct 5, 2020
87bfcfb
Fixed formatting issue in readme.md
Oct 5, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# IDE Stuff
.idea

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would add more files. Maybe you can adopt the structure from the other packages:

https://github.com/aboutbits/pagination/blob/master/.gitignore

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have added the required fields



# Node and Javascirpt
node_modules
1 change: 1 addition & 0 deletions components/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type IconProps = React.SVGProps<SVGSVGElement>
116 changes: 116 additions & 0 deletions generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
const axios = require('axios');
const fs = require('fs');
const path = require('path');

// Base url for icons
const iconURL = "https://fonts.google.com/metadata/icons";

/**
* Format name.
* Covert from snake case to camel case and prevent numbers at the beginning
*
* @param string - String to format
* @returns {string} - Formatted string
*/
function formatName(string) {
const formattedString = string
.replace(/_/g, ' ')
.replace(/\w\S*/g, (txt) => {
return txt
.charAt(0)
.toUpperCase() + txt.substr(1)
.toLowerCase();
})
.replace(/ /g, '');
return 'Icon' + formattedString;
}


/**
* Component template for functional react icon component
*
* @param name - Component name
* @param svg - Icon SVG
* @returns {string} - Component
*/
function componentTemplate(name, svg) {
let component = "import React from 'react'\n";
component += "import { IconProps } from './types'\n";
component += `const ${name}: React.FC<IconProps> = (props) => (`;
component += svg + ")\n\n";
component += `export { ${name} }`;

return component;

}

/**
* Generate React Icon components
*
* @param icon - Icon object
*/
function generateComponent(icon) {
icon.forEach(async c => {
const name = formatName(c.name);
const svg = await getSVGFile(c.name, c.version);

fs.writeFileSync(
path.join(__dirname, './components', `${name}.tsx`),
componentTemplate(name, svg)
)
});
}

/**
* Generate index tsx file for easy import
*
* @param icons - Array of icons
*/
function generateIndex(icons) {
let imports = "";
let exports = "export {\n";

icons.forEach(icon => {
const name = formatName(icon.name)
imports += `import { ${name} } from './components/${name}'\n`
exports += `\t${name},\n`
});
exports += "}";

fs.writeFileSync(
"./index.tsx",
(imports + "\n" + exports)
);
}

/**
* Get SVG data form google static fonts api
*
* @param icon - Icon name
* @param version - Icon Version
* @returns {Promise<any>} - SVG Data
*/
async function getSVGFile(icon, version) {
const svg = await axios.get(`https://fonts.gstatic.com/s/i/materialicons/${icon}/v${version}/24px.svg`);

return svg
.data
.replace('height="24"', '')
.replace('width="24"', '{...props}');
}


(async () => {
// Get icon information from google fonts
const res = await axios.get(iconURL);
// remove )]}' from the response
const data = res.data.substring(4);

// Parse response from json to js object
const icons = await JSON.parse(data);

// Generate icon components and Index
await generateComponent(icons.icons);
await generateIndex(icons.icons);

})();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would add an empty line at the end of the file.

9 changes: 9 additions & 0 deletions license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


Copyright About Bits GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "material-design-icons-crawler",
"version": "1.0.0",
"description": "",
"main": "generator.js",
"scripts": {
"build": "node generator.js",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Attention, the build command is a reserved command that will be used when you execute "npm version patch/minor/major". That's why I would rename this command to something more explicitly named like "import".

In addition, in this file lots of required dependencies and scripts are missing. They are required for publishing the package. See: https://github.com/aboutbits/pagination/blob/master/package.json

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

All necessary fields have been added. Since tsc is not required for this package, the build command executes the bootstrapping command to create the icon components

"clean": "rm components/*.tsx && rm index.tsx"
},
"devDependencies": {
"axios": "^0.20.0"
},
"keywords": [],
"author": "",
"license": "ISC"
}
65 changes: 65 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,67 @@
React Material Icons
====================

This package includes all [Material Icons](https://material.io/resources/icons/?style=baseline) as reusable react components

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would write "react" as "React", because it's the right way to write it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

All names have been updated


## Table of content
- [Usage](#usage)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add consistent empty lines before and after titles and paragraphs like in the other packages: https://raw.githubusercontent.com/aboutbits/pagination/master/readme.md

- [Build & Publish](#build--publish)
- [Information](#information)

## Usage

In order to use this package you have to install it through npm

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would use here the same wording like in the other packages: First, ...

```bash
npm install @aboutbits/react-material-icons
```

After you successfully installed the package you can simply use the icons in you react application like this
```jsx
import React from 'react'

const MyCommponent = () => {
return (
<IconCached />
);
}
```

SVG related parameters like height and width can be passed as props

## Build & Publish

To build the package, simply run the following command

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would extract the description of the build/clean command into it's own section. And keep the "Build & Publish" section equals to the other packages.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Build and clean have got an own section.

```bash
npm run build
```

To publish the package commit all changes and push them to master. Then run one of the following commands locally:
```bash
npm version patch
npm version minor
npm version major
```

To remove all generated files run the clean script

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should the user be able to clean the generated files? Or should they be automatically be deleted as first step of the generation? For example, first delete the src folder and then regenerate the files in there.

The clean task that you mention here, is to delete the dist folder. And the dist folder is just required for publishing.

```bash
npm run clean
```

## Information

About Bits is a company based in South Tyrol, Italy. You can find more information about us on [our website](https://aboutbits.it).

### Support

For support, please contact [info@aboutbits.it](mailto:info@aboutbits.it).

### Credits

- [Simon Planinschek](https://github.com/stplasim)
- [Alex Lanz](https://github.com/alexlanz)
- [Martin Malfertheiner](https://github.com/mmalfertheiner)
- [All Contributors](../../contributors)

### License

The MIT License (MIT). Please see the [license file](license.md) for more information.