-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
51 lines (45 loc) · 1.47 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
(function(_path, _fs, _less) {
var ROOT = __dirname;
var SRC_ROOT = _path.join(ROOT, 'src');
var THEME_ROOT = _path.join(ROOT, 'src/themes');
var BUILD_ROOT = _path.join(ROOT, 'build');
var getDirName = require('path').dirname;
function writeFile(path, contents, cb) {
console.log(getDirName(path))
_fs.mkdirsSync(getDirName(path));
_fs.writeFileSync(path, contents);
}
/* get dirs in dir, if withhidden is true, also return file bigin with "." */
function getDirectories(dir, withhidden) {
var wh = withhidden || false;
var list = [];
_fs.readdirSync(dir).forEach(function(iter) {
var s = _fs.lstatSync(_path.join(dir, iter));
if (s.isDirectory() || s.isSymbolicLink()) {
if (!wh && iter.match(/^\./)) {
return;
}
list.push(iter);
}
});
return list;
}
function buildThemes() {
var themes = getDirectories(THEME_ROOT);
themes.forEach(function(theme){
var less_content = _fs.readFileSync(_path.join(THEME_ROOT, theme, 'style.less')).toString();
_less.render(less_content, {compress: true, syncImport: true, paths: _path.join(THEME_ROOT, theme)}, function(e, output) {
if (e) {
console.log(e);
return;
}
writeFile('build/themes/default/style.css', output.css);
});
/* copy fonts */
_fs.copySync(_path.join(THEME_ROOT, theme, 'font'), _path.join('build/themes/', theme, '/font'));
})
}
module.exports = {
buildThemes: buildThemes,
};
})(require('path'), require('node-fs-extra'), require('less'));