google-font-installer
Advanced tools
Comparing version 1.0.8 to 1.0.9
44
cli.js
@@ -10,2 +10,3 @@ #!/usr/bin/env node | ||
var pjson = require('./package.json'); | ||
var ncp = require("copy-paste"); | ||
@@ -50,2 +51,15 @@ program | ||
program | ||
.command('copy <family...>') | ||
.option('-v, --variants <variants...>', 'Specify variants/weights to copy clipboard, seperated with comma (and no spaces)') | ||
.description('Copy stylesheet link') | ||
.action(function(family, options){ | ||
var searchedTerm = family.join(" "); | ||
var variants = options.variants ? options.variants.split(',') : false; | ||
fontList.on('success', function(){ | ||
copyFont(searchedTerm, variants); | ||
}) | ||
}); | ||
program | ||
.version(pjson.version); | ||
@@ -108,2 +122,24 @@ | ||
function copyFont(searchedTerm, variants) { | ||
fontList.getFontByName(searchedTerm, function(err, filteredList){ | ||
if (err){ | ||
printError(err); | ||
return; | ||
} | ||
if (filteredList.data.length === 1) { | ||
var list = filteredList.getFirst(); | ||
var cssUrl = variants ? list.cssUrl + ':' + variants.join(',') : list.cssUrl; | ||
ncp.copy(cssUrl, function () { | ||
console.log('"%s" font url has been copied to your clipboard.'.green, searchedTerm); | ||
}); | ||
} else { | ||
console.log('Copy failed: unable to find font family "%s". \n'.bold.red, searchedTerm); | ||
searchFont(searchedTerm); | ||
} | ||
}) | ||
} | ||
function printFontList(err, list, message){ | ||
@@ -116,5 +152,5 @@ if (err) { | ||
} else { | ||
message = message || 'Search reuslts for:' | ||
message = message || 'Search results for:' | ||
if (list._filterTerm) | ||
console.log('%s "%s"\n'.green, message, list._filterTerm.bold.blue); | ||
console.log('%s "%s"\n'.green, message, (list._filterTerm || '').bold.blue); | ||
list.data.forEach(function(el){ | ||
@@ -134,3 +170,3 @@ console.log(" * %s".bold.blue, el.family); | ||
result.forEach(function(el){ | ||
console.log('%s variant %s downloaded in %s'.green, el.family.bold, el.variant.bold, el.path.underline); | ||
console.log('%s variant %s downloaded in %s'.green, (el.family || '??').bold, (el.variant || '??').bold, (el.path || '??').underline); | ||
}) | ||
@@ -141,4 +177,4 @@ console.log(''); | ||
function printError(err) { | ||
console.log(err.message.bold.red); | ||
console.log((err.message || err.stack || 'Error, please try again!').bold.red); | ||
process.exit(1); | ||
} |
{ | ||
"name": "google-font-installer", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"description": "Download and install Google Web Fonts on your local machine", | ||
@@ -29,2 +29,3 @@ "author": "Lorenzo Zottar <lordgiotto@gmail.com>", | ||
"commander": "^2.9.0", | ||
"copy-paste": "^1.3.0", | ||
"file-type": "^3.6.0", | ||
@@ -31,0 +32,0 @@ "mv": "^2.1.1", |
@@ -11,6 +11,6 @@ Google Font Installer | ||
<br> | ||
![how gfi works](https://raw.githubusercontent.com/lordgiotto/google-font-installer/master/gfi.gif) | ||
<br> | ||
### Table of content | ||
@@ -22,2 +22,3 @@ | ||
- [Install a font](#install-a-font) | ||
- [Copy font CSS URL](#copy-font-css-url) | ||
- [Examples](#cli-examples) | ||
@@ -80,9 +81,17 @@ - [APIs](#apis) | ||
### Copy font CSS url | ||
``` | ||
$ gfi copy [family_name] [-v|--variants comma_separeted_variants] | ||
``` | ||
If **family_name** will match more than one family, nothing will be copied: a list of alternatives will help you better specify the font family name. | ||
<a id="cli-examples"></a> | ||
### Examples | ||
Search the _source_ keyword: | ||
**Search the _source_ keyword** | ||
``` | ||
$ gfi search source | ||
Search reuslts for: "source" | ||
Search results for: "source" | ||
@@ -102,3 +111,4 @@ * Source Code Pro | ||
``` | ||
Download Source Sans Pro 600 and 700italic: | ||
**Download Source Sans Pro 600 and 700italic** | ||
``` | ||
@@ -110,3 +120,4 @@ $ gfi download source sans pro -v 600,700italic | ||
``` | ||
Install Lato 100 | ||
**Install Lato 100** | ||
``` | ||
@@ -118,2 +129,12 @@ $ gfi install lato -v 100 | ||
``` | ||
**Copy font url for Work Sans variants 200, normal and 600** | ||
``` | ||
$ gfi copy work sans -v 200,400,600 | ||
"work sans" font url has been copied to your clipboard. | ||
``` | ||
(*https://fonts.googleapis.com/css?family=Work+Sans:200,400,600* will be available in your clipboard) | ||
# APIs | ||
@@ -120,0 +141,0 @@ |
856426
669
348
7
+ Addedcopy-paste@^1.3.0
+ Addedcopy-paste@1.5.3(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedsafer-buffer@2.1.2(transitive)