chore: add a script to check latest npm dist tags
This commit is contained in:
parent
05e17d69e5
commit
51a0c064c7
1 changed files with 44 additions and 0 deletions
44
scripts/check-npm-dist-tag.mjs
Normal file
44
scripts/check-npm-dist-tag.mjs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/* eslint-disable no-console */
|
||||
/* eslint-disable no-await-in-loop */
|
||||
import { promisify } from 'util';
|
||||
import { exec as execCallback } from 'child_process';
|
||||
import { readFile } from 'fs/promises';
|
||||
import { readdirSync } from 'fs';
|
||||
|
||||
const exec = promisify(execCallback);
|
||||
|
||||
const getDirectories = source =>
|
||||
readdirSync(source, { withFileTypes: true })
|
||||
.filter(pathMeta => pathMeta.isDirectory())
|
||||
.map(pathMeta => pathMeta.name);
|
||||
|
||||
async function checkNpmDistTag(folder) {
|
||||
const actions = [];
|
||||
console.log('| Name | Local Version | NPM dist tag latest | Check |');
|
||||
console.log('| ------------------------ | ------------- | ------------------- | ----- |');
|
||||
for (const subPackage of getDirectories(`./${folder}`)) {
|
||||
const filePath = `./${folder}/${subPackage}/package.json`;
|
||||
const packageJsonRaw = await readFile(filePath, 'utf-8');
|
||||
const packageJson = JSON.parse(packageJsonRaw.toString());
|
||||
const { version, name } = packageJson;
|
||||
|
||||
const { stdout } = await exec(`npm info ${name}@latest dist-tags.latest`);
|
||||
const latestVersion = stdout.trim();
|
||||
|
||||
console.log(
|
||||
`| ${name.padEnd(24, ' ')} | ${version.padEnd(13, ' ')} | ${latestVersion.padEnd(19, ' ')} | ${version !== latestVersion ? ' ❌ ' : ' ✓ '} |`,
|
||||
);
|
||||
|
||||
if (version !== latestVersion) {
|
||||
actions.push(`npm dist-tag add ${name}@${version} latest`);
|
||||
}
|
||||
}
|
||||
|
||||
if (actions.length) {
|
||||
console.log();
|
||||
console.log('FIX IT by running the following commands:');
|
||||
console.log(actions.join('\n'));
|
||||
}
|
||||
}
|
||||
|
||||
checkNpmDistTag('packages');
|
||||
Loading…
Reference in a new issue