0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00
logto/.scripts/version.js

52 lines
1.5 KiB
JavaScript
Raw Normal View History

2022-12-30 00:49:00 -05:00
import { exec } from 'node:child_process';
import { promisify } from 'node:util';
const execAsync = promisify(exec);
const versionGroup = process.argv[2];
if (process.argv.length > 3) {
throw new Error('Extraneous arguments found. Only one optional argument for version group name is allowed.');
}
// This is configured based on our practice. Change with care.
// Should be synced with `/.github/workflows/changesets.yml`
2022-12-30 00:49:00 -05:00
const allowedGroups = { core: 'core', toolkit: 'toolkit' };
if (!Object.values(allowedGroups).includes(versionGroup)) {
throw new Error('Version group is invalid. Should be one of ' + Object.values(allowedGroups).join(', ') + '.');
}
const { allPackages } = await import('./packages-meta.js');
const getIgnoreGroup = () => {
console.log(`=== Versioning ${versionGroup} group packages ===`);
return allPackages.filter(({ path }) => {
if (versionGroup === allowedGroups.toolkit) {
return !path.includes(allowedGroups.toolkit + '/');
}
return false;
});
}
const ignoreCmd = getIgnoreGroup()
.map(({ name }) => ` \\\n --ignore ${name}`)
.join('');
const cmd = ('pnpm changeset version' + ignoreCmd);
const catchCmdError = ({ stderr, stdout, code }) => {
console.log(stdout);
2022-12-30 00:49:00 -05:00
console.error(stderr);
process.exit(code ?? 1);
2023-01-06 03:33:08 -05:00
};
console.log(cmd);
await execAsync(cmd).catch(catchCmdError);
// Manually run lifecycle script since changesets didn't
await execAsync('pnpm -r version').catch(catchCmdError);
// Sanity check for prepublish scripts
await execAsync('pnpm -r prepublishOnly').catch(catchCmdError);