diff --git a/package.json b/package.json index 2b8a7540b..bd84d20db 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "pretest": "pnpm build", "reinstall": "pnpm clean:all && pnpm install", "script:list-packages": "tsx ./scripts/list-packages.ts", + "script:pack": "tsx scripts/pack-all-to-dest.ts", "release:alpha": "tsx ./scripts/release.ts --bump prerelease --tag alpha", "release:beta": "tsx ./scripts/release.ts --bump prerelease --tag beta", "test": "pnpm test:int && pnpm test:components && pnpm test:e2e", diff --git a/scripts/pack-all-to-dest.ts b/scripts/pack-all-to-dest.ts new file mode 100644 index 000000000..b46a7c568 --- /dev/null +++ b/scripts/pack-all-to-dest.ts @@ -0,0 +1,79 @@ +import type { ExecSyncOptions } from 'child_process' + +import chalk from 'chalk' +import { exec as execOrig, execSync } from 'child_process' +import execa from 'execa' +import fse from 'fs-extra' +import minimist from 'minimist' +import { fileURLToPath } from 'node:url' +import path from 'path' +import util from 'util' + +import { getPackageDetails } from './lib/getPackageDetails.js' + +const execOpts: ExecSyncOptions = { stdio: 'inherit' } +const execaOpts: execa.Options = { stdio: 'inherit' } + +const __filename = fileURLToPath(import.meta.url) +const __dirname = path.dirname(__filename) + +const exec = util.promisify(execOrig) + +main().catch((error) => { + console.error(error) + process.exit(1) +}) + +async function main() { + const args = minimist(process.argv.slice(2)) + const { dest } = args + if (!dest) throw new Error('--dest is required') + + const resolvedDest = path.resolve(dest) + + const packageWhitelist = [ + 'payload', + 'translations', + 'ui', + 'next', + 'graphql', + 'db-mongodb', + 'db-postgres', + 'richtext-slate', + 'richtext-lexical', + ] + + const packageDetails = await getPackageDetails(packageWhitelist) + + // Prebuild all packages + header(`\nšŸ”Ø Prebuilding all packages...`) + + await execa('pnpm', ['install'], execaOpts) + + const filtered = packageDetails.filter((p): p is Exclude => p !== null) + + header(`\n Outputting ${filtered.length} packages... + + ${filtered.map((p) => p.name).join('\n')} +`) + + execSync('pnpm build:all --output-logs=errors-only', { stdio: 'inherit' }) + + header(`\n šŸ“¦ Packing all packages to ${dest}...`) + + await Promise.all( + filtered.map(async (p) => { + await exec(`pnpm -r --filter ${p.shortName} run prepublishOnly`) + await exec(`pnpm pack -C ${p.packagePath} --pack-destination ${resolvedDest}`) + }), + ) + + header(`\nšŸŽ‰ Done!`) +} + +function header(message: string, opts?: { enable?: boolean }) { + const { enable } = opts ?? {} + if (!enable) return + + console.log(chalk.bold.green(`${message}\n`)) +}