import childProcess from 'node:child_process'; import { promisify } from 'node:util'; import SentryCli from '@sentry/cli'; import './setup.ts'; import { getUrlForLocale } from '../src/domain.ts'; const exec = promisify(childProcess.exec); const version = (await exec('git log -n 1 --pretty=format:"%H"')).stdout; const notifyRelease = async () => { if (!process.env.NUXT_PUBLIC_SENTRY_DSN) { process.stdout.write('SENTRY_DSN is not defined, skipping deployment information to Sentry'); return; } const sentryCli = new SentryCli(); await sentryCli.releases.new(version); await sentryCli.releases.setCommits(version, { auto: true, }); await sentryCli.releases.finalize(version); }; const notifyDeployment = async () => { if (!process.env.NUXT_PUBLIC_SENTRY_DSN) { process.stdout.write('SENTRY_DSN is not defined, skipping deployment information to Sentry'); return; } const environment = process.env.NUXT_PUBLIC_ENV ?? 'default'; const sentryCli = new SentryCli(); await sentryCli.releases.newDeploy(version, { env: environment, url: getUrlForLocale('_'), }); process.stdout.write(`Sent deployment information for environment ${environment} to Sentry`); }; const main = async () => { switch (process.argv[1]) { case 'release': await notifyRelease(); break; case 'deploy': await notifyDeployment(); break; } }; await main();