storybook/scripts/release/get-current-version.ts
2023-11-03 12:01:35 +01:00

28 lines
890 B
TypeScript

/* eslint-disable no-console */
import chalk from 'chalk';
import { setOutput } from '@actions/core';
import path from 'path';
import { readJson } from 'fs-extra';
import url from 'url';
const CODE_DIR_PATH = path.join(__dirname, '..', '..', 'code');
const CODE_PACKAGE_JSON_PATH = path.join(CODE_DIR_PATH, 'package.json');
export const getCurrentVersion = async () => {
console.log(`📐 Reading current version of Storybook...`);
const { version } = (await readJson(CODE_PACKAGE_JSON_PATH)) as { version: string };
if (process.env.GITHUB_ACTIONS === 'true') {
setOutput('current-version', version);
}
console.log(`📦 Current version is ${chalk.green(version)}`);
return version;
};
const modulePath = url.fileURLToPath(import.meta.url);
if (process.argv[1] === modulePath) {
getCurrentVersion().catch((err) => {
console.error(err);
process.exit(1);
});
}