From 239cca8780407ce03369d6d18c167b991c0e8e9e Mon Sep 17 00:00:00 2001 From: jlenon7 Date: Wed, 15 Jan 2025 15:41:21 -0300 Subject: [PATCH] feat(new): add new app --- package-lock.json | 4 ++-- package.json | 2 +- src/console/commands/new.command.ts | 20 ++++++++++++++++++- .../e2e/console/commands/new.command.test.ts | 18 +++++++++++++++++ .../consoles/confirm-web-react-ssr.ts | 11 ++++++++++ 5 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 tests/fixtures/consoles/confirm-web-react-ssr.ts diff --git a/package-lock.json b/package-lock.json index 9576233..5c565ae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/cli", - "version": "5.4.0", + "version": "5.5.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@athenna/cli", - "version": "5.4.0", + "version": "5.5.0", "license": "MIT", "dependencies": { "@athenna/artisan": "^5.3.0", diff --git a/package.json b/package.json index d828e0d..d3254e9 100644 --- a/package.json +++ b/package.json @@ -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 ", diff --git a/src/console/commands/new.command.ts b/src/console/commands/new.command.ts index d117181..8239789 100644 --- a/src/console/commands/new.command.ts +++ b/src/console/commands/new.command.ts @@ -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) @@ -45,6 +45,9 @@ export class NewCommand extends BaseCommand { case 'WEB REACT': await this.webReact() break + case 'WEB REACT SSR': + await this.webReactSsr() + break } } @@ -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] @@ -137,6 +141,20 @@ export class NewCommand extends BaseCommand { .render() } + public async webReactSsr(): Promise { + 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 { let projectPath = `${Config.get('rc.callPath')}${sep}${this.name}` diff --git a/tests/e2e/console/commands/new.command.test.ts b/tests/e2e/console/commands/new.command.test.ts index f3bdaba..f6594fb 100644 --- a/tests/e2e/console/commands/new.command.test.ts +++ b/tests/e2e/console/commands/new.command.test.ts @@ -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', { diff --git a/tests/fixtures/consoles/confirm-web-react-ssr.ts b/tests/fixtures/consoles/confirm-web-react-ssr.ts new file mode 100644 index 0000000..4bf29c9 --- /dev/null +++ b/tests/fixtures/consoles/confirm-web-react-ssr.ts @@ -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' })