Skip to content

Commit

Permalink
Merge pull request #124 from AthennaIO/develop
Browse files Browse the repository at this point in the history
feat(new): add new app
  • Loading branch information
jlenon7 authored Jan 15, 2025
2 parents 8a22677 + 239cca8 commit 44353fe
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/cli",
"version": "5.4.0",
"version": "5.5.0",
"description": "Athenna CLI to create new Athenna projects.",
"license": "MIT",
"author": "João Lenon <[email protected]>",
Expand Down
20 changes: 19 additions & 1 deletion src/console/commands/new.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class NewCommand extends BaseCommand {

const type = await this.prompt.list(
'What type of application do you wish to create?',
['REST API', 'CLI', 'CRON', 'WEB EDGE', 'WEB REACT'],
['REST API', 'CLI', 'CRON', 'WEB EDGE', 'WEB REACT', 'WEB REACT SSR'],
)

this.branch = this.getApplicationBranch(type)
Expand All @@ -45,6 +45,9 @@ export class NewCommand extends BaseCommand {
case 'WEB REACT':
await this.webReact()
break
case 'WEB REACT SSR':
await this.webReactSsr()
break
}
}

Expand All @@ -65,6 +68,7 @@ export class NewCommand extends BaseCommand {
'REST API': 'http',
'WEB EDGE': 'web-edge',
'WEB REACT': 'web-react',
'WEB REACT SSR': 'web-react-ssr',
}

return map[result]
Expand Down Expand Up @@ -137,6 +141,20 @@ export class NewCommand extends BaseCommand {
.render()
}

public async webReactSsr(): Promise<void> {
this.logger.simple('\n({bold,green} [ GENERATING WEB REACT SSR ])\n')

await this.clone()

this.logger
.instruction()
.head('Run following commands to get started:')
.add(`cd ${this.name}`)
.add('cp .env.example .env')
.add('node artisan serve')
.render()
}

public async clone(): Promise<void> {
let projectPath = `${Config.get('rc.callPath')}${sep}${this.name}`

Expand Down
18 changes: 18 additions & 0 deletions tests/e2e/console/commands/new.command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,24 @@ export default class NewCommandTest extends BaseConsoleTest {
assert.isTrue(await File.exists(Path.pwd('project/vite.config.ts')))
}

@Test()
public async shouldBeAbleToCreateAWebReactSsrProject({ command, assert }: Context) {
const output = await command.run('new project', {
path: Path.fixtures('consoles/confirm-web-react-ssr.ts'),
})

output.assertSucceeded()

assert.isFalse(await Folder.exists(Path.pwd('project/.git')))
assert.isFalse(await Folder.exists(Path.pwd('project/.github')))
assert.isFalse(await Folder.exists(Path.pwd('project/README.md')))
assert.isTrue(await File.exists(Path.pwd('project/.env')))
assert.isTrue(await File.exists(Path.pwd('project/.env.test')))
assert.isTrue(await File.exists(Path.pwd('project/.env.example')))
assert.isTrue(await File.exists(Path.pwd('project/bin/main.ts')))
assert.isTrue(await File.exists(Path.pwd('project/vite.config.ts')))
}

@Test()
public async shouldBeAbleToCreateADifferentArtisanFileForNodeJSVersionsBellowV20({ command, assert }: Context) {
const output = await command.run('new project', {
Expand Down
11 changes: 11 additions & 0 deletions tests/fixtures/consoles/confirm-web-react-ssr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Mock } from '@athenna/test'
import { Path } from '@athenna/common'
import { Ignite } from '@athenna/core'
import { Prompt } from '@athenna/artisan'

Mock.when(Prompt.prototype, 'confirm').resolve(false)
Mock.when(Prompt.prototype, 'list').resolve('WEB REACT SSR')

const ignite = await new Ignite().load(Path.toHref(Path.bin('artisan.ts')), { bootLogs: false })

await ignite.console(process.argv, { displayName: 'Artisan' })

0 comments on commit 44353fe

Please sign in to comment.