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.
|
2023-01-07 08:14:17 -05:00
|
|
|
// 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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-01-29 01:48:35 -05:00
|
|
|
const ignoreGroup = getIgnoreGroup();
|
|
|
|
const ignoreCmd = ignoreGroup
|
2022-12-30 00:49:00 -05:00
|
|
|
.map(({ name }) => ` \\\n --ignore ${name}`)
|
|
|
|
.join('');
|
|
|
|
const cmd = ('pnpm changeset version' + ignoreCmd);
|
|
|
|
|
2023-01-07 08:14:17 -05:00
|
|
|
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);
|
|
|
|
|
2023-01-29 01:48:35 -05:00
|
|
|
const filterCmd = ignoreGroup
|
|
|
|
.map(({ name }) => ` \\\n --filter \\!${name}`)
|
|
|
|
.join('');
|
2023-01-06 03:33:08 -05:00
|
|
|
// Manually run lifecycle script since changesets didn't
|
2023-01-29 01:48:35 -05:00
|
|
|
await execAsync(`pnpm -r ${filterCmd} version`).catch(catchCmdError);
|
2023-01-07 08:14:17 -05:00
|
|
|
|
|
|
|
// Sanity check for prepublish scripts
|
2023-01-29 01:48:35 -05:00
|
|
|
await execAsync(`pnpm -r ${filterCmd} prepublishOnly`).catch(catchCmdError);
|