Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 19 additions & 0 deletions packages/cli/src/commands/__tests__/dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,25 @@ describe('yarn rw dev', () => {
expect(generateCommand.command).toEqual('yarn rw-gen-watch')
})

it('Should run custom side', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding a test 🙏

getConfig.mockReturnValue({
web: { port: 8910 },
api: { port: 8911 },
experimental: {
sides: { app: { workspace: 'app', devScript: 'android' } },
dev: { defaultSides: ['app'] },
},
})

await handler({ side: ['app'] })

const concurrentlyArgs = concurrently.mock.lastCall[0]

const appCommand = find(concurrentlyArgs, { name: 'app' })

expect(appCommand.command).toEqual('yarn workspace app run android')
})

it('Debug port passed in command line overrides TOML', async () => {
getConfig.mockReturnValue({
web: {
Expand Down
16 changes: 11 additions & 5 deletions packages/cli/src/commands/dev.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
import { terminalLink } from 'termi-link'

import { getConfig } from '@cedarjs/project-config'

import c from '../lib/colors.js'
import { checkNodeVersion } from '../middleware/checkNodeVersion.js'

export const command = 'dev [side..]'
export const description = 'Start development servers for api, and web'
export const description = 'Start development servers all your sides'

export const builder = (yargs) => {
// The reason `forward` is hidden is that it's been broken with Vite
// and it's not clear how to fix it.
const projectConfig = getConfig()

yargs
.positional('side', {
choices: ['api', 'web'],
default: ['api', 'web'],
choices: ['api', 'web', ...Object.keys(projectConfig.experimental.sides)],
default:
projectConfig.experimental.dev.defaultSides.length > 0
? projectConfig.experimental.dev.defaultSides
: ['api', 'web'],
description: 'Which dev server(s) to start',
type: 'array',
})
// The reason `forward` is hidden is that it's been broken with Vite
// and it's not clear how to fix it.
.option('forward', {
alias: 'fwd',
description:
Expand Down
18 changes: 15 additions & 3 deletions packages/cli/src/commands/devHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,24 +193,35 @@ export const handler = async ({
NODE_ENV: 'development',
NODE_OPTIONS: getDevNodeOptions(),
},
prefixColor: 'cyan',
runWhen: () => fs.existsSync(rwjsPaths.api.src),
},
web: {
name: 'web',
command: webCommand,
prefixColor: 'blue',
cwd: rwjsPaths.web.base,
runWhen: () => fs.existsSync(rwjsPaths.web.src),
},
gen: {
name: 'gen',
command: 'yarn rw-gen-watch',
prefixColor: 'green',
runWhen: () => generate,
},
}

side
.filter((sideName) => sideName !== 'api' && sideName !== 'web')
.forEach((sideName) => {
const sideConfig = getConfig().experimental.sides[sideName]

if (sideConfig) {
jobs[sideName] = {
name: sideName,
command: `yarn workspace ${sideConfig.workspace} run ${sideConfig.devScript}`,
runWhen: () => true,
}
}
})

// TODO: Convert jobs to an array and supply cwd command.
const { result } = concurrently(
Object.keys(jobs)
Expand All @@ -224,6 +235,7 @@ export const handler = async ({
prefix: '{name} |',
timestampFormat: 'HH:mm:ss',
handleInput: true,
prefixColors: 'auto',
},
)
result.catch((e) => {
Expand Down
4 changes: 4 additions & 0 deletions packages/project-config/src/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ describe('getConfig', () => {
},
],
},
"dev": {
"defaultSides": [],
},
"opentelemetry": {
"enabled": false,
"wrapApi": true,
Expand All @@ -69,6 +72,7 @@ describe('getConfig', () => {
"rsc": {
"enabled": false,
},
"sides": {},
"streamingSsr": {
"enabled": false,
},
Expand Down
16 changes: 16 additions & 0 deletions packages/project-config/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ interface StudioConfig {
graphiql?: GraphiQLStudioConfig
}

type Sides = Record<
string,
{
workspace: string
devScript: string
}
>

export interface Config {
web: BrowserTargetConfig
api: NodeTargetConfig
Expand Down Expand Up @@ -119,6 +127,10 @@ export interface Config {
enabled: boolean
lintOnly: boolean
}
sides: Sides
dev: {
defaultSides: string[]
}
}
}

Expand Down Expand Up @@ -205,6 +217,10 @@ const DEFAULT_CONFIG: Config = {
enabled: false,
lintOnly: false,
},
sides: {},
dev: {
defaultSides: [],
},
},
}

Expand Down
Loading