-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add prepublish script #942
Changes from 4 commits
112d419
bae13de
304ef26
04a0828
f09136d
463ad23
86cfce5
4c15527
ccd66ab
dd9e42c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ | |
}, | ||
"scripts": { | ||
"jsonlint": "jsonlint _data/simple-icons.json -q -V .jsonlintschema", | ||
"svglint": "svglint icons/* --ci" | ||
"svglint": "svglint icons/* --ci", | ||
"prepublishOnly": "node scripts/prepublish.js", | ||
"postpublish": "rm icons/*.js && rm index.js" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env node | ||
/** | ||
* @fileoverview | ||
* Compiles our icons into static .js files that can be imported in the browser | ||
* and are tree-shakeable. | ||
* The static .js files go in icons/{filename}.js. | ||
* Also generates an index.js that exports all icons by title, but is not tree-shakeable | ||
*/ | ||
|
||
const dataFile = "../_data/simple-icons.json"; | ||
const indexFile = `${__dirname}/../index.js`; | ||
const iconsDir = `${__dirname}/../icons`; | ||
const data = require(dataFile); | ||
const fs = require('fs'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick, but other then this you're always using double quotes |
||
|
||
const { titleToFilename } = require("./utils"); | ||
|
||
const icons = {}; | ||
data.icons.forEach(i => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename the variable |
||
const filename = titleToFilename(i.title); | ||
i.svg = fs.readFileSync(`${iconsDir}/${filename}.svg`, "utf8"); | ||
icons[i.title] = i; | ||
// write the static .js file for the icon | ||
fs.writeFileSync( | ||
`${iconsDir}/${filename}.js`, | ||
`module.exports = ${JSON.stringify(i)};` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe change this to |
||
); | ||
}); | ||
|
||
// write our generic index.js | ||
fs.writeFileSync(indexFile, `module.exports = ${JSON.stringify(icons)};`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, change this to |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module.exports = { | ||
/** | ||
* Converts a brand title into a filename (not a full path) | ||
* @param {String} title The title to convert | ||
*/ | ||
titleToFilename: title => ( | ||
title.toLowerCase() | ||
.replace(/\+/g, "plus") | ||
.replace(/^\./, "dot-") | ||
.replace(/\.$/, "-dot") | ||
.replace(/\./g, "-dot-") | ||
.replace(/[ !’]/g, '') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick, but other then this you're always using double quotes |
||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
webpack
could be a link, just like "JSDelivr" and "Unpkg"