-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
parser: 'babel', | ||
singleQuote: true | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# vue-cli-plugin-webfontloader | ||
|
||
Web Font Loader Plugin for [[email protected]](https://github.com/vuejs/vue-cli) | ||
|
||
## Install | ||
|
||
If you haven't yet installed vue-cli 3, first follow the install instructions here: https://github.com/vuejs/vue-cli | ||
|
||
Generate a project | ||
|
||
```bash | ||
vue create my-app | ||
``` | ||
|
||
Install the plugin | ||
|
||
```bash | ||
cd my-app | ||
vue add webfontloader | ||
``` | ||
|
||
Follow the prompts to set up your specific web font loader configuration. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const { EOL } = require('os'); | ||
const prettier = require('prettier'); | ||
const fs = require('fs'); | ||
|
||
const getConfig = options => { | ||
const config = {}; | ||
|
||
if (options.custom) { | ||
config.custom = { | ||
families: options.custom.split(',').map(f => f.trim()) | ||
}; | ||
} | ||
|
||
if (options.fontdeck) { | ||
config.fontdeck = { id: options.fontdeck }; | ||
} | ||
|
||
if (options.monotype) { | ||
config.monotype = { projectId: options.monotype }; | ||
} | ||
|
||
if (options.google) { | ||
config.google = { | ||
families: options.google.split(',').map(f => f.trim()) | ||
}; | ||
} | ||
|
||
if (options.typekit) { | ||
config.typekit = { id: options.typekit }; | ||
} | ||
|
||
return config; | ||
}; | ||
|
||
module.exports = (api, options) => { | ||
api.extendPackage({ | ||
dependencies: { | ||
webfontloader: '^1.6.28' | ||
} | ||
}); | ||
|
||
api.injectImports(api.entryFile, `import WebFont from 'webfontloader';`); | ||
|
||
api.onCreateComplete(() => { | ||
const lines = fs | ||
.readFileSync(api.entryFile, { encoding: 'utf-8' }) | ||
.split(/\r?\n/g); | ||
|
||
const hasPlugin = lines.some(line => line.match(/WebFont\.load\(/)); | ||
|
||
if (hasPlugin) { | ||
return; | ||
} | ||
|
||
const newVueLine = lines.findIndex(line => line.match(/new Vue\(/)); | ||
|
||
const opts = prettier.resolveConfig.sync('./.prettierrc.js'); | ||
|
||
const webFontLoad = prettier | ||
.format(`WebFont.load(${JSON.stringify(getConfig(options))})`, opts) | ||
.trim(); | ||
|
||
lines.splice(newVueLine - 1, 0, '', webFontLoad); | ||
|
||
fs.writeFileSync(api.entryFile, lines.join(EOL), { encoding: 'utf-8' }); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = () => {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "vue-cli-plugin-webfontloader", | ||
"version": "0.1.0", | ||
"description": "vue-cli plugin to add webfontloader", | ||
"main": "index.js", | ||
"repository": "https://github.com/caseyjacobson/vue-cli-plugin-webfontloader", | ||
"author": "Casey Jacobson <[email protected]>", | ||
"license": "MIT", | ||
"private": true, | ||
"dependencies": { | ||
"fs": "^0.0.1-security", | ||
"os": "^0.1.1", | ||
"prettier": "^1.18.2", | ||
"webfontloader": "^1.6.28" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module.exports = [ | ||
{ | ||
type: 'checkbox', | ||
name: 'providers', | ||
message: 'Web font providers:', | ||
choices: ['Custom', 'Fontdeck', 'Fonts.com', 'Google', 'Typekit'], | ||
validate: input => { | ||
if (input.length > 0) { | ||
return true; | ||
} | ||
|
||
return 'Please select at least one web font provider.'; | ||
} | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'custom', | ||
message: | ||
'What custom fonts are you using? (e.g. Roboto, Source Sans Pro, Helvetica)', | ||
validate: input => Boolean(input), | ||
when: answers => answers.providers.includes('Custom') | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'fontdeck', | ||
message: 'What is your Fontdeck ID?', | ||
validate: input => Boolean(input), | ||
when: answers => answers.providers.includes('Fontdeck') | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'monotype', | ||
message: 'What is your Fonts.com Project ID?', | ||
validate: input => Boolean(input), | ||
when: answers => answers.providers.includes('Fonts.com') | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'google', | ||
message: | ||
'What Google fonts are you using? (e.g. Droid Sans, Open Sans Condensed:300,700)', | ||
validate: input => Boolean(input), | ||
when: answers => answers.providers.includes('Google') | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'typekit', | ||
message: 'What is your Typekit Kit ID?', | ||
validate: input => Boolean(input), | ||
when: answers => answers.providers.includes('Typekit') | ||
} | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
fs@^0.0.1-security: | ||
version "0.0.1-security" | ||
resolved "https://registry.yarnpkg.com/fs/-/fs-0.0.1-security.tgz#8a7bd37186b6dddf3813f23858b57ecaaf5e41d4" | ||
integrity sha1-invTcYa23d84E/I4WLV+yq9eQdQ= | ||
|
||
os@^0.1.1: | ||
version "0.1.1" | ||
resolved "https://registry.yarnpkg.com/os/-/os-0.1.1.tgz#208845e89e193ad4d971474b93947736a56d13f3" | ||
integrity sha1-IIhF6J4ZOtTZcUdLk5R3NqVtE/M= | ||
|
||
prettier@^1.18.2: | ||
version "1.18.2" | ||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.18.2.tgz#6823e7c5900017b4bd3acf46fe9ac4b4d7bda9ea" | ||
integrity sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw== | ||
|
||
webfontloader@^1.6.28: | ||
version "1.6.28" | ||
resolved "https://registry.yarnpkg.com/webfontloader/-/webfontloader-1.6.28.tgz#db786129253cb6e8eae54c2fb05f870af6675bae" | ||
integrity sha1-23hhKSU8tujq5UwvsF+HCvZnW64= |