-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpublish.js
28 lines (23 loc) · 1.72 KB
/
publish.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
/* eslint-disable max-len */
const { execSync } = require('child_process');
const path = require('path');
const { readFileSync, writeFileSync } = require('fs');
const version = process.argv[2];
const semverRegex = /(?<=^[Vv]|^)(?:(?<major>(?:0|[1-9](?:(?:0|[1-9])+)*))[.](?<minor>(?:0|[1-9](?:(?:0|[1-9])+)*))[.](?<patch>(?:0|[1-9](?:(?:0|[1-9])+)*))(?:-(?<prerelease>(?:(?:(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?|(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?)|(?:0|[1-9](?:(?:0|[1-9])+)*))(?:[.](?:(?:(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?|(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?)|(?:0|[1-9](?:(?:0|[1-9])+)*)))*))?(?:[+](?<build>(?:(?:(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?|(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?)|(?:(?:0|[1-9])+))(?:[.](?:(?:(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?|(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?)|(?:(?:0|[1-9])+)))*))?)$/;
if (!version) {
process.exit();
}
if (!version.match(semverRegex)) {
console.error('Please enter a semantic version (e.g. 1.0.0).');
process.exit();
}
const srcPath = path.resolve(__dirname, '../src/', 'vcf-pdf-viewer.js');
let srcString = readFileSync(srcPath, 'utf8');
const replaceRegex = /get version.*?'(\d.\d.\d)';/s;
const matches = replaceRegex.exec(srcString);
srcString = srcString.replace(matches[0], matches[0].replace(matches[1], version));
writeFileSync(srcPath, srcString);
execSync(`git commit -a -m "Update src version: ${matches[1]} -> ${version}"`);
execSync(`npm version ${version}`);
execSync('git push');
execSync('npm publish --access public');