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

feat(new): add new app #124

Merged
merged 1 commit into from
Jan 15, 2025
Merged
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
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' })
Loading