Skip to content

Commit

Permalink
⬆️ 1.0.0 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
IonicaBizau committed May 29, 2018
1 parent 4c0f9a6 commit e851ee9
Show file tree
Hide file tree
Showing 7 changed files with 357 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.swp
*.swo
*~
*.log
node_modules
*.env
.DS_Store
package-lock.json
66 changes: 66 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# :eight_spoked_asterisk: :stars: :sparkles: :dizzy: :star2: :star2: :sparkles: :dizzy: :star2: :star2: Contributing :star: :star2: :dizzy: :sparkles: :star: :star2: :dizzy: :sparkles: :stars: :eight_spoked_asterisk:

So, you want to contribute to this project! That's awesome. However, before
doing so, please read the following simple steps how to contribute. This will
make the life easier and will avoid wasting time on things which are not
requested. :sparkles:

## Discuss the changes before doing them
- First of all, open an issue in the repository, using the [bug tracker][1],
describing the contribution you would like to make, the bug you found or any
other ideas you have. This will help us to get you started on the right
foot.

- If it makes sense, add the platform and software information (e.g. operating
system, Node.JS version etc.), screenshots (so we can see what you are
seeing).

- It is recommended to wait for feedback before continuing to next steps.
However, if the issue is clear (e.g. a typo) and the fix is simple, you can
continue and fix it.

## Fixing issues
- Fork the project in your account and create a branch with your fix:
`some-great-feature` or `some-issue-fix`.

- Commit your changes in that branch, writing the code following the
[code style][2]. If the project contains tests (generally, the `test`
directory), you are encouraged to add a test as well. :memo:

- If the project contains a `package.json` or a `bower.json` file add yourself
in the `contributors` array (or `authors` in the case of `bower.json`;
if the array does not exist, create it):

```json
{
"contributors": [
"Your Name <and@email.address> (http://your.website)"
]
}
```

## Creating a pull request

