-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
76 lines (62 loc) · 2.11 KB
/
build.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const fs = require('fs');
const del = require('del');
const path = require('path');
const webfontsGenerator = require('webfonts-generator');
const name = 'dev-awesome';
const svgFolder = path.resolve('svg');
const distFolder = path.resolve('dist');
const fontsFolder = path.resolve(distFolder, 'fonts');
const svgFontFolder = path.resolve(svgFolder, 'black');
const templateFolder = path.resolve('template');
const svgFileNames = fs.readdirSync(svgFontFolder);
const codepoints = JSON.parse(fs.readFileSync(path.resolve('codepoints.json'), 'utf8'));
const coloredSvgFolder = path.resolve(fontsFolder, 'svg', 'colored');
del.sync(distFolder);
fs.mkdirSync(distFolder);
fs.mkdirSync(fontsFolder);
fs.mkdirSync(path.resolve(fontsFolder, 'svg'));
fs.mkdirSync(coloredSvgFolder);
function options(extension = 'css') {
const isScss = extension == 'scss';
const opts = {
files: svgFileNames.map((svgFile) => path.resolve(svgFontFolder, svgFile)),
dest: fontsFolder,
fontName: name,
cssFontsUrl: isScss ? '#{$da-font-path}' : '../fonts',
codepoints: codepoints,
css: true,
html: true,
cssDest: path.resolve(distFolder, extension, `${isScss ? '_' : ''}${name}.${extension}`),
htmlDest: path.resolve('index.html'),
cssTemplate: path.resolve(templateFolder, `css.hbs`),
htmlTemplate: path.resolve(templateFolder, 'html.hbs'),
fixedWidth: true,
centerHorizontally: false,
fontHeight: 800,
descent: 0,
templateOptions: {
classPrefix: 'da-',
baseSelector: 'da',
isScss: isScss,
},
}
console.info('[INFO] Building', extension, 'files with options:', JSON.stringify(opts, null, 2), '\n\n');
return opts;
}
function callback(error) {
if (error) {
console.error(error);
} else {
svgFileNames.forEach((svgFile) => fs.copyFileSync(
path.resolve(path.resolve(svgFontFolder, '..', 'colored'), svgFile),
path.resolve(coloredSvgFolder, svgFile)
));
}
}
webfontsGenerator(options('css'), (err) => {
callback(err);
webfontsGenerator(options('scss'), (err) => {
callback(err);
console.info("[Done] :: Happy Mumuki'ng!!");
})
});