-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsass.js
61 lines (49 loc) · 1.84 KB
/
sass.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
var sass = require('sass');
var fs = require('fs');
var pkg = require('./package.json');
// Themes
let themes = ['default', 'skinny-nav', 'sidebar'];
// Banner
var banner = `/*! ${pkg.name} v${pkg.version} | (c) ${new Date().getFullYear()} ${pkg.author.name} | ${pkg.license} License | ${pkg.repository.url} */`;
var getOptions = function (theme, filename, minify) {
return {
file: `src/scss/${theme}.scss`,
outFile: `dist/${theme}/css/${filename}`,
indentType: 'tab',
indentWidth: 1,
outputStyle: minify ? 'compressed' : 'expanded'
};
};
var writeFile = function (pathOut, fileName, fileData, printBanner = true) {
// Create the directory path
fs.mkdir(pathOut, { recursive: true }, function (err) {
// If there's an error, throw it
if (err) throw err;
// Write the file to the path
fs.writeFile(`${pathOut}/${fileName}`, fileData, function (err) {
if (err) throw err;
var data = fs.readFileSync(`${pathOut}/${fileName}`);
var fd = fs.openSync(`${pathOut}/${fileName}`, 'w+');
var insert = printBanner ? new Buffer.from(banner + '\n') : '';
fs.writeSync(fd, insert, 0, insert.length, 0);
fs.writeSync(fd, data, 0, data.length, insert.length);
fs.close(fd, function (err) {
if (err) throw err;
console.log(`Compiled ${pathOut}/${fileName}`);
})
})
})
}
var parseSass = function (theme, minify) {
var filename = `${theme}${minify ? '.min' : ''}.css`;
sass.render(getOptions(theme, filename, minify), function (err, result) {
// If there's an error, throw it
if (err) throw err;
// Write the file
writeFile(`dist/${theme}/css`, filename, result.css);
});
};
themes.forEach(function (theme) {
parseSass(theme);
parseSass(theme, true);
});