chore(create-payload-app): console.log wrapper

This commit is contained in:
Elliot DeNolf
2024-03-29 13:23:25 -04:00
parent 7d7b232fdb
commit 77f401d977
5 changed files with 22 additions and 14 deletions

View File

@@ -8,6 +8,7 @@ import path from 'path'
import type { CliArgs, DbDetails, PackageManager, ProjectTemplate } from '../types.js'
import { log } from '../utils/log.js'
import { debug, error, success, warning } from '../utils/log.js'
import { configurePayloadConfig } from './configure-payload-config.js'
@@ -60,13 +61,13 @@ export async function createProject(args: {
const { cliArgs, dbDetails, packageManager, projectDir, projectName, template } = args
if (cliArgs['--dry-run']) {
console.log(`\n Dry run: Creating project in ${chalk.green(projectDir)}\n`)
log(`\n Dry run: Creating project in ${chalk.green(projectDir)}\n`)
return
}
await createOrFindProjectDir(projectDir)
console.log(`\n Creating project in ${chalk.green(projectDir)}\n`)
log(`\n Creating project in ${chalk.green(projectDir)}\n`)
if (cliArgs['--local-template']) {
// Copy template from local path. For development purposes.

View File

@@ -1,13 +1,13 @@
import type { CompilerOptions } from 'typescript'
import chalk from 'chalk'
import { parse, stringify } from 'comment-json'
import execa from 'execa'
import fs from 'fs'
import fse from 'fs-extra'
import globby from 'globby'
import path from 'path'
import { promisify } from 'util'
import { log } from '../utils/log.js'
const readFile = promisify(fs.readFile)
const writeFile = promisify(fs.writeFile)
@@ -50,7 +50,7 @@ export async function initNext(args: InitNextArgs): Promise<InitNextResult> {
const layoutPath = path.resolve(nextAppDir, 'layout.tsx')
if (fs.existsSync(layoutPath)) {
// Output directions for user to move all files from app to top-level directory named `(name)`
console.log(moveMessage({ nextAppDir, projectDir }))
log(moveMessage({ nextAppDir, projectDir }))
return { reason: 'Found existing layout.tsx in app directory', success: false }
}

View File

@@ -3,6 +3,7 @@ import { parseModule } from 'esprima'
import fs from 'fs'
import { warning } from '../utils/log.js'
import { log } from '../utils/log.js'
export const withPayloadImportStatement = `import { withPayload } from '@payloadcms/next'\n`
@@ -90,7 +91,7 @@ function warnUserWrapNotSuccessful() {
`
console.log(withPayloadMessage)
log(withPayloadMessage)
}
type Directive = {

View File

@@ -1,4 +1,3 @@
/* eslint-disable no-console */
import slugify from '@sindresorhus/slugify'
import arg from 'arg'
import { detect } from 'detect-package-manager'
@@ -15,7 +14,7 @@ import { parseTemplate } from './lib/parse-template.js'
import { selectDb } from './lib/select-db.js'
import { getValidTemplates, validateTemplate } from './lib/templates.js'
import { writeEnvFile } from './lib/write-env-file.js'
import { debug, error, success } from './utils/log.js'
import { debug, error, log, success } from './utils/log.js'
import { helpMessage, successMessage, welcomeMessage } from './utils/messages.js'
export class Main {
@@ -66,10 +65,10 @@ export class Main {
try {
if (this.args['--help']) {
console.log(helpMessage())
log(helpMessage())
process.exit(0)
}
console.log(welcomeMessage)
log(welcomeMessage)
// Detect if inside Next.js project
const foundConfig = (
@@ -108,7 +107,7 @@ export class Main {
if (templateArg) {
const valid = validateTemplate(templateArg)
if (!valid) {
console.log(helpMessage())
log(helpMessage())
process.exit(1)
}
}
@@ -150,9 +149,9 @@ export class Main {
}
success('Payload project successfully created')
console.log(successMessage(projectDir, packageManager))
} catch (error: unknown) {
console.log(error)
log(successMessage(projectDir, packageManager))
} catch (err: unknown) {
error(err instanceof Error ? err.message : 'An error occurred')
}
}
}

View File

@@ -25,3 +25,10 @@ export const debug = (message: string): void => {
`${chalk.gray(figures.pointerSmall)} ${chalk.bgGray('[DEBUG]')} ${chalk.gray(message)}`,
)
}
/**
* console.log passthrough
*/
export const log = (message: string): void => {
console.log(message)
}