From 7d8de8c0199bbf28133becbe88eedcf723a1edfc Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Fri, 11 Nov 2022 14:04:31 +0800 Subject: [PATCH] chore: add pubilsh script --- .changeset/config.json | 6 +++--- .scripts/publish.js | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 .scripts/publish.js diff --git a/.changeset/config.json b/.changeset/config.json index 99aa3618b..7a727f244 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -7,15 +7,15 @@ "@logto/cli", "@logto/create" ], [ - "@logto/console", "@logto/core", + "@logto/console", "@logto/integration-tests", "@logto/ui" ]], "linked": [[ + "@logto/schemas", "@logto/phrases", - "@logto/phrases-ui", - "@logto/schemas" + "@logto/phrases-ui" ]], "//": "END OF CAUTION", "access": "restricted", diff --git a/.scripts/publish.js b/.scripts/publish.js new file mode 100644 index 000000000..38324d2b1 --- /dev/null +++ b/.scripts/publish.js @@ -0,0 +1,41 @@ +const { execSync } = require('child_process'); +const changesetConfig = require('../.changeset/config.json'); + +/** @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`); + return packageName; + }) + .filter((value) => !!value); + +if (taggedPackages.length === 0) { + console.log('No package tagged, exiting'); + process.exit(0); +} + +execSync('pnpm -r publish'); +execSync('git push --tags');