viewerjs/build/index.js
2017-01-24 14:49:09 +08:00

54 lines
1.2 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const pkg = require('../package');
const dist = path.join(__dirname, '../dist/');
const docs = path.join(__dirname, '../docs/');
const now = new Date();
const banner = `/*!
* Viewer.js v${pkg.version}
* https://github.com/${pkg.repository}
*
* Copyright (c) ${now.getFullYear()} ${pkg.author.name}
* Released under the ${pkg.license} license
*
* Date: ${now.toISOString()}
*/
`;
fs.readdirSync(dist).forEach((file) => {
if (!/\.(js|css)$/.test(file)) {
return;
}
const filePath = path.join(dist, file);
const fileData = banner + fs.readFileSync(filePath, 'utf8').toString();
fs.writeFile(filePath, fileData, (err) => {
if (err) {
throw err;
}
console.log(`Added banner to ${file}.`);
if (file === 'viewer.js') {
fs.writeFile(path.join(docs, 'js/', file), fileData, (e) => {
if (e) {
throw e;
}
console.log(`Copied ${file} to docs/js.`);
});
} else if (file === 'viewer.css') {
fs.writeFile(path.join(docs, 'css/', file), fileData, (e) => {
if (e) {
throw e;
}
console.log(`Copied ${file} to docs/css.`);
});
}
});
});