Skip to content

Commit

Permalink
add script
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw committed Feb 14, 2024
1 parent 5683928 commit 1934df8
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions js/scripts/check-npm-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { execSync } from 'child_process';
import fs from 'fs';
import { fileURLToPath } from 'url';
import path from 'path';

// Convert the URL to a file path
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// Adjust the path to your package.json as necessary
const packageJsonPath = path.join(__dirname, '../package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, { encoding: 'utf-8' }));
const { version } = packageJson;
const { name: packageName } = packageJson;

try {
const npmVersion = execSync(`npm view ${packageName} version`, { encoding: 'utf-8' }).trim();
if (npmVersion && version <= npmVersion) {
console.error(`Current version ${version} is not greater than npm version ${npmVersion}.`);
process.exit(1); // Exit with error
} else {
console.log(`Current version ${version} is greater than npm version ${npmVersion}. Proceeding with publish.`);
}
} catch (error) {
console.error('Error checking version:', error);
process.exit(1); // Exit with error if the check fails
}

0 comments on commit 1934df8

Please sign in to comment.