Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: 'yarn rw dev' now only starts the API and DB servers when the api folder is present #490

Merged
merged 2 commits into from
May 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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