Skip to content

Commit

Permalink
Added build file
Browse files Browse the repository at this point in the history
  • Loading branch information
fengyuanchen committed Jan 24, 2017
1 parent 29a7aec commit 11bdf2c
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions build/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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.`);
});
}
});
});

0 comments on commit 11bdf2c

Please sign in to comment.