-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathmessages.ts
More file actions
116 lines (85 loc) · 3.79 KB
/
messages.ts
File metadata and controls
116 lines (85 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* eslint-disable no-console */
import chalk from 'chalk'
import path from 'path'
import terminalLink from 'terminal-link'
import type { PackageManager, ProjectTemplate } from '../types.js'
import { getValidTemplates } from '../lib/templates.js'
const header = (message: string): string => chalk.bold(message)
export const welcomeMessage = chalk`
{green Welcome to Payload. Let's create a project! }
`
const spacer = ' '.repeat(8)
export function helpMessage(): void {
const validTemplates = getValidTemplates()
console.log(chalk`
{bold USAGE}
{dim Inside of an existing Next.js project}
{dim $} {bold npx create-payload-app}
{dim Create a new project from scratch}
{dim $} {bold npx create-payload-app}
{dim $} {bold npx create-payload-app} my-project
{dim $} {bold npx create-payload-app} -n my-project -t template-name
{bold OPTIONS}
-n {underline my-payload-app} Set project name
-t {underline template_name} Choose specific template
-e {underline example_name} Choose specific example
{dim Available templates: ${formatTemplates(validTemplates)}}
-a {underline agent_name} Set coding agent (claude, codex, cursor)
{dim Installs the Payload skill for the selected agent}
--no-agent Skip agent skill installation
--use-npm Use npm to install dependencies
--use-yarn Use yarn to install dependencies
--use-pnpm Use pnpm to install dependencies
--use-bun Use bun to install dependencies (experimental)
--no-deps Do not install any dependencies
-h Show help
`)
}
function formatTemplates(templates: ProjectTemplate[]) {
return `\n\n${spacer}${templates
.map((t) => `${t.name}${' '.repeat(28 - t.name.length)}${t.description}`)
.join(`\n${spacer}`)}`
}
export function successMessage(projectDir: string, packageManager: PackageManager): string {
const relativePath = path.relative(process.cwd(), projectDir)
return `
${header('Launch Application:')}
- cd ./${relativePath}
- ${packageManager === 'npm' ? 'npm run' : packageManager} dev or follow directions in README.md
${header('Documentation:')}
- ${createTerminalLink(
'Getting Started',
'https://payloadcms.com/docs/getting-started/what-is-payload',
)}
- ${createTerminalLink('Configuration', 'https://payloadcms.com/docs/configuration/overview')}
`
}
export function successfulNextInit(): string {
return `- ${createTerminalLink(
'Getting Started',
'https://payloadcms.com/docs/getting-started/what-is-payload',
)}
- ${createTerminalLink('Configuration', 'https://payloadcms.com/docs/configuration/overview')}
`
}
export function moveMessage(args: { nextAppDir: string; projectDir: string }): string {
const relativeAppDir = path.relative(process.cwd(), args.nextAppDir)
return `
${header('Next Steps:')}
Payload does not support a top-level layout.tsx file in the app directory.
${chalk.bold('To continue:')}
- Create a new directory in ./${relativeAppDir} such as ./${relativeAppDir}/${chalk.bold('(app)')}
- Move all files from ./${relativeAppDir} into that directory
It is recommended to do this from your IDE if your app has existing file references.
Once moved, rerun the create-payload-app command again.
`
}
export function feedbackOutro(): string {
return `${chalk.bgCyan(chalk.black(' Have feedback? '))} Visit us on ${createTerminalLink('GitHub', 'https://github.com/payloadcms/payload')}.`
}
// Create terminalLink with fallback for unsupported terminals
function createTerminalLink(text: string, url: string) {
return terminalLink(text, url, {
fallback: (text, url) => `${text}: ${url}`,
})
}