feat: implement info command (#7882)
Implements `info` command similar to Next.js. `pnpm payload info` will output info in this format: ``` Binaries: Node: 18.20.2 npm: 10.5.0 Yarn: 1.22.19 pnpm: 9.7.0 Relevant Packages: payload: 3.0.0-beta.91 next: 15.0.0-canary.104 @payloadcms/db-mongodb: 3.0.0-beta.91 @payloadcms/db-postgres: 3.0.0-beta.91 @payloadcms/email-nodemailer: 3.0.0-beta.91 @payloadcms/graphql: 3.0.0-beta.91 @payloadcms/next/utilities: 3.0.0-beta.91 @payloadcms/plugin-cloud: 3.0.0-beta.91 @payloadcms/richtext-lexical: 3.0.0-beta.91 @payloadcms/richtext-slate: 3.0.0-beta.91 @payloadcms/translations: 3.0.0-beta.91 @payloadcms/ui/shared: 3.0.0-beta.91 react: 19.0.0-rc-06d0b89e-20240801 react-dom: 19.0.0-rc-06d0b89e-20240801 Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:13:04 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6020 Available memory (MB): 32768 Available CPU cores: 12 ```
This commit is contained in:
@@ -7,6 +7,7 @@ import type { BinScript } from '../config/types.js'
|
||||
import { findConfig } from '../config/find.js'
|
||||
import { generateImportMap } from './generateImportMap/index.js'
|
||||
import { generateTypes } from './generateTypes.js'
|
||||
import { info } from './info.js'
|
||||
import { loadEnv } from './loadEnv.js'
|
||||
import { migrate } from './migrate.js'
|
||||
|
||||
@@ -16,6 +17,11 @@ export const bin = async () => {
|
||||
const args = minimist(process.argv.slice(2))
|
||||
const script = (typeof args._[0] === 'string' ? args._[0] : '').toLowerCase()
|
||||
|
||||
if (script === 'info') {
|
||||
await info()
|
||||
return
|
||||
}
|
||||
|
||||
if (script === 'run') {
|
||||
const scriptPath = args._[1]
|
||||
if (!scriptPath) {
|
||||
|
||||
63
packages/payload/src/bin/info.ts
Normal file
63
packages/payload/src/bin/info.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { execFileSync } from 'child_process'
|
||||
import os from 'os'
|
||||
|
||||
import { getDependencies } from '../index.js'
|
||||
import { PAYLOAD_PACKAGE_LIST } from '../versions/payloadPackageList.js'
|
||||
|
||||
export const info = async () => {
|
||||
const deps = await getDependencies(process.cwd(), [
|
||||
...PAYLOAD_PACKAGE_LIST,
|
||||
'next',
|
||||
'react',
|
||||
'react-dom',
|
||||
])
|
||||
|
||||
const formattedDeps = Array.from(deps.resolved.entries()).map(([name, { version }]) => ({
|
||||
name,
|
||||
version,
|
||||
}))
|
||||
|
||||
console.log(generateOutput(formattedDeps))
|
||||
}
|
||||
|
||||
function generateOutput(packages: Array<{ name: string; version: string }>) {
|
||||
const cpuCores = os.cpus().length
|
||||
|
||||
const primaryDeps = packages.filter(({ name }) => name === 'payload' || name === 'next')
|
||||
const otherDeps = packages
|
||||
.filter(({ name }) => name !== 'payload' && name !== 'next')
|
||||
.sort((a, b) => a.name.localeCompare(b.name))
|
||||
|
||||
const formattedDeps = [...primaryDeps, ...otherDeps]
|
||||
.map(({ name, version }) => ` ${name}: ${version}`)
|
||||
.join('\n')
|
||||
|
||||
return `
|
||||
Binaries:
|
||||
Node: ${process.versions.node}
|
||||
npm: ${getBinaryVersion('npm')}
|
||||
Yarn: ${getBinaryVersion('yarn')}
|
||||
pnpm: ${getBinaryVersion('pnpm')}
|
||||
Relevant Packages:
|
||||
${formattedDeps}
|
||||
Operating System:
|
||||
Platform: ${os.platform()}
|
||||
Arch: ${os.arch()}
|
||||
Version: ${os.version()}
|
||||
Available memory (MB): ${Math.ceil(os.totalmem() / 1024 / 1024)}
|
||||
Available CPU cores: ${cpuCores > 0 ? cpuCores : 'N/A'}
|
||||
`
|
||||
}
|
||||
|
||||
function getBinaryVersion(binaryName: string) {
|
||||
try {
|
||||
return execFileSync(binaryName, ['--version']).toString().trim()
|
||||
} catch {
|
||||
return 'N/A'
|
||||
}
|
||||
}
|
||||
|
||||
// Direct execution
|
||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
||||
void info()
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { CustomVersionParser } from './utilities/dependencies/dependencyChecker.js'
|
||||
|
||||
import { checkDependencies } from './utilities/dependencies/dependencyChecker.js'
|
||||
import { PAYLOAD_PACKAGE_LIST } from './versions/payloadPackageList.js'
|
||||
|
||||
const customReactVersionParser: CustomVersionParser = (version) => {
|
||||
const [mainVersion, ...preReleases] = version.split('-')
|
||||
@@ -18,37 +19,7 @@ const customReactVersionParser: CustomVersionParser = (version) => {
|
||||
}
|
||||
|
||||
export async function checkPayloadDependencies() {
|
||||
const dependencies = [
|
||||
'@payloadcms/ui/shared',
|
||||
'payload',
|
||||
'@payloadcms/next/utilities',
|
||||
'@payloadcms/richtext-lexical',
|
||||
'@payloadcms/richtext-slate',
|
||||
'@payloadcms/graphql',
|
||||
'@payloadcms/plugin-cloud',
|
||||
'@payloadcms/db-mongodb',
|
||||
'@payloadcms/db-postgres',
|
||||
'@payloadcms/plugin-form-builder',
|
||||
'@payloadcms/plugin-nested-docs',
|
||||
'@payloadcms/plugin-seo',
|
||||
'@payloadcms/plugin-search',
|
||||
'@payloadcms/plugin-cloud-storage',
|
||||
'@payloadcms/plugin-stripe',
|
||||
'@payloadcms/plugin-zapier',
|
||||
'@payloadcms/plugin-redirects',
|
||||
'@payloadcms/bundler-webpack',
|
||||
'@payloadcms/bundler-vite',
|
||||
'@payloadcms/live-preview',
|
||||
'@payloadcms/live-preview-react',
|
||||
'@payloadcms/translations',
|
||||
'@payloadcms/email-nodemailer',
|
||||
'@payloadcms/email-resend',
|
||||
'@payloadcms/storage-azure',
|
||||
'@payloadcms/storage-s3',
|
||||
'@payloadcms/storage-gcs',
|
||||
'@payloadcms/storage-vercel-blob',
|
||||
'@payloadcms/storage-uploadthing',
|
||||
]
|
||||
const dependencies = [...PAYLOAD_PACKAGE_LIST]
|
||||
|
||||
if (process.env.PAYLOAD_CI_DEPENDENCY_CHECKER !== 'true') {
|
||||
dependencies.push('@payloadcms/plugin-sentry')
|
||||
|
||||
31
packages/payload/src/versions/payloadPackageList.ts
Normal file
31
packages/payload/src/versions/payloadPackageList.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
export const PAYLOAD_PACKAGE_LIST = [
|
||||
'payload',
|
||||
'@payloadcms/bundler-vite',
|
||||
'@payloadcms/bundler-webpack',
|
||||
'@payloadcms/db-mongodb',
|
||||
'@payloadcms/db-postgres',
|
||||
'@payloadcms/email-nodemailer',
|
||||
'@payloadcms/email-resend',
|
||||
'@payloadcms/graphql',
|
||||
'@payloadcms/live-preview-react',
|
||||
'@payloadcms/live-preview',
|
||||
'@payloadcms/next/utilities',
|
||||
'@payloadcms/plugin-cloud-storage',
|
||||
'@payloadcms/plugin-cloud',
|
||||
'@payloadcms/plugin-form-builder',
|
||||
'@payloadcms/plugin-nested-docs',
|
||||
'@payloadcms/plugin-redirects',
|
||||
'@payloadcms/plugin-search',
|
||||
'@payloadcms/plugin-seo',
|
||||
'@payloadcms/plugin-stripe',
|
||||
'@payloadcms/plugin-zapier',
|
||||
'@payloadcms/richtext-lexical',
|
||||
'@payloadcms/richtext-slate',
|
||||
'@payloadcms/storage-azure',
|
||||
'@payloadcms/storage-gcs',
|
||||
'@payloadcms/storage-s3',
|
||||
'@payloadcms/storage-uploadthing',
|
||||
'@payloadcms/storage-vercel-blob',
|
||||
'@payloadcms/translations',
|
||||
'@payloadcms/ui/shared',
|
||||
]
|
||||
Reference in New Issue
Block a user