@koalarx/nest-cli 2.0.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +43 -48
- package/package.json +11 -38
- package/src/commands/new-project/index.ts +99 -0
- package/src/commands/new-project/new-project.ts +91 -0
- package/{index.ts → src/index.ts} +12 -3
- package/templates/root-files-folders/.dockerignore +7 -0
- package/{code-base/startup-project → templates/root-files-folders}/.vscode/launch.json +7 -5
- package/templates/root-files-folders/.vscode/mcp.json +11 -0
- package/{code-base/startup-project → templates/root-files-folders}/.vscode/settings.json +23 -9
- package/{code-base/startup-project → templates/root-files-folders}/Dockerfile +3 -1
- package/templates/root-files-folders/README.md +33 -0
- package/templates/root-files-folders/bunfig.toml +10 -0
- package/templates/root-files-folders/nest-cli.json +35 -0
- package/{code-base/startup-project → templates/root-files-folders}/package.json +21 -19
- package/templates/root-files-folders/tsconfig.build.json +9 -0
- package/{code-base/startup-project → templates/root-files-folders}/tsconfig.json +8 -6
- package/templates/root-files-folders/tsconfig.prisma.json +16 -0
- package/tsconfig.json +14 -0
- package/LICENSE +0 -21
- package/code-base/startup-project/.eslintignore +0 -2
- package/code-base/startup-project/.eslintrc.js +0 -22
- package/code-base/startup-project/.swcrc +0 -23
- package/code-base/startup-project/LICENSE +0 -21
- package/code-base/startup-project/README.md +0 -5
- package/code-base/startup-project/nest-cli.json +0 -19
- package/code-base/startup-project/prisma/migrations/20250326220607_init/migration.sql +0 -32
- package/code-base/startup-project/prisma/migrations/migration_lock.toml +0 -3
- package/code-base/startup-project/prisma/schema.prisma +0 -39
- package/code-base/startup-project/prisma/scripts/fix-extensions.mjs +0 -31
- package/code-base/startup-project/prisma.config.ts +0 -8
- package/code-base/startup-project/src/application/mapping/mapping.profile.ts +0 -10
- package/code-base/startup-project/src/application/mapping/person.mapping.ts +0 -39
- package/code-base/startup-project/src/application/person/common/persist-person.request.ts +0 -28
- package/code-base/startup-project/src/application/person/create/create-person.handler.spec.ts +0 -22
- package/code-base/startup-project/src/application/person/create/create-person.handler.ts +0 -39
- package/code-base/startup-project/src/application/person/create/create-person.request.ts +0 -11
- package/code-base/startup-project/src/application/person/create/create-person.response.ts +0 -3
- package/code-base/startup-project/src/application/person/create/create-person.validator.ts +0 -19
- package/code-base/startup-project/src/application/person/create-person-job/create-person-job.ts +0 -58
- package/code-base/startup-project/src/application/person/delete/delete-person.handler.spec.ts +0 -24
- package/code-base/startup-project/src/application/person/delete/delete-person.handler.ts +0 -33
- package/code-base/startup-project/src/application/person/delete-inative-job/delete-inactive-job.ts +0 -49
- package/code-base/startup-project/src/application/person/events/inactive-person/inactive-person-event.ts +0 -3
- package/code-base/startup-project/src/application/person/events/inactive-person/inactive-person-handler.ts +0 -27
- package/code-base/startup-project/src/application/person/events/person-event.job.ts +0 -11
- package/code-base/startup-project/src/application/person/read/read-person.handler.spec.ts +0 -28
- package/code-base/startup-project/src/application/person/read/read-person.handler.ts +0 -37
- package/code-base/startup-project/src/application/person/read/read-person.response.ts +0 -44
- package/code-base/startup-project/src/application/person/read-many/read-many-person.handler.spec.ts +0 -67
- package/code-base/startup-project/src/application/person/read-many/read-many-person.handler.ts +0 -47
- package/code-base/startup-project/src/application/person/read-many/read-many-person.request.ts +0 -21
- package/code-base/startup-project/src/application/person/read-many/read-many-person.response.ts +0 -16
- package/code-base/startup-project/src/application/person/read-many/read-many.validator.ts +0 -16
- package/code-base/startup-project/src/application/person/update/update-person.handler.spec.ts +0 -47
- package/code-base/startup-project/src/application/person/update/update-person.handler.ts +0 -57
- package/code-base/startup-project/src/application/person/update/update-person.request.ts +0 -36
- package/code-base/startup-project/src/application/person/update/update-person.validator.ts +0 -21
- package/code-base/startup-project/src/core/env.ts +0 -6
- package/code-base/startup-project/src/domain/dtos/read-many-person.dto.ts +0 -16
- package/code-base/startup-project/src/domain/entities/person/person-address.ts +0 -12
- package/code-base/startup-project/src/domain/entities/person/person-phone.ts +0 -12
- package/code-base/startup-project/src/domain/entities/person/person.ts +0 -24
- package/code-base/startup-project/src/domain/repositories/iperson.repository.ts +0 -10
- package/code-base/startup-project/src/domain/services/.gitkeep +0 -0
- package/code-base/startup-project/src/host/app.module.ts +0 -19
- package/code-base/startup-project/src/host/controllers/controller.module.ts +0 -16
- package/code-base/startup-project/src/host/controllers/person/create-person.controller.ts +0 -30
- package/code-base/startup-project/src/host/controllers/person/delete-person.controller.ts +0 -22
- package/code-base/startup-project/src/host/controllers/person/person.controller.e2e-spec.ts +0 -158
- package/code-base/startup-project/src/host/controllers/person/person.module.ts +0 -37
- package/code-base/startup-project/src/host/controllers/person/read-many-person.controller.ts +0 -29
- package/code-base/startup-project/src/host/controllers/person/read-person.controller.ts +0 -26
- package/code-base/startup-project/src/host/controllers/person/router.config.ts +0 -9
- package/code-base/startup-project/src/host/controllers/person/update-person.controller.ts +0 -30
- package/code-base/startup-project/src/host/main.ts +0 -38
- package/code-base/startup-project/src/infra/database/db-transaction-context.ts +0 -25
- package/code-base/startup-project/src/infra/database/repositories/person.repository.ts +0 -54
- package/code-base/startup-project/src/infra/database/repositories/repositories.module.ts +0 -15
- package/code-base/startup-project/src/infra/infra.module.ts +0 -8
- package/code-base/startup-project/src/infra/services/.gitkeep +0 -0
- package/code-base/startup-project/src/test/create-e2e-test-app.ts +0 -27
- package/code-base/startup-project/src/test/create-unit-test-app.ts +0 -24
- package/code-base/startup-project/src/test/mockup/person/create-person-request.mockup.ts +0 -9
- package/code-base/startup-project/src/test/repositories/person.repository.ts +0 -36
- package/code-base/startup-project/src/test/setup-e2e.ts +0 -12
- package/code-base/startup-project/tsconfig.build-prisma.json +0 -21
- package/code-base/startup-project/tsconfig.build.json +0 -9
- package/commands/new-project/index.ts +0 -34
- package/index.js +0 -30715
- package/utils/copy-folder.ts +0 -25
- /package/{code-base → templates}/env/config.txt +0 -0
- /package/{code-base → templates}/gitignore/config.txt +0 -0
- /package/{code-base/startup-project → templates/root-files-folders}/.gitattributes +0 -0
- /package/{code-base/startup-project → templates/root-files-folders}/.vscode/tasks.json +0 -0
package/CHANGELOG.md
ADDED
package/README.md
CHANGED
|
@@ -1,76 +1,71 @@
|
|
|
1
1
|
# @koalarx/nest-cli
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## 📋 Sobre
|
|
6
|
-
|
|
7
|
-
`@koalarx/nest-cli` é a forma recomendada para inicializar novos projetos que utilizam a biblioteca [@koalarx/nest](https://github.com/igordrangel/koala-nest). Cria automaticamente a estrutura de diretórios, configurações de ambiente e setup inicial.
|
|
3
|
+
CLI oficial para criar projetos utilizando **Koala Nest** - uma abstração robusta do NestJS seguindo princípios de Domain-Driven Design (DDD).
|
|
8
4
|
|
|
9
5
|
## 📦 Instalação
|
|
10
6
|
|
|
11
7
|
```bash
|
|
8
|
+
npm install -g @koalarx/nest-cli
|
|
9
|
+
# ou
|
|
12
10
|
bun add -g @koalarx/nest-cli
|
|
13
11
|
```
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
- Bun 1.0.0+ ([Instale o Bun](https://bun.sh))
|
|
13
|
+
## 🚀 Uso
|
|
17
14
|
|
|
18
|
-
|
|
15
|
+
### Criar Novo Projeto
|
|
19
16
|
|
|
20
17
|
```bash
|
|
21
|
-
# Criar novo projeto
|
|
22
18
|
koala-nest new meu-projeto
|
|
23
|
-
|
|
24
|
-
# Entrar no diretório
|
|
25
|
-
cd meu-projeto
|
|
26
|
-
|
|
27
|
-
# Iniciar desenvolvimento (as dependências são instaladas automaticamente com bun)
|
|
28
|
-
bun start:dev
|
|
29
19
|
```
|
|
30
20
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
## Comandos Disponíveis
|
|
34
|
-
|
|
35
|
-
### `prisma:generate`
|
|
36
|
-
|
|
37
|
-
Comando especializado que substitui o comando nativo do Prisma para compatibilidade com a biblioteca `@koalarx/nest`.
|
|
21
|
+
Ou de forma interativa:
|
|
38
22
|
|
|
39
23
|
```bash
|
|
40
|
-
|
|
24
|
+
koala-nest new
|
|
41
25
|
```
|
|
42
26
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
27
|
+
Isso criará um novo projeto com:
|
|
28
|
+
- ✅ Estrutura DDD completa (Domain, Application, Host, Infra)
|
|
29
|
+
- ✅ Configuração do Prisma
|
|
30
|
+
- ✅ Exemplo de CRUD com Person
|
|
31
|
+
- ✅ Testes unitários e E2E configurados
|
|
32
|
+
- ✅ Bun configurado
|
|
33
|
+
- ✅ Dockerfile
|
|
34
|
+
- ✅ ESLint e Prettier
|
|
35
|
+
- ✅ AutoMapping
|
|
36
|
+
- ✅ Validação com Zod
|
|
37
|
+
- ✅ Swagger/Scalar
|
|
46
38
|
|
|
47
|
-
|
|
39
|
+
## 📁 Estrutura Gerada
|
|
48
40
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
41
|
+
```
|
|
42
|
+
meu-projeto/
|
|
43
|
+
├── src/
|
|
44
|
+
│ ├── application/ # Handlers, Validators, Mapping
|
|
45
|
+
│ ├── core/ # Configurações e variáveis globais
|
|
46
|
+
│ ├── domain/ # Entities, DTOs, Repositories
|
|
47
|
+
│ ├── host/ # Controllers e Modules
|
|
48
|
+
│ ├── infra/ # Database e implementações
|
|
49
|
+
│ └── test/ # Configurações de teste
|
|
50
|
+
├── prisma/
|
|
51
|
+
│ ├── schema.prisma
|
|
52
|
+
│ └── migrations/
|
|
53
|
+
├── .env
|
|
54
|
+
├── Dockerfile
|
|
55
|
+
├── package.json
|
|
56
|
+
└── tsconfig.json
|
|
57
|
+
```
|
|
64
58
|
|
|
65
|
-
|
|
59
|
+
## 🔗 Links Úteis
|
|
66
60
|
|
|
67
|
-
|
|
61
|
+
- [Documentação Koala Nest](https://github.com/igordrangel/koala-nest)
|
|
62
|
+
- [Exemplo Completo](https://github.com/igordrangel/koala-nest/blob/main/docs/EXAMPLE.md)
|
|
63
|
+
- [NPM Package](https://www.npmjs.com/package/@koalarx/nest)
|
|
68
64
|
|
|
69
|
-
|
|
65
|
+
## 🤝 Contribuindo
|
|
70
66
|
|
|
71
|
-
-
|
|
72
|
-
- **[Exemplo de Projeto](./code-base/startup-project)** — Estrutura padrão gerada pela CLI
|
|
67
|
+
Contribuições são bem-vindas! Veja o [repositório principal](https://github.com/igordrangel/koala-nest) para mais informações.
|
|
73
68
|
|
|
74
69
|
## 📄 Licença
|
|
75
70
|
|
|
76
|
-
|
|
71
|
+
ISC © Igor D. Rangel
|
package/package.json
CHANGED
|
@@ -1,21 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koalarx/nest-cli",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"scripts": {
|
|
6
|
-
"test": "vitest run",
|
|
7
|
-
"test:watch": "vitest",
|
|
8
|
-
"test:cov": "vitest run --coverage",
|
|
9
|
-
"test:debug": "vitest --inspect-brk --inspect --logHeapUsage --threads=false",
|
|
10
|
-
"build": "bun .github/scripts/publish.ts",
|
|
11
|
-
"prepare": "bun run build",
|
|
12
|
-
"prepublishOnly": "bun run test",
|
|
13
|
-
"version": "git add -A src",
|
|
14
|
-
"postversion": "git push && git push --tags",
|
|
15
|
-
"deploy:hotfix": "npm version patch",
|
|
16
|
-
"deploy:feature": "npm version minor",
|
|
17
|
-
"deploy:release": "npm version major"
|
|
18
|
-
},
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "CLI para criação de projetos utilizando Koala Nest",
|
|
19
5
|
"main": "index.js",
|
|
20
6
|
"bin": {
|
|
21
7
|
"koala-nest": "index.js"
|
|
@@ -23,33 +9,20 @@
|
|
|
23
9
|
"type": "module",
|
|
24
10
|
"repository": {
|
|
25
11
|
"type": "git",
|
|
26
|
-
"url": "git+https://github.com/igordrangel/koala-nest
|
|
12
|
+
"url": "git+https://github.com/igordrangel/koala-nest.git",
|
|
13
|
+
"directory": "apps/koala-nest-cli"
|
|
27
14
|
},
|
|
28
15
|
"keywords": [
|
|
29
|
-
"Nest.js"
|
|
16
|
+
"Nest.js",
|
|
17
|
+
"CLI",
|
|
18
|
+
"DDD",
|
|
19
|
+
"Koala Nest",
|
|
20
|
+
"NestJS CLI"
|
|
30
21
|
],
|
|
31
22
|
"author": "Igor D. Rangel",
|
|
32
23
|
"license": "ISC",
|
|
33
24
|
"bugs": {
|
|
34
|
-
"url": "https://github.com/igordrangel/koala-nest
|
|
35
|
-
},
|
|
36
|
-
"homepage": "https://github.com/igordrangel/koala-nest-cli#readme",
|
|
37
|
-
"dependencies": {
|
|
38
|
-
"chalk": "^2.4.2",
|
|
39
|
-
"commander": "^2.19.0",
|
|
40
|
-
"inquirer": "^6.2.2",
|
|
41
|
-
"shelljs": "^0.8.3"
|
|
25
|
+
"url": "https://github.com/igordrangel/koala-nest/issues"
|
|
42
26
|
},
|
|
43
|
-
"
|
|
44
|
-
"@rocketseat/eslint-config": "^1.2.0",
|
|
45
|
-
"@types/node": "^18.14.0",
|
|
46
|
-
"@types/node-fetch": "^2.6.4",
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
48
|
-
"@typescript-eslint/parser": "^5.0.0",
|
|
49
|
-
"eslint": "^8.44.0",
|
|
50
|
-
"eslint-config-prettier": "^8.8.0",
|
|
51
|
-
"eslint-plugin-prettier": "^4.2.1",
|
|
52
|
-
"prettier": "^2.3.2",
|
|
53
|
-
"typescript": "^5.2.2"
|
|
54
|
-
}
|
|
27
|
+
"homepage": "https://github.com/igordrangel/koala-nest/tree/main/apps/koala-nest-cli#readme"
|
|
55
28
|
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
import { execSync } from 'node:child_process'
|
|
3
|
+
import { cpSync, readFileSync, writeFileSync } from 'node:fs'
|
|
4
|
+
import { dirname, join } from 'node:path'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
6
|
+
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
8
|
+
const __dirname = dirname(__filename)
|
|
9
|
+
|
|
10
|
+
// Caminho para o template base (startup-project gerado de apps/example)
|
|
11
|
+
// De: src/commands/new-project/index.ts
|
|
12
|
+
// Para: dist-cli/templates/startup-project
|
|
13
|
+
// Relativo: ../../templates/startup-project
|
|
14
|
+
const TEMPLATE_BASE = join(__dirname, '../../templates/startup-project')
|
|
15
|
+
// De: src/commands/new-project/index.ts
|
|
16
|
+
// Para: dist-cli/templates
|
|
17
|
+
// Relativo: ../../templates
|
|
18
|
+
const TEMPLATES_DIR = join(__dirname, '../../templates')
|
|
19
|
+
|
|
20
|
+
export async function newProject(projectName: string) {
|
|
21
|
+
const targetDir = join(process.cwd(), projectName)
|
|
22
|
+
|
|
23
|
+
console.log(chalk.blue('🚀 Criando projeto Koala Nest...'))
|
|
24
|
+
console.log(chalk.gray(`📁 Destino: ${targetDir}\n`))
|
|
25
|
+
|
|
26
|
+
// 1. Copiar estrutura base do example
|
|
27
|
+
console.log(chalk.yellow('📋 Copiando estrutura base...'))
|
|
28
|
+
cpSync(TEMPLATE_BASE, targetDir, {
|
|
29
|
+
recursive: true,
|
|
30
|
+
filter: (src) => {
|
|
31
|
+
// Ignorar node_modules, dist (mas não dist-cli), e .git
|
|
32
|
+
const isBlacklisted =
|
|
33
|
+
src.includes('node_modules') ||
|
|
34
|
+
(src.includes('dist') && !src.includes('dist-cli')) ||
|
|
35
|
+
src.includes('.git')
|
|
36
|
+
return !isBlacklisted
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
// 2. Adicionar arquivos extras dos templates
|
|
41
|
+
console.log(chalk.yellow('📦 Adicionando configurações extras...'))
|
|
42
|
+
|
|
43
|
+
// Copiar Dockerfile
|
|
44
|
+
const dockerfilePath = join(TEMPLATES_DIR, 'startup-project', 'Dockerfile')
|
|
45
|
+
try {
|
|
46
|
+
cpSync(dockerfilePath, join(targetDir, 'Dockerfile'))
|
|
47
|
+
} catch {
|
|
48
|
+
console.log(chalk.red('⚠️ Dockerfile não encontrado nos templates, pulando...'))
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 3. Atualizar package.json
|
|
52
|
+
console.log(chalk.yellow('⚙️ Configurando package.json...'))
|
|
53
|
+
const packageJsonPath = join(targetDir, 'package.json')
|
|
54
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'))
|
|
55
|
+
packageJson.name = projectName
|
|
56
|
+
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
|
|
57
|
+
|
|
58
|
+
// 4. Atualizar README.md
|
|
59
|
+
console.log(chalk.yellow('📄 Atualizando README...'))
|
|
60
|
+
const readmePath = join(targetDir, 'README.md')
|
|
61
|
+
let readme = readFileSync(readmePath, 'utf-8')
|
|
62
|
+
readme = readme.replace(/\[projectName\]/g, projectName)
|
|
63
|
+
writeFileSync(readmePath, readme)
|
|
64
|
+
|
|
65
|
+
// 5. Criar .env
|
|
66
|
+
console.log(chalk.yellow('🔐 Criando arquivo .env...'))
|
|
67
|
+
const envTemplate = readFileSync(join(TEMPLATES_DIR, 'env', 'config.txt'), 'utf-8')
|
|
68
|
+
const envContent = envTemplate.replace(/\[projectName\]/g, projectName.replace(/-/g, '_'))
|
|
69
|
+
writeFileSync(join(targetDir, '.env'), envContent)
|
|
70
|
+
|
|
71
|
+
// 6. Criar .gitignore
|
|
72
|
+
console.log(chalk.yellow('🚫 Criando .gitignore...'))
|
|
73
|
+
const gitIgnoreContent = readFileSync(join(TEMPLATES_DIR, 'gitignore', 'config.txt'), 'utf-8')
|
|
74
|
+
writeFileSync(join(targetDir, '.gitignore'), gitIgnoreContent)
|
|
75
|
+
|
|
76
|
+
// 7. Instalar dependências e gerar Prisma
|
|
77
|
+
console.log(chalk.yellow('\n📥 Instalando dependências...'))
|
|
78
|
+
try {
|
|
79
|
+
execSync(`cd ${projectName} && bun install`, {
|
|
80
|
+
stdio: 'inherit',
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
console.log(chalk.yellow('🔨 Gerando Prisma Client...'))
|
|
84
|
+
execSync(`cd ${projectName} && bun run prisma:generate`, {
|
|
85
|
+
stdio: 'inherit',
|
|
86
|
+
})
|
|
87
|
+
} catch {
|
|
88
|
+
console.log(chalk.red('⚠️ Erro ao instalar dependências. Execute manualmente:'))
|
|
89
|
+
console.log(chalk.gray(` cd ${projectName}`))
|
|
90
|
+
console.log(chalk.gray(` bun install`))
|
|
91
|
+
console.log(chalk.gray(` bun run prisma:generate`))
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
console.log(chalk.green('\n✅ Projeto criado com sucesso!'))
|
|
95
|
+
console.log(chalk.cyan('\n📚 Próximos passos:'))
|
|
96
|
+
console.log(chalk.gray(` cd ${projectName}`))
|
|
97
|
+
console.log(chalk.gray(` bun run start:dev`))
|
|
98
|
+
console.log(chalk.gray(`\n📖 Documentação: https://github.com/igordrangel/koala-nest\n`))
|
|
99
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
import { execSync } from 'node:child_process'
|
|
3
|
+
import { cpSync, readFileSync, writeFileSync } from 'node:fs'
|
|
4
|
+
import { dirname, join } from 'node:path'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
6
|
+
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
8
|
+
const __dirname = dirname(__filename)
|
|
9
|
+
|
|
10
|
+
// Caminho para a pasta example no monorepo (será o template base)
|
|
11
|
+
const TEMPLATE_BASE = join(__dirname, '../../../example')
|
|
12
|
+
const TEMPLATES_DIR = join(__dirname, '../../templates')
|
|
13
|
+
|
|
14
|
+
export async function newProject(projectName: string) {
|
|
15
|
+
const targetDir = join(process.cwd(), projectName)
|
|
16
|
+
|
|
17
|
+
console.log(chalk.blue('🚀 Criando projeto Koala Nest...'))
|
|
18
|
+
console.log(chalk.gray(`📁 Destino: ${targetDir}\n`))
|
|
19
|
+
|
|
20
|
+
// 1. Copiar estrutura base do example
|
|
21
|
+
console.log(chalk.yellow('📋 Copiando estrutura base...'))
|
|
22
|
+
cpSync(TEMPLATE_BASE, targetDir, {
|
|
23
|
+
recursive: true,
|
|
24
|
+
filter: (src) => {
|
|
25
|
+
// Ignorar node_modules e arquivos de build
|
|
26
|
+
return !src.includes('node_modules') &&
|
|
27
|
+
!src.includes('dist') &&
|
|
28
|
+
!src.includes('.git')
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
// 2. Adicionar arquivos extras dos templates
|
|
33
|
+
console.log(chalk.yellow('📦 Adicionando configurações extras...'))
|
|
34
|
+
|
|
35
|
+
// Copiar Dockerfile
|
|
36
|
+
const dockerfilePath = join(TEMPLATES_DIR, 'startup-project', 'Dockerfile')
|
|
37
|
+
try {
|
|
38
|
+
cpSync(dockerfilePath, join(targetDir, 'Dockerfile'))
|
|
39
|
+
} catch {
|
|
40
|
+
console.log(chalk.red('⚠️ Dockerfile não encontrado nos templates, pulando...'))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 3. Atualizar package.json
|
|
44
|
+
console.log(chalk.yellow('⚙️ Configurando package.json...'))
|
|
45
|
+
const packageJsonPath = join(targetDir, 'package.json')
|
|
46
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'))
|
|
47
|
+
packageJson.name = projectName
|
|
48
|
+
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
|
|
49
|
+
|
|
50
|
+
// 4. Atualizar README.md
|
|
51
|
+
console.log(chalk.yellow('📄 Atualizando README...'))
|
|
52
|
+
const readmePath = join(targetDir, 'README.md')
|
|
53
|
+
let readme = readFileSync(readmePath, 'utf-8')
|
|
54
|
+
readme = readme.replace(/\[projectName\]/g, projectName)
|
|
55
|
+
writeFileSync(readmePath, readme)
|
|
56
|
+
|
|
57
|
+
// 5. Criar .env
|
|
58
|
+
console.log(chalk.yellow('🔐 Criando arquivo .env...'))
|
|
59
|
+
const envTemplate = readFileSync(join(TEMPLATES_DIR, 'env', 'config.txt'), 'utf-8')
|
|
60
|
+
const envContent = envTemplate.replace(/\[projectName\]/g, projectName.replace(/-/g, '_'))
|
|
61
|
+
writeFileSync(join(targetDir, '.env'), envContent)
|
|
62
|
+
|
|
63
|
+
// 6. Criar .gitignore
|
|
64
|
+
console.log(chalk.yellow('🚫 Criando .gitignore...'))
|
|
65
|
+
const gitIgnoreContent = readFileSync(join(TEMPLATES_DIR, 'gitignore', 'config.txt'), 'utf-8')
|
|
66
|
+
writeFileSync(join(targetDir, '.gitignore'), gitIgnoreContent)
|
|
67
|
+
|
|
68
|
+
// 7. Instalar dependências e gerar Prisma
|
|
69
|
+
console.log(chalk.yellow('\n📥 Instalando dependências...'))
|
|
70
|
+
try {
|
|
71
|
+
execSync(`cd ${projectName} && bun install`, {
|
|
72
|
+
stdio: 'inherit',
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
console.log(chalk.yellow('🔨 Gerando Prisma Client...'))
|
|
76
|
+
execSync(`cd ${projectName} && bun build:prisma`, {
|
|
77
|
+
stdio: 'inherit',
|
|
78
|
+
})
|
|
79
|
+
} catch {
|
|
80
|
+
console.log(chalk.red('⚠️ Erro ao instalar dependências. Execute manualmente:'))
|
|
81
|
+
console.log(chalk.gray(` cd ${projectName}`))
|
|
82
|
+
console.log(chalk.gray(` bun install`))
|
|
83
|
+
console.log(chalk.gray(` bun build:prisma`))
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
console.log(chalk.green('\n✅ Projeto criado com sucesso!'))
|
|
87
|
+
console.log(chalk.cyan('\n📚 Próximos passos:'))
|
|
88
|
+
console.log(chalk.gray(` cd ${projectName}`))
|
|
89
|
+
console.log(chalk.gray(` bun run start:dev`))
|
|
90
|
+
console.log(chalk.gray(`\n📖 Documentação: https://github.com/igordrangel/koala-nest\n`))
|
|
91
|
+
}
|
|
@@ -2,9 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
import program from 'commander'
|
|
4
4
|
import inquirer from 'inquirer'
|
|
5
|
-
import { newProject } from './commands/new-project'
|
|
5
|
+
import { newProject } from './commands/new-project/index.js'
|
|
6
6
|
import chalk from 'chalk'
|
|
7
|
-
import
|
|
7
|
+
import { readFileSync } from 'fs'
|
|
8
|
+
import { join, dirname } from 'path'
|
|
9
|
+
import { fileURLToPath } from 'url'
|
|
10
|
+
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
12
|
+
const __dirname = dirname(__filename)
|
|
13
|
+
|
|
14
|
+
const packageJson = JSON.parse(
|
|
15
|
+
readFileSync(join(__dirname, '../package.json'), 'utf-8')
|
|
16
|
+
)
|
|
8
17
|
|
|
9
18
|
const banner = `
|
|
10
19
|
_ __ _ _ _ _ ____ _ ___
|
|
@@ -36,7 +45,7 @@ program
|
|
|
36
45
|
.then((answers) => answers.projectName)
|
|
37
46
|
}
|
|
38
47
|
|
|
39
|
-
newProject(projectName)
|
|
48
|
+
await newProject(projectName)
|
|
40
49
|
})
|
|
41
50
|
|
|
42
51
|
program.parse(process.argv)
|
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
"type": "node",
|
|
6
6
|
"request": "launch",
|
|
7
7
|
"name": "Nest Debug (Bun)",
|
|
8
|
-
"runtimeExecutable": "
|
|
8
|
+
"runtimeExecutable": "npm",
|
|
9
9
|
"runtimeArgs": [
|
|
10
10
|
"run",
|
|
11
|
-
"start:debug"
|
|
11
|
+
"start:debug",
|
|
12
|
+
"--",
|
|
13
|
+
"--inspect-brk"
|
|
12
14
|
],
|
|
13
15
|
"console": "integratedTerminal",
|
|
14
16
|
"restart": true,
|
|
@@ -18,9 +20,9 @@
|
|
|
18
20
|
"type": "bun",
|
|
19
21
|
"request": "launch",
|
|
20
22
|
"name": "Debug Bun File",
|
|
21
|
-
"program": "${file}",
|
|
23
|
+
"program": "${file}",
|
|
22
24
|
"cwd": "${workspaceFolder}",
|
|
23
|
-
"stopOnEntry": false
|
|
24
|
-
}
|
|
25
|
+
"stopOnEntry": false
|
|
26
|
+
}
|
|
25
27
|
]
|
|
26
28
|
}
|
|
@@ -9,7 +9,10 @@
|
|
|
9
9
|
"workbench.startupEditor": "newUntitledFile",
|
|
10
10
|
"javascript.suggest.autoImports": true,
|
|
11
11
|
"javascript.updateImportsOnFileMove.enabled": "always",
|
|
12
|
-
"editor.rulers": [
|
|
12
|
+
"editor.rulers": [
|
|
13
|
+
80,
|
|
14
|
+
120
|
|
15
|
+
],
|
|
13
16
|
"extensions.ignoreRecommendations": true,
|
|
14
17
|
"typescript.tsserver.log": "off",
|
|
15
18
|
"files.associations": {
|
|
@@ -60,9 +63,11 @@
|
|
|
60
63
|
"vitest.config.e2e.ts": "vitest",
|
|
61
64
|
"*.e2e-spec.ts": "test-js",
|
|
62
65
|
"*.dto.ts": "diff",
|
|
66
|
+
"*.handler.ts": "esbuild",
|
|
63
67
|
"*.request.ts": "log",
|
|
64
68
|
"*.schema.ts": "scheme",
|
|
65
|
-
"*.response.ts": "
|
|
69
|
+
"*.response.ts": "conduct",
|
|
70
|
+
"*.validator.ts": "commitlint"
|
|
66
71
|
},
|
|
67
72
|
"material-icon-theme.folders.associations": {
|
|
68
73
|
"adapters": "contract",
|
|
@@ -98,15 +103,24 @@
|
|
|
98
103
|
"filters": "pipe"
|
|
99
104
|
},
|
|
100
105
|
"[javascript]": {
|
|
101
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
106
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
107
|
+
"editor.formatOnSave": true,
|
|
108
|
+
"editor.codeActionsOnSave": {
|
|
109
|
+
"source.fixAll.eslint": "explicit"
|
|
110
|
+
}
|
|
102
111
|
},
|
|
103
112
|
"[typescript]": {
|
|
104
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
113
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
114
|
+
"editor.formatOnSave": true,
|
|
115
|
+
"editor.codeActionsOnSave": {
|
|
116
|
+
"source.fixAll.eslint": "explicit"
|
|
117
|
+
}
|
|
109
118
|
},
|
|
119
|
+
"prettier.documentSelectors": [
|
|
120
|
+
"**/*.ts",
|
|
121
|
+
"**/*.tsx",
|
|
122
|
+
"**/*.js"
|
|
123
|
+
],
|
|
110
124
|
"terminal.integrated.defaultProfile.windows": "Command Prompt",
|
|
111
125
|
"git.confirmSync": false,
|
|
112
126
|
"files.eol": "\n",
|
|
@@ -114,5 +128,5 @@
|
|
|
114
128
|
"npm.scriptExplorerAction": "run",
|
|
115
129
|
"npm.packageManager": "npm",
|
|
116
130
|
"editor.wordWrap": "on",
|
|
117
|
-
"editor.wrappingIndent": "indent"
|
|
131
|
+
"editor.wrappingIndent": "indent"
|
|
118
132
|
}
|
|
@@ -18,7 +18,7 @@ COPY . .
|
|
|
18
18
|
ENV DATABASE_URL=" "
|
|
19
19
|
|
|
20
20
|
# Compilando o app
|
|
21
|
-
RUN bun
|
|
21
|
+
RUN bun build:prisma && bun build
|
|
22
22
|
|
|
23
23
|
# ====== STAGE 2: RUNTIME ======
|
|
24
24
|
FROM oven/bun:${BUN_VERSION}
|
|
@@ -33,9 +33,11 @@ WORKDIR /home/bun/app
|
|
|
33
33
|
|
|
34
34
|
# Copiando apenas os arquivos necessários do builder
|
|
35
35
|
COPY --from=builder --chown=bun:bun --chmod=555 /home/bun/app/node_modules ./node_modules
|
|
36
|
+
COPY --from=builder --chown=bun:bun --chmod=555 /home/bun/app/templates ./templates
|
|
36
37
|
COPY --from=builder --chown=bun:bun --chmod=555 /home/bun/app/prisma ./prisma
|
|
37
38
|
COPY --from=builder --chown=bun:bun --chmod=555 /home/bun/app/dist ./dist
|
|
38
39
|
COPY --from=builder --chown=bun:bun --chmod=555 /home/bun/app/package.json ./package.json
|
|
40
|
+
COPY --from=builder --chown=bun:bun --chmod=555 /home/bun/app/prisma.config.ts ./prisma.config.ts
|
|
39
41
|
|
|
40
42
|
# Alterando o usuário para "bun" por segurança
|
|
41
43
|
USER bun
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# [projectName]
|
|
2
|
+
|
|
3
|
+
Projeto criado com [Koala Nest](https://github.com/igordrangel/koala-nest)
|
|
4
|
+
|
|
5
|
+
## 🚀 Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Instalar dependências
|
|
9
|
+
bun install
|
|
10
|
+
|
|
11
|
+
# Configurar banco de dados
|
|
12
|
+
cp .env.example .env
|
|
13
|
+
bun prisma:migrate
|
|
14
|
+
|
|
15
|
+
# Iniciar em desenvolvimento
|
|
16
|
+
bun start:dev
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 📚 Documentação
|
|
20
|
+
|
|
21
|
+
- [Koala Nest Docs](https://github.com/igordrangel/koala-nest#readme)
|
|
22
|
+
- [NestJS Documentation](https://docs.nestjs.com)
|
|
23
|
+
- [Prisma Documentation](https://www.prisma.io/docs)
|
|
24
|
+
|
|
25
|
+
## 🏗️ Estrutura
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
src/
|
|
29
|
+
├── domain/ # Regras de negócio
|
|
30
|
+
├── application/ # Casos de uso
|
|
31
|
+
├── infra/ # Implementação técnica
|
|
32
|
+
└── host/ # Configuração (Controllers, Módulos)
|
|
33
|
+
```
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/nest-cli",
|
|
3
|
+
"collection": "@nestjs/schematics",
|
|
4
|
+
"monorepo": true,
|
|
5
|
+
"projects": {
|
|
6
|
+
"prisma": {
|
|
7
|
+
"type": "library",
|
|
8
|
+
"root": "prisma/generated",
|
|
9
|
+
"entryFile": "client",
|
|
10
|
+
"sourceRoot": "./",
|
|
11
|
+
"compilerOptions": {
|
|
12
|
+
"tsConfigPath": "tsconfig.prisma.json"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"app": {
|
|
16
|
+
"type": "application",
|
|
17
|
+
"root": "src",
|
|
18
|
+
"entryFile": "../dist/host/main",
|
|
19
|
+
"sourceRoot": "src",
|
|
20
|
+
"compilerOptions": {
|
|
21
|
+
"deleteOutDir": true,
|
|
22
|
+
"tsConfigPath": "tsconfig.build.json",
|
|
23
|
+
"plugins": [
|
|
24
|
+
{
|
|
25
|
+
"name": "@nestjs/swagger",
|
|
26
|
+
"options": {
|
|
27
|
+
"classValidatorShim": false,
|
|
28
|
+
"introspectComments": true
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|