-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
124 lines (104 loc) · 2.93 KB
/
index.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
'use strict';
const initBrowserSync = require('browser-sync');
const fs = require('fs');
const livingcss = require('livingcss');
const path = require('path');
const sass = require('node-sass');
const pkg = require('./package.json');
function sassSrcFile() {
return path.join(__dirname, pkg.srcDir, pkg.srcFile);
}
function sassSrcGlob() {
return path.join(pkg.srcDir, '*.scss');
}
function cssDestDir() {
return path.join(__dirname, pkg.destDir);
}
function cssDestFile() {
return path.join(__dirname, pkg.destDir, pkg.destFile);
}
function cssDestCleanFile() {
return path.join(__dirname, pkg.destDir, pkg.destCleanFile);
}
function cssDestGlob() {
return path.join(cssDestDir(), '*.css');
}
function cssDestWebUrl() {
return pkg.destFile;
}
function htmlDestFileGlob() {
return path.join(pkg.destDir, '*.html');
}
function compileSass() {
// compile sass files
const sassOutput = sass.renderSync({
file: sassSrcFile(),
});
// write out compiled sass
fs.writeFileSync(cssDestFile(), sassOutput.css);
}
function buildStyleguide() {
// build styleguide into index.html file
livingcss(sassSrcGlob(), cssDestDir(), {
preprocess: function (context) {
context.title = 'Blossom Bootstrap Theme';
context.footerHTML = '© Blossom Labs, Inc. https://blossomfinance.com/';
context.globalStylesheets = [
cssDestWebUrl(),
];
context.scripts.push('https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js');
},
});
}
module.exports = {
sassSrcFile,
sassSrcGlob,
cssDestFile,
cssDestCleanFile,
cssDestGlob,
compileSass,
buildStyleguide,
browserSync: function browserSync() {
return initBrowserSync({
// serve the files and inject the reload snippet
server: {
baseDir: pkg.destDir,
index: 'overview.html',
},
serveStatic: [{
route: 'webfonts',
dir: path.join(__dirname, 'node_modules/@fortawesome/fontawesome-free/webfonts'),
}, {
route: 'fonts',
dir: path.join(__dirname, 'node_modules/@blossomfinance/svg-webfont-icons/dist/fonts'),
}],
// allow serving in heroku
port: process.env.PORT || '3000',
// avoid inlining css, which is the default
loadcss: false,
// extra info on command line
logFileChanges: true,
logConnections: true,
// two things to watch:
// 1. source code, need to rebuild living style guide
// 2. compiled styleguide html, need to reload browser
files: [
// rebuild when source code has changed
{
match: [sassSrcGlob()],
fn: function () {
try {
compileSass();
buildStyleguide();
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);
}
},
},
// reload when html page updates
htmlDestFileGlob(),
],
});
},
};