diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 8fc0495b..944d4a59 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -68,7 +68,9 @@ jobs: run: pnpm install --frozen-lockfile - name: Build - run: pnpm run build + run: | + pnpm run build + pnpm tsx packages/cli/scripts/post-build.ts - name: Lint run: pnpm run lint diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 19457988..471c2b52 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -36,7 +36,9 @@ jobs: run: pnpm install --frozen-lockfile - name: Build - run: pnpm run build + run: | + pnpm run build + pnpm tsx packages/cli/scripts/post-build.ts - name: Get version from package.json id: version diff --git a/packages/cli/scripts/post-build.ts b/packages/cli/scripts/post-build.ts new file mode 100644 index 00000000..99d4e3fb --- /dev/null +++ b/packages/cli/scripts/post-build.ts @@ -0,0 +1,20 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const token = process.env.TELEMETRY_TRACKING_TOKEN ?? ''; + +if (!token) { + console.warn('TELEMETRY_TRACKING_TOKEN is not set.'); +} + +const filesToProcess = ['dist/index.js', 'dist/index.cjs']; +const _dirname = path.dirname(fileURLToPath(import.meta.url)); + +for (const file of filesToProcess) { + console.log(`Processing ${file} for telemetry token...`); + const filePath = path.join(_dirname, '..', file); + const content = fs.readFileSync(filePath, 'utf-8'); + const updatedContent = content.replace('', token); + fs.writeFileSync(filePath, updatedContent, 'utf-8'); +} diff --git a/packages/cli/tsup.config.ts b/packages/cli/tsup.config.ts index c1881d32..2496f3ea 100644 --- a/packages/cli/tsup.config.ts +++ b/packages/cli/tsup.config.ts @@ -1,5 +1,3 @@ -import fs from 'node:fs'; -import path from 'node:path'; import { defineConfig } from 'tsup'; export default defineConfig({ @@ -12,19 +10,4 @@ export default defineConfig({ clean: true, dts: true, format: ['esm', 'cjs'], - onSuccess: async () => { - if (!process.env['TELEMETRY_TRACKING_TOKEN']) { - return; - } - const filesToProcess = ['dist/index.js', 'dist/index.cjs']; - for (const file of filesToProcess) { - console.log(`Processing ${file} for telemetry token...`); - const content = fs.readFileSync(path.join(__dirname, file), 'utf-8'); - const updatedContent = content.replace( - '', - process.env['TELEMETRY_TRACKING_TOKEN'], - ); - fs.writeFileSync(file, updatedContent, 'utf-8'); - } - }, });