- Open a pull request, and reference the initial issue in the pull request
message (e.g. *fixes #<your-issue-number>*). Write a good description and
title, so everybody will know what is fixed/improved.

- If it makes sense, add screenshots, gifs etc., so it is easier to see what
is going on.

## Wait for feedback
Before accepting your contributions, we will review them. You may get feedback
about what should be fixed in your modified code. If so, just keep committing
in your branch and the pull request will be updated automatically.

## Everyone is happy!
Finally, your contributions will be merged, and everyone will be happy! :smile:
Contributions are more than welcome!

Thanks! :sweat_smile:



[1]: https://github.com/IonicaBizau/google-font-downloader/issues

[2]: https://github.com/IonicaBizau/code-style
15 changes: 15 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Documentation

You can see below the API reference of this module.

### `googleFontDownloader(a, b)`
Download Google fonts by providing the url

#### Params

- **Number** `a`: Param descrpition.
- **Number** `b`: Param descrpition.

#### Return
- **Number** Return description.

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2018 Ionică Bizău <bizauionica@gmail.com> (https://ionicabizau.net)

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.
141 changes: 141 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<!-- Please do not edit this file. Edit the `blah` field in the `package.json` instead. If in doubt, open an issue. -->


# `$ google-font-downloader`

[![Support me on Patreon][badge_patreon]][patreon] [![Buy me a book][badge_amazon]][amazon] [![PayPal][badge_paypal_donate]][paypal-donations] [![Ask me anything](https://img.shields.io/badge/ask%20me-anything-1abc9c.svg)](https://github.com/IonicaBizau/ama) [![Version](https://img.shields.io/npm/v/google-font-downloader.svg)](https://www.npmjs.com/package/google-font-downloader) [![Downloads](https://img.shields.io/npm/dt/google-font-downloader.svg)](https://www.npmjs.com/package/google-font-downloader)

> Download Google fonts by providing the url
#### Usage


You can use this tool to download Google Fonts for offline use, just by providing the Google APIs url.


:bulb: **Note**: It's not clear yet if Google Fonts are EU GDPR compliant (see [this issue](https://github.com/google/fonts/issues/1495)). This may be a good reason to download the Google Fonts you use on your server.

#### How it works


You need to provide the url to the Google APIs endpoint (e.g. `https://fonts.googleapis.com/css?family=Open+Sans:400,400i,700,700i`) and you will get the following files/directories in the current working directory:


- A file named `google-fonts-<timestamp>.css—this will contain the CSS snippets that you need to copy in your app. You may need to update the paths to the font files.
- A directory structure looking like this: `fonts/<font-name>/<version>/<font-file>`


## :cloud: Installation

You can install the package globally and use it as command line tool:


```sh
# Using npm
npm install --global google-font-downloader

# Using yarn
yarn global add google-font-downloader
```


Then, run `google-font-downloader --help` and see what the CLI tool can do.


```
$ google-font-downloader --help
Usage: google-font-downloader <url> [options]
Download Google fonts by providing the url
Command arguments:
<url> The Google APIs url.
Options:
-v, --version Displays version information.
-h, --help Displays this help.
Examples:
$ google-font-downloader https://fonts.googleapis.com/css?family=Open+Sans:400,400i,700,700i
Documentation can be found at https://github.com/IonicaBizau/google-font-downloader#readme.
```

## :clipboard: Example


Here is an example how to use this package as library. To install it locally, as library, you can do that using `npm` (or `yarn`):

```sh
# Using npm
npm install --save google-font-downloader

# Using yarn
yarn add google-font-downloader
```



```js
const googleFontDownloader = require("google-font-downloader");

console.log(googleFontDownloader());
```



## :question: Get Help

There are few ways to get help:

1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long you add a link to your Stack Overflow question.
2. For bug reports and feature requests, open issues. :bug:

3. For direct and quick help, you can [use Codementor](https://www.codementor.io/johnnyb). :rocket:



## :memo: Documentation

For full API reference, see the [DOCUMENTATION.md][docs] file.

## :yum: How to contribute
Have an idea? Found a bug? See [how to contribute][contributing].


## :sparkling_heart: Support my projects

I open-source almost everything I can, and I try to reply everyone needing help using these projects. Obviously,
this takes time. You can integrate and use these projects in your applications *for free*! You can even change the source code and redistribute (even resell it).

However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:

- Starring and sharing the projects you like :rocket:
- [![Buy me a book][badge_amazon]][amazon]—I love books! I will remember you after years if you buy me one. :grin: :book:
- [![PayPal][badge_paypal]][paypal-donations]—You can make one-time donations via PayPal. I'll probably buy a ~~coffee~~ tea. :tea:
- [![Support me on Patreon][badge_patreon]][patreon]—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).
- **Bitcoin**—You can send me bitcoins at this address (or scanning the code below): `1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6`

![](https://i.imgur.com/z6OQI95.png)

Thanks! :heart:



## :scroll: License

[MIT][license] © [Ionică Bizău][website]

[badge_patreon]: http://ionicabizau.github.io/badges/patreon.svg
[badge_amazon]: http://ionicabizau.github.io/badges/amazon.svg
[badge_paypal]: http://ionicabizau.github.io/badges/paypal.svg
[badge_paypal_donate]: http://ionicabizau.github.io/badges/paypal_donate.svg
[patreon]: https://www.patreon.com/ionicabizau
[amazon]: http://amzn.eu/hRo9sIZ
[paypal-donations]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RVXDDLKKLQRJW
[donate-now]: http://i.imgur.com/6cMbHOC.png

[license]: http://showalicense.com/?fullname=Ionic%C4%83%20Biz%C4%83u%20%3Cbizauionica%40gmail.com%3E%20(https%3A%2F%2Fionicabizau.net)&year=2018#license-mit
[website]: https://ionicabizau.net
[contributing]: /CONTRIBUTING.md
[docs]: /DOCUMENTATION.md
72 changes: 72 additions & 0 deletions bin/google-font-downloader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env node

"use strict";

const Tilda = require("tilda")
, WritableStream = require("streamp").writable
, tinyreq = require("tinyreq")
, matchAll = require("match-all")
;

const USER_AGENT = "User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36"

new Tilda(`${__dirname}/../package.json`, {
args: [
{
name: "url"
, desc: "The Google APIs url."
, required: true
}
],
examples: [
"google-font-downloader https://fonts.googleapis.com/css?family=Open+Sans:400,400i,700,700i"
]
}).main(action => {
const url = action.args.url
const data = {}
console.log(`Getting the external CSS: ${url}`)
tinyreq({
url,
headers: {
"user-agent": USER_AGENT
}
}).then(body => {
const matchFontFilesRegex = /url\((https\:\/\/fonts\.gstatic\.com\/.*)\) format/gm

data.original_stylesheet = body
data.local_stylesheet = body
data.font_urls = matchAll(body, matchFontFilesRegex).toArray()
data.local_font_paths = data.font_urls.map(c => `fonts/${c.split("/").slice(4).join("/")}`)
data.fonts = data.font_urls.map((c, index) => ({
remote: c,
local: data.local_font_paths[index]
}))

console.log(`Detected ${data.fonts.length} font files to download.`)
return Promise.all(data.fonts.map(c => {
data.local_stylesheet = data.local_stylesheet.replace(c.remote, c.local)
return new Promise(res => {
const req = tinyreq({ url: c.remote, encoding: null, headers: { "user-agent": USER_AGENT } })
, stream = new WritableStream(c.local)

req.on("data", data => {
stream.write(data)
}).on("error", e => {
console.error("Failed to download " + c.remote)
console.error(e)
res()
}).on("end", () => {
console.log(`Downloaded ${c.remote} in ${c.local}`)
stream.end()
res()
})
})
}))
}).then(() => {
const fileName = `google-fonts-${Date.now()}.css`
, cssStream = new WritableStream(fileName)

console.log(`Writting the CSS into ${fileName}`)
cssStream.end(data.local_stylesheet)
})
});
34 changes: 34 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"bin": {
"google-font-downloader": "bin/google-font-downloader.js"
},
"name": "google-font-downloader",
"description": "Download Google fonts by providing the url",
"keywords": [
Expand Down Expand Up @@ -40,5 +43,36 @@
},
"bugs": {
"url": "https://github.com/IonicaBizau/google-font-downloader/issues"
},
"dependencies": {
"match-all": "^1.2.4",
"streamp": "^2.2.8",
"tilda": "^4.4.13",
"tinyreq": "^3.4.0"
},
"blah": {
"description": [
{
"h4": "Usage"
},
{
"p": "You can use this tool to download Google Fonts for offline use, just by providing the Google APIs url."
},
{
"p": ":bulb: **Note**: It's not clear yet if Google Fonts are EU GDPR compliant (see [this issue](https://github.com/google/fonts/issues/1495)). This may be a good reason to download the Google Fonts you use on your server."
},
{
"h4": "How it works"
},
{
"p": "You need to provide the url to the Google APIs endpoint (e.g. `https://fonts.googleapis.com/css?family=Open+Sans:400,400i,700,700i`) and you will get the following files/directories in the current working directory:"
},
{
"ul": [
"A file named `google-fonts-<timestamp>.css—this will contain the CSS snippets that you need to copy in your app. You may need to update the paths to the font files.",
"A directory structure looking like this: `fonts/<font-name>/<version>/<font-file>`"
]
}
]
}
}

0 comments on commit e851ee9

Please sign in to comment.