Skip to content

Commit 11bdf2c

Browse files
committed
Added build file
1 parent 29a7aec commit 11bdf2c

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

build/index.js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const pkg = require('../package');
4+
5+
const dist = path.join(__dirname, '../dist/');
6+
const docs = path.join(__dirname, '../docs/');
7+
const now = new Date();
8+
const banner = `/*!
9+
* Viewer.js v${pkg.version}
10+
* https://github.com/${pkg.repository}
11+
*
12+
* Copyright (c) ${now.getFullYear()} ${pkg.author.name}
13+
* Released under the ${pkg.license} license
14+
*
15+
* Date: ${now.toISOString()}
16+
*/
17+
18+
`;
19+
20+
fs.readdirSync(dist).forEach((file) => {
21+
if (!/\.(js|css)$/.test(file)) {
22+
return;
23+
}
24+
25+
const filePath = path.join(dist, file);
26+
const fileData = banner + fs.readFileSync(filePath, 'utf8').toString();
27+
28+
fs.writeFile(filePath, fileData, (err) => {
29+
if (err) {
30+
throw err;
31+
}
32+
33+
console.log(`Added banner to ${file}.`);
34+
35+
if (file === 'viewer.js') {
36+
fs.writeFile(path.join(docs, 'js/', file), fileData, (e) => {
37+
if (e) {
38+
throw e;
39+
}
40+
41+
console.log(`Copied ${file} to docs/js.`);
42+
});
43+
} else if (file === 'viewer.css') {
44+
fs.writeFile(path.join(docs, 'css/', file), fileData, (e) => {
45+
if (e) {
46+
throw e;
47+
}
48+
49+
console.log(`Copied ${file} to docs/css.`);
50+
});
51+
}
52+
});
53+
});

0 commit comments

Comments
 (0)