-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
63 lines (47 loc) · 2.24 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
const { resolve: resolvePath } = require('path');
const { ensureDirExists, copyFileDeeply, readData, saveData, execute } = require('./helper');
const SRC_ROOT = resolvePath(__dirname, '../src');
const SA_ROOT = `${SRC_ROOT}/shared`;
function copyAssets(distRoot, polyfill) {
['fonts', 'images', 'javascripts', 'stylesheets'].forEach(dirName => {
const assetsPath = `${distRoot}/${dirName}`;
ensureDirExists(assetsPath);
const srcPath = `${SA_ROOT}/${dirName}`;
const distPath = `${distRoot}/${dirName}/ksio`;
ensureDirExists(distPath, true);
copyFileDeeply(srcPath, distPath, polyfill ? [] : ['polyfills']);
});
const distStyleDirPath = `${distRoot}/stylesheets/ksio/`;
const shareSnsStyleFilePath = `${distStyleDirPath}/vendors/share.scss`;
const shareSnsStyleFileContent = readData(shareSnsStyleFilePath);
if (!polyfill) {
return saveData(shareSnsStyleFilePath, shareSnsStyleFileContent.replace(new RegExp('fonts/vendors/share', 'g'), 'ksio/vendors/share'));
}
saveData(shareSnsStyleFilePath, shareSnsStyleFileContent.replace(new RegExp('fonts/vendors/share', 'g'), '../../../fonts/ksio/vendors/share').replace(new RegExp('font-url', 'g'), 'url'));
const faStyleFilePath = `${distStyleDirPath}/polyfills/_font-awesome-sprockets.scss`;
saveData(faStyleFilePath, readData(faStyleFilePath).replace(' font-path($path)', ' "../fonts/ksio/polyfills/#{$path}"'));
['_all', '_bootstrap-custom', '_helper', '_painter'].forEach(fileName => {
const filePath = `${distStyleDirPath}/${fileName}.scss`;
const bsStr = fileName === '_all' ? 'bootstrap-sprockets' : 'bootstrap';
saveData(
filePath,
readData(filePath)
.replace(new RegExp('@import "compass', 'g'), '@import "./polyfills/compass')
.replace(new RegExp(`@import "${bsStr}`, 'g'), `@import "./polyfills/${bsStr}`)
.replace(new RegExp('@import "font-awesome', 'g'), '@import "./polyfills/font-awesome'),
);
});
}
module.exports = {
execute: (type = 'doc') => {
if (type === 'doc') {
return execute('generate');
}
if (type === 'jekyll') {
return copyAssets(`${SRC_ROOT}/jekyll/_assets`);
}
if (type === 'hexo') {
return copyAssets(`${SRC_ROOT}/hexo/themes/lime/source`, true);
}
},
};