Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
feather
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
feather
Commits
ae164db7
Commit
ae164db7
authored
Jul 03, 2017
by
Cole Bemis
Committed by
Cole Bemis
Jul 03, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
build: Add script to build `dist/icons.json`
parent
c089ee1f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
0 deletions
+84
-0
.babelrc
.babelrc
+5
-0
Makefile
Makefile
+8
-0
build-json.js
bin/build-json.js
+71
-0
No files found.
.babelrc
0 → 100644
View file @
ae164db7
{
"presets": [
"es2015"
]
}
Makefile
0 → 100644
View file @
ae164db7
node_modules
:
npm
install
dist
:
mkdir
dist
dist/icons.json
:
node_modules dist icons icons/*.svg
./node_modules/.bin/babel-node bin/build-json.js
bin/build-json.js
0 → 100755
View file @
ae164db7
/**
* @file Builds `icons.json` from `icons` directory.
*/
/* eslint-disable import/no-extraneous-dependencies */
import
fs
from
'
fs
'
;
import
path
from
'
path
'
;
import
RSVP
from
'
rsvp
'
;
import
Svgo
from
'
svgo
'
;
import
parse5
from
'
parse5
'
;
const
svgFiles
=
fs
.
readdirSync
(
path
.
resolve
(
__dirname
,
'
../icons
'
))
.
filter
(
file
=>
path
.
extname
(
file
)
===
'
.svg
'
);
buildIconsObject
(
svgFiles
)
.
then
(
icons
=>
{
fs
.
writeFileSync
(
path
.
resolve
(
__dirname
,
'
../dist/icons.json
'
),
JSON
.
stringify
(
icons
),
);
});
/**
* Build an icons object in the format: `{ <icon name>: <svg content> }`.
* @param {string[]} svgFiles - A list of file names.
* @returns {RSVP.Promise<Object>}
*/
function
buildIconsObject
(
svgFiles
)
{
const
icons
=
{};
svgFiles
.
forEach
(
svgFile
=>
{
const
svg
=
fs
.
readFileSync
(
path
.
resolve
(
__dirname
,
'
../icons
'
,
svgFile
),
'
utf8
'
);
const
key
=
path
.
basename
(
svgFile
,
'
.svg
'
);
icons
[
key
]
=
optimizeSvg
(
svg
)
.
then
(
optimizedSvg
=>
getSvgContent
(
optimizedSvg
));
});
return
RSVP
.
hash
(
icons
);
}
/**
* Optimize SVG with `svgo`.
* @param {string} svg - An SVG string.
* @returns {RSVP.Promise<string>}
*/
function
optimizeSvg
(
svg
)
{
// configure svgo
const
svgo
=
new
Svgo
({
plugins
:
[
{
convertShapeToPath
:
false
},
{
mergePaths
:
false
},
{
removeAttrs
:
{
attrs
:
'
(fill|stroke.*)
'
}
},
],
});
return
new
RSVP
.
Promise
(
resolve
=>
{
svgo
.
optimize
(
svg
,
({
data
})
=>
resolve
(
data
));
});
}
/**
* Get content between opening and closing `<svg>` tags.
* @param {string} svg - An SVG string.
* @returns {string}
*/
function
getSvgContent
(
svg
)
{
const
fragment
=
parse5
.
parseFragment
(
svg
);
const
content
=
parse5
.
serialize
(
fragment
.
childNodes
[
0
]);
return
content
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment