forked from svg-sprite/svg-sprite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
48 lines (45 loc) · 1.2 KB
/
example.js
File metadata and controls
48 lines (45 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var SVGSpriter = require('./lib/svg-sprite'),
path = require('path'),
mkdirp = require('mkdirp'),
fs = require('fs'),
glob = require('glob'),
cwd = path.join(__dirname, 'test', 'fixture', 'svg', 'single'),
dest = path.normalize(path.join(__dirname, 'tmp')),
files = glob.glob.sync('**/weather*.svg', {cwd: cwd});
spriter = new SVGSpriter({
dest : dest,
log : 'debug'
});
/**
* Add a bunch of SVG files
*
* @param {SVGSpriter} spriter Spriter instance
* @param {Array} files SVG files
* @return {SVGSpriter} Spriter instance
*/
function addFixtureFiles(spriter, files) {
files.forEach(function(file){
spriter.add(
path.resolve(path.join(cwd, file)),
file,
fs.readFileSync(path.join(cwd, file), {encoding: 'utf-8'})
);
})
return spriter;
}
addFixtureFiles(spriter, files).compile({
css : {
sprite : 'svg/sprite.vertical.svg',
layout : 'vertical',
dimensions : true,
render : {
css : true,
scss : true
}
}
}, function(error, result, cssData) {
for (var type in result.css) {
mkdirp.sync(path.dirname(result.css[type].path));
fs.writeFileSync(result.css[type].path, result.css[type].contents);
}
})