Modules all the way
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
const version = require('../package.json').version;
|
||||
const semver = require('semver');
|
||||
import esMain from 'es-main';
|
||||
import process from 'process';
|
||||
import semver from 'semver';
|
||||
import {promises as fs} from 'fs';
|
||||
|
||||
function nextVersion() {
|
||||
async function nextVersion() {
|
||||
const pkg = await fs.readFile('../package.json', {encoding: 'utf8'});
|
||||
const version = JSON.parse(pkg).version;
|
||||
const s = semver.parse(version);
|
||||
if (!s) {
|
||||
throw new Error(`Invalid version ${version}`);
|
||||
@@ -9,6 +13,13 @@ function nextVersion() {
|
||||
return `${s.major}.${s.minor}.${s.patch}-dev.${Date.now()}`;
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
process.stdout.write(`${nextVersion()}\n`);
|
||||
if (esMain(import.meta)) {
|
||||
nextVersion()
|
||||
.then((version) => {
|
||||
process.stdout.write(`${version}\n`);
|
||||
})
|
||||
.catch((error) => {
|
||||
process.stderr.write(`${error}\n`);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user