2022-11-11 01:29:35 -05:00
|
|
|
/**
|
|
|
|
* This script runs the following tasks:
|
|
|
|
*
|
|
|
|
* 1. Tag main packages defined in `.changeset/config.json` if they are not tagged with the current version in `package.json`;
|
|
|
|
* 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-11-11 01:04:31 -05:00
|
|
|
const { execSync } = require('child_process');
|
|
|
|
const changesetConfig = require('../.changeset/config.json');
|
|
|
|
|
2022-11-11 01:29:35 -05:00
|
|
|
const corePackageName = '@logto/core';
|
2022-11-11 01:04:31 -05:00
|
|
|
/** @type {Array<{ name: string; version?: string; path: string; private: boolean; }>} */
|
|
|
|
const allPackages = JSON.parse(execSync('pnpm recursive list --depth=-1 --json', { encoding: 'utf8' }));
|
|
|
|
const mainPackages = [...changesetConfig.fixed, ...changesetConfig.linked].map(([first]) => first);
|
|
|
|
|
|
|
|
const taggedPackages = mainPackages
|
|
|
|
.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);
|
|
|
|
}
|
|
|
|
|
|
|
|
execSync('pnpm -r publish');
|
2022-11-16 05:20:06 -05:00
|
|
|
execSync('git push --follow-tags');
|