Skip to content
Open
Show file tree
Hide file tree
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
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 () => {
getConfig.mockReturnValue({
web: { port: 8910 },
api: { port: 8911 },
experimental: {
sides: { app: { workspace: 'app', devScript: 'android' } },
cli: { 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 for 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.cli.dev.defaultSides.length > 0
? projectConfig.experimental.cli.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 @@ -46,6 +46,9 @@ describe('getConfig', () => {
"experimental": {
"cli": {
"autoInstall": true,
"dev": {
"defaultSides": [],
},
"plugins": [
{
"package": "@cedarjs/cli-storybook-vite",
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 @@ -104,6 +112,9 @@ export interface Config {
cli: {
autoInstall: boolean
plugins: CLIPlugin[]
dev: {
defaultSides: string[]
}
}
useSDLCodeGenForGraphQLTypes: boolean
streamingSsr: {
Expand All @@ -119,6 +130,7 @@ export interface Config {
enabled: boolean
lintOnly: boolean
}
sides: Sides
}
}

Expand Down Expand Up @@ -190,6 +202,9 @@ const DEFAULT_CONFIG: Config = {
package: '@cedarjs/cli-data-migrate',
},
],
dev: {
defaultSides: [],
},
},
useSDLCodeGenForGraphQLTypes: false,
streamingSsr: {
Expand All @@ -205,6 +220,7 @@ const DEFAULT_CONFIG: Config = {
enabled: false,
lintOnly: false,
},
sides: {},
},
}

Expand Down
Loading