Skip to content

Commit

Permalink
Use cli-helpers methods in the cli package
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe committed Sep 9, 2022
1 parent 6ff10af commit 8704d6b
Show file tree
Hide file tree
Showing 74 changed files with 263 additions and 265 deletions.
5 changes: 2 additions & 3 deletions packages/cli/src/commands/buildHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import VerboseRenderer from 'listr-verbose-renderer'
import rimraf from 'rimraf'
import terminalLink from 'terminal-link'

import { getPaths, colors } from '@redwoodjs/cli-helpers'
import { buildApi } from '@redwoodjs/internal/dist/build/api'
import { loadAndValidateSdls } from '@redwoodjs/internal/dist/validateSchema'
import { detectPrerenderRoutes } from '@redwoodjs/prerender/detection'
import { timedTelemetry, errorTelemetry } from '@redwoodjs/telemetry'

import { getPaths } from '../lib'
import c from '../lib/colors'
import { generatePrismaCommand } from '../lib/generatePrismaClient'

export const handler = async ({
Expand Down Expand Up @@ -149,7 +148,7 @@ export const handler = async ({
}
})
} catch (e) {
console.log(c.error(e.message))
console.log(colors.error(e.message))
errorTelemetry(process.argv, e.message)
process.exit(1)
}
Expand Down
9 changes: 4 additions & 5 deletions packages/cli/src/commands/check.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getPaths } from '../lib'
import c from '../lib/colors'
import { getPaths, colors } from '@redwoodjs/cli-helpers'

export const command = 'check'
export const aliases = ['diagnostics']
Expand All @@ -14,12 +13,12 @@ export const handler = async () => {
printDiagnostics(getPaths().base, {
getSeverityLabel: (severity) => {
if (severity === DiagnosticSeverity.Error) {
return c.error('error')
return colors.error('error')
}
if (severity === DiagnosticSeverity.Warning) {
return c.warning('warning')
return colors.warning('warning')
}
return c.info('info')
return colors.info('info')
},
})
}
3 changes: 1 addition & 2 deletions packages/cli/src/commands/consoleHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import fs from 'fs'
import path from 'path'
import repl from 'repl'

import { getPaths } from '@redwoodjs/cli-helpers'
import { registerApiSideBabelHook } from '@redwoodjs/internal/dist/build/babel/api'

import { getPaths } from '../lib'

const paths = getPaths()

