Skip to content

Commit

Permalink
Generate font directory from source files (#1101)
Browse files Browse the repository at this point in the history
* Generate font directory from source files

* Don't keep two eslint configs
  • Loading branch information
oblador committed Nov 24, 2019
1 parent 73f9b17 commit 49a6704
Show file tree
Hide file tree
Showing 13 changed files with 8,445 additions and 3,862 deletions.
25 changes: 25 additions & 0 deletions directory/.gitignore
@@ -0,0 +1,25 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

generated
68 changes: 68 additions & 0 deletions directory/README.md 100755 → 100644
@@ -0,0 +1,68 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `yarn start`

Runs the app in the development mode.<br />
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.<br />
You will also see any lint errors in the console.

### `yarn test`

Launches the test runner in the interactive watch mode.<br />
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `yarn build`

Builds the app for production to the `build` folder.<br />
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.<br />
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `yarn eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting

### Analyzing the Bundle Size

This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size

### Making a Progressive Web App

This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app

### Advanced Configuration

This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration

### Deployment

This section has moved here: https://facebook.github.io/create-react-app/docs/deployment

### `yarn build` fails to minify

This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
30 changes: 30 additions & 0 deletions directory/bin/generate-font-styles.js
@@ -0,0 +1,30 @@
#!/usr/bin/env node

const fs = require('fs');
const path = require('path');

const customFontMap = {
'FontAwesome5_Solid.ttf': 'FontAwesome5',
'FontAwesome5_Brands.ttf': 'FontAwesome5Brands',
};

const fontDirectory = path.resolve(__dirname, '../../Fonts');
const fontExtension = '.ttf';
const styles = fs
.readdirSync(fontDirectory)
.filter(f => path.extname(f) === fontExtension)
.map(file => ({
file,
fontFamily: customFontMap[file] || path.basename(file, fontExtension),
}))
.map(
({ file, fontFamily }) => `
@font-face {
font-family: '${fontFamily}';
src: url('./fonts/${file}') format('truetype');
}
`
)
.join('\n');

process.stdout.write(styles);
42 changes: 42 additions & 0 deletions directory/bin/generate-glyphmap-index.js
@@ -0,0 +1,42 @@
#!/usr/bin/env node

const fs = require('fs');
const path = require('path');

const glypmapDirectory = path.resolve(__dirname, '../../glyphmaps');
const glypmapExtension = '.json';

const fontAwesomeGlyphmap = require(path.join(
glypmapDirectory,
'FontAwesome5Free.json'
));
const fontAwesomeMeta = require(path.join(
glypmapDirectory,
'FontAwesome5Free_meta.json'
));
const pickGlyps = (glyps, glyphmap) =>
glyps.reduce((acc, glyp) => {
acc[glyp] = glyphmap[glyp];
return acc;
}, {});

const index = fs
.readdirSync(glypmapDirectory)
.filter(f => path.extname(f) === glypmapExtension)
.filter(f => !f.startsWith('FontAwesome5'))
.reduce(
(acc, file) => {
const name = path.basename(file, glypmapExtension);
acc[name] = require(path.join(glypmapDirectory, file));
return acc;
},
{
FontAwesome5: pickGlyps(fontAwesomeMeta.solid, fontAwesomeGlyphmap),
FontAwesome5Brands: pickGlyps(
fontAwesomeMeta.brands,
fontAwesomeGlyphmap
),
}
);

process.stdout.write(JSON.stringify(index, null, 2));
32 changes: 23 additions & 9 deletions directory/package.json
@@ -1,21 +1,35 @@
{
"name": "react-native-vector-icons-directory",
"version": "0.0.1",
"version": "0.1.0",
"private": true,
"homepage": "https://oblador.github.io/react-native-vector-icons",
"devDependencies": {
"gh-pages": "^1.0.0",
"react-scripts": "^0.8.4"
},
"dependencies": {
"lodash": "^4.14.0",
"react": "^15.3.2",
"react-dom": "^15.3.2"
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-scripts": "3.2.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"deploy": "npm run build && gh-pages -d build"
"generate-glyphmap-index": "mkdir -p src/generated && node bin/generate-glyphmap-index.js > src/generated/glyphmapIndex.json",
"generate-font-index": "mkdir -p src/generated/fonts && cp ../Fonts/*.ttf src/generated/fonts && node bin/generate-font-styles.js > src/generated/fonts.css",
"postinstall": "yarn generate-glyphmap-index && yarn generate-font-index"
},
"eslintConfig": {
"extends": "../.eslintrc"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
7 changes: 4 additions & 3 deletions directory/public/index.html 100755 → 100644
@@ -1,11 +1,12 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>react-native-vector-icons directory</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
Expand All @@ -14,8 +15,8 @@
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` in this folder.
To create a production bundle, use `npm run build`.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
75 changes: 1 addition & 74 deletions directory/src/App.css
@@ -1,77 +1,4 @@
@font-face {
font-family: 'AntDesign';
src: url('../../Fonts/AntDesign.ttf') format('truetype');
}

@font-face {
font-family: 'Entypo';
src: url('../../Fonts/Entypo.ttf') format('truetype');
}

@font-face {
font-family: 'EvilIcons';
src: url('../../Fonts/EvilIcons.ttf') format('truetype');
}

@font-face {
font-family: 'Feather';
src: url('../../Fonts/Feather.ttf') format('truetype');
}

@font-face {
font-family: 'FontAwesome';
src: url('../../Fonts/FontAwesome.ttf') format('truetype');
}

@font-face {
font-family: 'FontAwesome5';
src: url('../../Fonts/FontAwesome5_Solid.ttf') format('truetype');
}

@font-face {
font-family: 'FontAwesome5Brands';
src: url('../../Fonts/FontAwesome5_Brands.ttf') format('truetype');
}

@font-face {
font-family: 'Fontisto';
src: url('../../Fonts/Fontisto.ttf') format('truetype');
}

@font-face {
font-family: 'Foundation';
src: url('../../Fonts/Foundation.ttf') format('truetype');
}

@font-face {
font-family: 'Ionicons';
src: url('../../Fonts/Ionicons.ttf') format('truetype');
}

@font-face {
font-family: 'MaterialCommunityIcons';
src: url('../../Fonts/MaterialCommunityIcons.ttf') format('truetype');
}

@font-face {
font-family: 'MaterialIcons';
src: url('../../Fonts/MaterialIcons.ttf') format('truetype');
}

@font-face {
font-family: 'Octicons';
src: url('../../Fonts/Octicons.ttf') format('truetype');
}

@font-face {
font-family: 'SimpleLineIcons';
src: url('../../Fonts/SimpleLineIcons.ttf') format('truetype');
}

@font-face {
font-family: 'Zocial';
src: url('../../Fonts/Zocial.ttf') format('truetype');
}
@import url(./generated/fonts.css);

* {
-webkit-box-sizing: border-box;
Expand Down

0 comments on commit 49a6704

Please sign in to comment.