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

60 lines
1.8 KiB
JavaScript
Raw Normal View History

2022-11-11 01:29:35 -05:00
/**
* This script runs the following tasks:
*
2022-12-29 01:52:43 -05:00
* 1. Tag the first package of fixed version groups defined in `.changeset/config.json` and other single packages if they are not tagged with the current version in `package.json`;
2022-11-11 01:29:35 -05:00
* 2. If no new git tag added, exit;
* 3. If at least one new git tag found, run `pnpm -r publish` and `git push --tags`.
*
* The subsequential release tasks, such as create GitHub release and build Docker image, will be took over by GitHub workflows.
*/
2022-12-29 01:52:43 -05:00
import { execSync } from 'child_process';
import { mainPackages, allPackages, singlePackages, corePackageName } from './packages-meta.js';
2022-11-11 01:04:31 -05:00
2022-12-29 01:52:43 -05:00
const taggedPackages = [...mainPackages, ...singlePackages]
2022-11-11 01:04:31 -05:00
.map((packageName) => {
const packageInfo = allPackages.find(({ name }) => name === packageName);
if (!packageInfo) {
throw new Error(`Package ${packageName} not found`);
}
const { name, version } = packageInfo;
if (!version) {
throw new Error(`No version found in package ${packageName}`);
}
const tag = name + '@' + version;
const hasTag = Boolean(execSync(`git tag -l ${tag}`, { encoding: 'utf8' }));
if (hasTag) {
console.log(`Tag ${tag} exists, skipping`);
return;
}
execSync(`git tag -a ${tag} -m'${tag}'`);
console.log(`Tag ${tag} added`);
2022-11-11 01:29:35 -05:00
if (packageName === corePackageName) {
const semver = 'v' + version;
execSync(`git tag -a ${semver} -m'${semver}'`);
console.log(`Tag ${semver} added (SemVer of core package ${corePackageName})`);
}
2022-11-11 01:04:31 -05:00
return packageName;
})
.filter((value) => !!value);
if (taggedPackages.length === 0) {
console.log('No package tagged, exiting');
process.exit(0);
}
2022-12-29 21:46:28 -05:00
try {
execSync('pnpm -r publish');
execSync('git push --follow-tags');
} catch (error) {
console.log(String(error.stdout));
throw error;
}