Skip to content

Commit

Permalink
feat(create-robo): added colyseus as an optional feature for apps
Browse files Browse the repository at this point in the history
  • Loading branch information
Pkmmte committed Apr 24, 2024
1 parent 9d3ff73 commit 4bd78da
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-terms-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-robo': patch
---

feat: added colyseus as an optional feature for apps
41 changes: 35 additions & 6 deletions packages/create-robo/src/robo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import {
ROBO_CONFIG_APP,
Indent,
ExecOptions,
Space
Space,
COLYSEUS_CONFIG
} from './utils.js'
import { RepoInfo, downloadAndExtractRepo, getRepoInfo, hasRepo } from './templates.js'
import retry from 'async-retry'
Expand Down Expand Up @@ -66,6 +67,12 @@ const optionalFeatures = [
value: 'prettier',
checked: true
},
{
name: `${chalk.bold('Colyseus')} - Multiplayer Framework for Node.js.`,
short: 'Colyseus',
value: 'colyseus',
checked: false
},
{
name: `${chalk.bold('ESLint')} ${Recommended} - Keeps your code clean and consistent.`,
short: 'ESLint',
Expand Down Expand Up @@ -108,9 +115,7 @@ const botPlugins = [
value: 'ai'
},
{
name: `${chalk.bold(
'AI Voice'
)} - Give your Robo a voice! Command and converse with it in voice channels.`,
name: `${chalk.bold('AI Voice')} - Give your Robo a voice! Command and converse with it in voice channels.`,
short: 'AI Voice',
value: 'ai-voice'
},
Expand Down Expand Up @@ -362,6 +367,12 @@ export default class Robo {
this._spinner.stop(false)
logger.log(Indent, chalk.red(` Could not install plugins!`))
}

// If Colyseus is selected, override the /config/plugins/robojs/server.mjs file
if (this._selectedFeatures.includes('colyseus')) {
logger.debug(`Overriding Colyseus server config file...`)
await fs.writeFile(path.join(this._workingDir, 'config', 'plugins', 'robojs', 'server.mjs'), COLYSEUS_CONFIG)
}
}

async downloadTemplate(url: string) {
Expand Down Expand Up @@ -476,7 +487,11 @@ export default class Robo {
logger.debug('\n')
logger.log(
Indent,
chalk.bold(`📦 Creating ${chalk.cyan(this._useTypeScript ? 'TypeScript' : 'JavaScript')} ${this._isPlugin ? 'plugin' : 'project'}`)
chalk.bold(
`📦 Creating ${chalk.cyan(this._useTypeScript ? 'TypeScript' : 'JavaScript')} ${
this._isPlugin ? 'plugin' : 'project'
}`
)
)
this._spinner.setText(Indent + ' {{spinner}} Generating files...\n')
this._spinner.start()
Expand Down Expand Up @@ -567,6 +582,18 @@ export default class Robo {
devDependencies.push('@vitejs/plugin-react-swc')
devDependencies.push('eslint-plugin-react-hooks')
}

// Colyseus requires more dependencies
if (features.includes('colyseus')) {
dependencies.push('@colyseus/core')
dependencies.push('@colyseus/monitor')
dependencies.push('@colyseus/schema')
dependencies.push('@colyseus/ws-transport')
dependencies.push('@robojs/server')
dependencies.push('colyseus.js')
dependencies.push('express')
devDependencies.push('@types/express')
}

// Generate customized documentation
if (this._isPlugin) {
Expand Down Expand Up @@ -792,7 +819,9 @@ export default class Robo {
}

private getTemplate(): string {
if (this._isApp && this._selectedFeatures.includes('react')) {
if (this._isApp && this._selectedFeatures.includes('react') && this._selectedFeatures.includes('colyseus')) {
return this._useTypeScript ? '../templates/activity-ts-colyseus-react' : '../templates/activity-ts-colyseus-react'
} else if (this._isApp && this._selectedFeatures.includes('react')) {
return this._useTypeScript ? '../templates/app-ts-react' : '../templates/app-js-react'
} else if (this._isApp) {
return this._useTypeScript ? '../templates/app-ts' : '../templates/app-js'
Expand Down
7 changes: 7 additions & 0 deletions packages/create-robo/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ export const Space = ' '.repeat(8)

export const IS_WINDOWS = /^win/.test(process.platform)

export const COLYSEUS_CONFIG = `// @ts-check
import { ColyseusServerEngine } from '../../../.robo/build/core/server.js'
export default {
engine: new ColyseusServerEngine()
}\n`

export const PRETTIER_CONFIG = `export default {
printWidth: 120,
semi: false,
Expand Down

0 comments on commit 4bd78da

Please sign in to comment.