refactor: rewrite in typescript (#7)

This commit is contained in:
Elliot DeNolf
2021-09-10 16:56:37 -04:00
committed by GitHub
parent 64d0bc7a16
commit a1a4765a94
80 changed files with 3999 additions and 609 deletions

18
src/utils/log.ts Normal file
View File

@@ -0,0 +1,18 @@
import chalk from 'chalk'
import figures from 'figures'
export const success = (message: string): void => {
console.log(chalk.green(figures.tick) + ' ' + chalk.bold(message))
}
export const warning = (message: string): void => {
console.log(chalk.yellow('? ') + chalk.bold(message))
}
export const info = (message: string): void => {
console.log(chalk.yellow(figures.info) + ' ' + chalk.bold(message))
}
export const error = (message: string): void => {
console.log(chalk.red(figures.cross) + ' ' + chalk.bold(message))
}

52
src/utils/messages.ts Normal file
View File

@@ -0,0 +1,52 @@
import chalk from 'chalk'
import figures from 'figures'
import terminalLink from 'terminal-link'
import { getValidTemplates } from '../lib/templates'
const header = (message: string) =>
chalk.yellow(figures.star) + ' ' + chalk.bold(message)
export const welcomeMessage = chalk`
{green Welcome to Payload. Let's create a project! }
`
export async function helpMessage(): Promise<string> {
const validTemplates = await getValidTemplates()
return chalk`
{bold USAGE}
{dim $} {bold npx create-payload-app}
{bold OPTIONS}
--name {underline my-payload-app} Set project name
--template {underline template_name} Choose specific template
{dim Available templates: ${validTemplates.join(', ')}}
--use-npm Use npm to install dependencies
--no-deps Do not install any dependencies
--help Show help
`
}
export function successMessage(projectDir: string, packageManager: string): string {
return `
${header('Launch Application:')}
- cd ${projectDir}
- ${packageManager === 'yarn' ? 'yarn' : 'npm run'} dev
${header('Documentation:')}
- ${terminalLink(
'Getting Started',
'https://payloadcms.com/docs/getting-started/what-is-payload',
)}
- ${terminalLink(
'Configuration',
'https://payloadcms.com/docs/configuration/overview',
)}
`
}

32
src/utils/usage.ts Normal file
View File

@@ -0,0 +1,32 @@
import * as Sentry from '@sentry/node'
import type { Primitive, Transaction } from '@sentry/types'
import os from 'os'
type SentryTags = { [key: string]: Primitive }
export const init = (): Transaction => {
Sentry.init({
dsn: 'https://139de3d0197f464082d5715a0c48a497@o589961.ingest.sentry.io/5739829',
tracesSampleRate: 1.0,
})
Sentry.setTags({
os_type: os.type(),
os_platform: os.platform(),
os_release: os.release(),
node_version: process.version,
})
return Sentry.startTransaction({
op: 'create-payload-app',
name: 'New Project',
})
}
export const setTags = (tags: SentryTags): void => {
Sentry.setTags({ ...tags })
}
export const handleException = (e: unknown): void => {
Sentry.captureException(e)
}