Skip to content

Commit

Permalink
'yarn rw dev' now only starts the API and DB servers when the api fol…
Browse files Browse the repository at this point in the history
…der is present
  • Loading branch information
ackinc authored and Justin Reidy committed May 19, 2020
1 parent 8b35c64 commit 711687b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/cli/src/commands/dev.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from 'fs'
import path from 'path'

import concurrently from 'concurrently'
Expand All @@ -16,15 +17,17 @@ export const handler = async ({ app = ['db', 'api', 'web'] }) => {
// For Windows: Replaces ` ` with `\ `. Damn, there has got to be a better
// way to sanitize paths?!
const BASE_DIR = getPaths().base.replace(' ', '\\ ')
const API_DIR = path.join(BASE_DIR, 'api')

// Generate the Prisma client if it doesn't exist.
await generatePrismaClient({ verbose: false, force: false })

const jobs = {
api: {
name: 'api',
command: `cd ${path.join(BASE_DIR, 'api')} && yarn dev-server`,
command: `cd ${API_DIR} && yarn dev-server`,
prefixColor: 'cyan',
runWhen: () => fs.existsSync(API_DIR),
},
db: {
name: ' db', // prefixed with ` ` to match output indentation.
Expand All @@ -33,6 +36,7 @@ export const handler = async ({ app = ['db', 'api', 'web'] }) => {
'api'
)} && yarn prisma generate --watch`,
prefixColor: 'magenta',
runWhen: () => fs.existsSync(API_DIR),
},
web: {
name: 'web',
Expand All @@ -41,13 +45,14 @@ export const handler = async ({ app = ['db', 'api', 'web'] }) => {
'web'
)} && yarn webpack-dev-server --config ../node_modules/@redwoodjs/core/config/webpack.development.js`,
prefixColor: 'blue',
runWhen: () => true,
},
}

concurrently(
Object.keys(jobs)
.map((n) => app.includes(n) && jobs[n])
.filter(Boolean),
.filter((job) => job.runWhen()),
{
restartTries: 3,
prefix: '{time} {name} |',
Expand Down

0 comments on commit 711687b

Please sign in to comment.