forked from zalando-incubator/hexo-theme-doc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbanner.js
32 lines (27 loc) · 801 Bytes
/
banner.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
'use strict';
const fs = require('fs');
const pkg = require('./package.json');
const path = require('path');
const banner = ` /*!
* ${pkg.name} - ${pkg.version}
* Copyright (c) see LICENSE at ${pkg.homepage}/blob/master/LICENSE
*/
`;
const files = [
'source/style/doc.css',
'source/script/doc.js',
];
files.forEach(writeBanner(banner));
function writeBanner (banner) {
return function (filePath) {
const fileExt = path.extname(filePath);
const absFilePath = path.resolve(__dirname, filePath);
let content = fs.readFileSync(absFilePath, 'utf8');
content = banner + content;
if (fileExt === '.css') {
content = content.replace(/@charset "UTF-8";/g, '');
content = '@charset "UTF-8";\n' + content;
}
fs.writeFileSync(absFilePath, content);
};
}