scripts/release.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 |
const fs = require('fs');
const path = require('path');
const readme = './README.md';
const overview = './docs/md/overview.md';
const app = './docs/js/app.js';
const tutorial = './docs/md/tutorial.md';
const package = './package.json';
const h3 = './h3.js';
const h3min = './h3.min.js';
const h3map = './h3.js.map';
const pkg = JSON.parse(fs.readFileSync(package, 'utf8'));
const conver = pkg.conver.substring(0,2)+'-'+pkg.conver[3];
// Update h3.js
let vregex = /v(\d+\.\d+\.\d+|[0-9A-F]{3}\-[0-9A-F])/;
let h3Data = fs.readFileSync(h3, 'utf8');
const notice = h3Data.match(/\/\*\*((.|\n|\r)+?)\*\//gm)[0];
const newNotice = notice
.replace(vregex, `v${conver}`)
.replace(/\"[^"]+\"/, `"${pkg.versionName}"`)
.replace(/Copyright \d+/, `Copyright ${new Date().getFullYear()}`);
h3Data = h3Data.replace(notice, newNotice);
fs.writeFileSync(h3, h3Data);
// Update README.md
let readmeData = fs.readFileSync(readme, 'utf8');
readmeData = readmeData.replace(vregex, `v${conver}`);
// Copy to overview.md
fs.writeFileSync(overview, readmeData);
// Update app.js and tutorial.md
const updateCode = (file) => {
let data = fs.readFileSync(file, 'utf8');
data = data.replace(vregex, `v${conver}`);
data = data.replace(/“.+“/, `“${pkg.versionName}“`);
fs.writeFileSync(file, data);
};
updateCode(app);
updateCode(tutorial);
// Update package.json
const packageData = JSON.parse(fs.readFileSync(package, 'utf8'));
packageData.version = pkg.version;
fs.writeFileSync(package, JSON.stringify(packageData, null, 2));
|