Skip to content

Commit

Permalink
Merge pull request #490 from ackinc/fix/conditionally-start-api-and-db
Browse files Browse the repository at this point in the history
Fix: 'yarn rw dev' now only starts the API and DB servers when the api folder is present
  • Loading branch information
peterp committed May 5, 2020
2 parents 529f72a + 64826b2 commit 3bb22fc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 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,18 @@ 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')
const WEB_DIR = path.join(BASE_DIR, 'web')

// 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 +37,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 +46,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: () => fs.existsSync(WEB_DIR),
},
}

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

0 comments on commit 3bb22fc

Please sign in to comment.