Files
payloadcms/scripts/pack-all-to-dest.ts
Elliot DeNolf 5fc9f76406 feat: filename compound index (#7651)
Allow a compound index to be used for upload collections via a
`filenameCompoundIndex` field. Previously, `filename` was always treated
as unique.

Usage:

```ts
{
  slug: 'upload-field',
   upload: {
     // Slugs to include in compound index
     filenameCompoundIndex: ['filename', 'alt'],
  },
}
```
2024-08-13 13:55:10 -04:00

78 lines
1.9 KiB
TypeScript

import type { ExecSyncOptions } from 'child_process'
import type execa from 'execa'
import chalk from 'chalk'
import { exec as execOrig, execSync } from 'child_process'
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',
'ui',
'next',
'db-mongodb',
'drizzle',
'db-sqlite',
'db-postgres',
'richtext-lexical',
'translations',
'plugin-cloud',
'graphql',
]
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<typeof p, null> => p !== null)
header(`\nOutputting ${filtered.length} packages...
${chalk.white.bold(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 pack -C ${p.packagePath} --pack-destination ${resolvedDest}`)
}),
)
header(`\n🎉 Done!`)
}
function header(message: string, opts?: { enable?: boolean }) {
console.log(chalk.bold.green(`${message}\n`))
}