const loadPrismaClient = (replContext) => {
Expand Down
10 changes: 4 additions & 6 deletions packages/cli/src/commands/dataMigrate/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,21 @@ import fs from 'fs-extra'
import Listr from 'listr'
import terminalLink from 'terminal-link'

import { getPaths, colors } from '@redwoodjs/cli-helpers'
import { errorTelemetry } from '@redwoodjs/telemetry'

import { getPaths } from '../../lib'
import c from '../../lib/colors'

const MODEL = `model RW_DataMigration {
version String @id
name String
startedAt DateTime
finishedAt DateTime
}`

const POST_INSTALL_INSTRUCTIONS = `${c.warning(
const POST_INSTALL_INSTRUCTIONS = `${colors.warning(
"Don't forget to apply your migration when ready:"
)}
${c.bold('yarn rw prisma migrate dev')}
${colors.bold('yarn rw prisma migrate dev')}
`

// Creates dataMigrations directory
Expand Down Expand Up @@ -93,7 +91,7 @@ export const handler = async () => {
await tasks.run()
} catch (e) {
errorTelemetry(process.argv, e.message)
console.error(c.error(e.message))
console.error(colors.error(e.message))
process.exit(e?.exitCode || 1)
}
}
16 changes: 8 additions & 8 deletions packages/cli/src/commands/dataMigrate/up.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import Listr from 'listr'
import VerboseRenderer from 'listr-verbose-renderer'
import terminalLink from 'terminal-link'

import { getPaths, colors } from '@redwoodjs/cli-helpers'
import { registerApiSideBabelHook } from '@redwoodjs/internal/dist/build/babel/api'
import { errorTelemetry } from '@redwoodjs/telemetry'

import { getPaths } from '../../lib'
import c from '../../lib/colors'

// sorts migrations by date, oldest first
const sortMigrations = (migrations) => {
return migrations.sort((a, b) => {
Expand Down Expand Up @@ -74,17 +72,17 @@ const report = (counters) => {
console.log('')
if (counters.run) {
console.info(
c.green(`${counters.run} data migration(s) completed successfully.`)
colors.green(`${counters.run} data migration(s) completed successfully.`)
)
}
if (counters.error) {
console.error(
c.error(`${counters.error} data migration(s) exited with errors.`)
colors.error(`${counters.error} data migration(s) exited with errors.`)
)
}
if (counters.skipped) {
console.warn(
c.warning(
colors.warning(
`${counters.skipped} data migration(s) skipped due to previous error.`
)
)
Expand Down Expand Up @@ -123,7 +121,9 @@ export const handler = async () => {

// exit immediately if there aren't any migrations to run
if (!migrations.length) {
console.info(c.green('\nNo data migrations run, already up-to-date.\n'))
console.info(
colors.green('\nNo data migrations run, already up-to-date.\n')
)
process.exit(0)
}

Expand Down Expand Up @@ -153,7 +153,7 @@ export const handler = async () => {
})
} catch (e) {
counters.error++
console.error(c.error(`Error in data migration: ${e.message}`))
console.error(colors.error(`Error in data migration: ${e.message}`))
}
},
}
Expand Down
11 changes: 6 additions & 5 deletions packages/cli/src/commands/deploy/baremetal.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import VerboseRenderer from 'listr-verbose-renderer'
import terminalLink from 'terminal-link'
import { titleCase } from 'title-case'

import { getPaths } from '../../lib'
import c from '../../lib/colors'
import { getPaths, colors } from '@redwoodjs/cli-helpers'

const CONFIG_FILENAME = 'deploy.toml'
const SYMLINK_FLAGS = '-nsf'
Expand Down Expand Up @@ -136,9 +135,11 @@ const sshExec = async (ssh, path, command, args) => {
})

if (result.code !== 0) {
console.error(c.error(`\nDeploy failed!`))
console.error(colors.error(`\nDeploy failed!`))
console.error(
c.error(`Error while running command \`${command} ${args.join(' ')}\`:`)
colors.error(
`Error while running command \`${command} ${args.join(' ')}\`:`
)
)
console.error(
boxen(result.stderr, {
Expand Down Expand Up @@ -685,7 +686,7 @@ export const handler = async (yargs) => {
})
await tasks.run()
} catch (e) {
console.error(c.error('\nDeploy failed:'))
console.error(colors.error('\nDeploy failed:'))
console.error(
boxen(e.stderr || e.message, {
padding: { top: 0, bottom: 0, right: 1, left: 1 },
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/commands/deploy/flightcontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import execa from 'execa'
import terminalLink from 'terminal-link'

import { apiServerHandler } from '@redwoodjs/api-server'
import { getPaths } from '@redwoodjs/cli-helpers'
import { getConfig } from '@redwoodjs/internal/dist/config'

import { getPaths } from '../../lib'

export const command = 'flightcontrol <side>'
export const alias = 'fc'
export const description =
Expand Down
6 changes: 2 additions & 4 deletions packages/cli/src/commands/deploy/helpers/helpers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import execa from 'execa'
import terminalLink from 'terminal-link'

import { getPaths } from '@redwoodjs/internal/dist/paths'

import c from '../../../lib/colors'
import { getPaths, colors } from '@redwoodjs/cli-helpers'

export const deployBuilder = (yargs) => {
yargs
Expand Down Expand Up @@ -47,7 +45,7 @@ export const deployHandler = async ({ build, prisma, dm: dataMigrate }) => {

const joinedCommands = commandSet.join(' && ')

console.log(c.green(`\nRunning:\n`) + `${joinedCommands} \n`)
console.log(colors.green(`\nRunning:\n`) + `${joinedCommands} \n`)

return execa(joinedCommands, {
shell: true,
Expand Down
10 changes: 4 additions & 6 deletions packages/cli/src/commands/deploy/layer0.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import fs from 'fs-extra'
import omit from 'lodash/omit'
import terminalLink from 'terminal-link'

import { getPaths } from '@redwoodjs/internal/dist/paths'

import c from '../../lib/colors'
import { getPaths, colors } from '@redwoodjs/cli-helpers'

import { deployBuilder, deployHandler } from './helpers/helpers'

Expand Down Expand Up @@ -104,7 +102,7 @@ export const ERR_MESSAGE_MISSING_CLI = buildErrorMessage(
[
'It looks like Layer0 is not configured for your project.',
'Run the following to add Layer0 to your project:',
` ${c.info('yarn add -D @layer0/cli')}`,
` ${colors.info('yarn add -D @layer0/cli')}`,
].join('\n')
)

Expand All @@ -113,13 +111,13 @@ export const ERR_MESSAGE_NOT_INITIALIZED = buildErrorMessage(
[
'It looks like Layer0 is not configured for your project.',
'Run the following to initialize Layer0 on your project:',
` ${c.info('yarn layer0 init')}`,
` ${colors.info('yarn layer0 init')}`,
].join('\n')
)

export function buildErrorMessage(title, message) {
return [
c.bold(c.error(title)),
colors.bold(colors.error(title)),
'',
message,
'',
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/commands/deploy/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import execa from 'execa'
import terminalLink from 'terminal-link'

import { apiServerHandler } from '@redwoodjs/api-server'
import { getPaths } from '@redwoodjs/cli-helpers'
import { getConfig } from '@redwoodjs/internal/dist/config'

import { getPaths } from '../../lib'

export const command = 'render <side>'
export const description = 'Build, Migrate, and Serve command for Render deploy'
export const builder = (yargs) => {
Expand Down
15 changes: 7 additions & 8 deletions packages/cli/src/commands/deploy/serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import VerboseRenderer from 'listr-verbose-renderer'
import prompts from 'prompts'
import terminalLink from 'terminal-link'

import { getPaths } from '../../lib'
import c from '../../lib/colors'
import { getPaths, colors } from '@redwoodjs/cli-helpers'

export const command = 'serverless'
export const aliases = ['aws serverless', 'sls']
Expand Down Expand Up @@ -152,7 +151,7 @@ export const handler = async (yargs) => {
const SETUP_MARKER = chalk.bgBlue(chalk.black('First Setup '))
console.log()

console.log(SETUP_MARKER, c.green('Starting first setup wizard...'))
console.log(SETUP_MARKER, colors.green('Starting first setup wizard...'))

const { stdout: slsInfo } = await execa(
`yarn serverless info --verbose --stage=${yargs.stage}`,
Expand All @@ -165,7 +164,7 @@ export const handler = async (yargs) => {
const deployedApiUrl = slsInfo.match(/HttpApiUrl: (https:\/\/.*)/)[1]

console.log()
console.log(SETUP_MARKER, `Found ${c.green(deployedApiUrl)}`)
console.log(SETUP_MARKER, `Found ${colors.green(deployedApiUrl)}`)
console.log()

const { addDotEnv } = await prompts({
Expand Down Expand Up @@ -223,15 +222,15 @@ export const handler = async (yargs) => {
const deployedWebUrl = slsInfo.match(/url: (https:\/\/.*)/)[1]

const message = [
c.bold('Successful first deploy!'),
colors.bold('Successful first deploy!'),
'',
`View your deployed site at: ${c.green(deployedWebUrl)}`,
`View your deployed site at: ${colors.green(deployedWebUrl)}`,
'',
'You can use serverless.com CI/CD by connecting/creating an app',
'To do this run `yarn serverless` on each of the sides, and connect your account',
'',
'Find more information in our docs:',
c.underline('https://redwoodjs.com/docs/deploy#serverless'),
colors.underline('https://redwoodjs.com/docs/deploy#serverless'),
]

console.log(
Expand All @@ -244,7 +243,7 @@ export const handler = async (yargs) => {
}
}
} catch (e) {
console.error(c.error(e.message))
console.error(colors.error(e.message))
process.exit(e?.exitCode || 1)
}
}
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/commands/destroy/graphiql/graphiql.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import Listr from 'listr'

import { colors } from '@redwoodjs/cli-helpers'

import {
existsAnyExtensionSync,
deleteFile,
readFile,
writeFile,
getGraphqlPath,
} from '../../../lib'
import c from '../../../lib/colors'
import { getOutputPath } from '../../setup/graphiql/graphiql'

const removeGraphiqlFromGraphqlHandler = () => {
Expand Down Expand Up @@ -51,6 +52,6 @@ export const handler = () => {
try {
tasks.run()
} catch (e) {
console.log(c.error(e.message))
console.log(colors.error(e.message))
}
}
5 changes: 2 additions & 3 deletions packages/cli/src/commands/destroy/helpers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Listr from 'listr'

import { deleteFilesTask } from '../../lib'
import c from '../../lib/colors'

import { colors } from '@redwoodjs/cli-helpers'
const tasks = ({ componentName, filesFn, name }) =>
new Listr(
[
Expand Down Expand Up @@ -36,7 +35,7 @@ export const createYargsForComponentDestroy = ({
options = await preTasksFn({ ...options, isDestroyer: true })
await tasks({ componentName, filesFn, name: options.name }).run()
} catch (e) {
console.log(c.error(e.message))
console.log(colors.error(e.message))
}
},
tasks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import fs from 'fs'

import '../../../../lib/test'

import { getPaths } from '../../../../lib'
import { getPaths } from '@redwoodjs/cli-helpers'

import { files } from '../../../generate/page/page'
import { tasks } from '../page'

Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/commands/destroy/page/page.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import camelcase from 'camelcase'
import Listr from 'listr'

import { colors } from '@redwoodjs/cli-helpers'

import { deleteFilesTask, removeRoutesFromRouterTask } from '../../../lib'
import c from '../../../lib/colors'
import { pathName } from '../../generate/helpers'
import {
files as pageFiles,
Expand Down Expand Up @@ -52,6 +53,6 @@ export const handler = async ({ name, path }) => {
try {
await t.run()
} catch (e) {
console.log(c.error(e.message))
console.log(colors.error(e.message))
}
}
Loading

0 comments on commit 8704d6b

Please sign in to comment.