@matizze/prumo-cli 0.0.0-stage → 0.5.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/README.md +120 -2
- package/dist/api.d.ts +10 -0
- package/dist/api.js +9 -0
- package/dist/args.d.ts +11 -0
- package/dist/args.js +61 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +11 -0
- package/dist/codemod/add-route.d.ts +66 -0
- package/dist/codemod/add-route.js +435 -0
- package/dist/codemod/edit.d.ts +35 -0
- package/dist/codemod/edit.js +51 -0
- package/dist/codemod/index.d.ts +8 -0
- package/dist/codemod/index.js +8 -0
- package/dist/codemod/merge-barrel.d.ts +9 -0
- package/dist/codemod/merge-barrel.js +49 -0
- package/dist/codemod/messages.d.ts +11 -0
- package/dist/codemod/messages.js +46 -0
- package/dist/codemod/names.d.ts +62 -0
- package/dist/codemod/names.js +204 -0
- package/dist/codemod/plan.d.ts +45 -0
- package/dist/codemod/plan.js +147 -0
- package/dist/codemod/register-domain.d.ts +51 -0
- package/dist/codemod/register-domain.js +237 -0
- package/dist/codemod/register-messages.d.ts +11 -0
- package/dist/codemod/register-messages.js +112 -0
- package/dist/codemod/route-elements.d.ts +25 -0
- package/dist/codemod/route-elements.js +72 -0
- package/dist/commands/check.d.ts +16 -0
- package/dist/commands/check.js +47 -0
- package/dist/commands/doctor.d.ts +20 -0
- package/dist/commands/doctor.js +104 -0
- package/dist/commands/make-component.d.ts +33 -0
- package/dist/commands/make-component.js +85 -0
- package/dist/commands/make-domain.d.ts +30 -0
- package/dist/commands/make-domain.js +83 -0
- package/dist/commands/make-page.d.ts +30 -0
- package/dist/commands/make-page.js +73 -0
- package/dist/commands/new.d.ts +33 -0
- package/dist/commands/new.js +179 -0
- package/dist/commands/shared.d.ts +43 -0
- package/dist/commands/shared.js +83 -0
- package/dist/describe.d.ts +63 -0
- package/dist/describe.js +134 -0
- package/dist/doctor/checks.d.ts +35 -0
- package/dist/doctor/checks.js +283 -0
- package/dist/doctor/ranges.d.ts +16 -0
- package/dist/doctor/ranges.js +27 -0
- package/dist/doctor/versions.d.ts +33 -0
- package/dist/doctor/versions.js +44 -0
- package/dist/errors.d.ts +12 -0
- package/dist/errors.js +19 -0
- package/dist/generate/app.d.ts +27 -0
- package/dist/generate/app.js +136 -0
- package/dist/generate/component.d.ts +36 -0
- package/dist/generate/component.js +48 -0
- package/dist/generate/domain.d.ts +31 -0
- package/dist/generate/domain.js +63 -0
- package/dist/generate/page.d.ts +45 -0
- package/dist/generate/page.js +100 -0
- package/dist/help.d.ts +19 -0
- package/dist/help.js +97 -0
- package/dist/in-process.d.ts +26 -0
- package/dist/in-process.js +23 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/new/name.d.ts +7 -0
- package/dist/new/name.js +24 -0
- package/dist/new/packages.d.ts +6 -0
- package/dist/new/packages.js +40 -0
- package/dist/new/versions.d.ts +7 -0
- package/dist/new/versions.js +13 -0
- package/dist/process.d.ts +22 -0
- package/dist/process.js +45 -0
- package/dist/project.d.ts +22 -0
- package/dist/project.js +42 -0
- package/dist/root.d.ts +3 -0
- package/dist/root.js +24 -0
- package/dist/run.d.ts +13 -0
- package/dist/run.js +72 -0
- package/dist/runtime.d.ts +19 -0
- package/dist/runtime.js +1 -0
- package/dist/templates.d.ts +26 -0
- package/dist/templates.js +46 -0
- package/package.json +45 -3
- package/templates/app/AGENTS.md.tpl +50 -0
- package/templates/app/README.md.tpl +15 -0
- package/templates/app/eslint.config.js.tpl +19 -0
- package/templates/app/gitignore.tpl +22 -0
- package/templates/app/index.html.tpl +12 -0
- package/templates/app/mcp.json.tpl +8 -0
- package/templates/app/src/App.tsx.tpl +8 -0
- package/templates/app/src/i18n.ts.tpl +12 -0
- package/templates/app/src/main.tsx.tpl +12 -0
- package/templates/app/src/messages/index.ts.tpl +1 -0
- package/templates/app/src/providers/app.tsx.tpl +23 -0
- package/templates/app/src/providers/repository/index.ts.tpl +5 -0
- package/templates/app/src/queries-index.ts.tpl +1 -0
- package/templates/app/src/repositories/index.ts.tpl +18 -0
- package/templates/app/src/repositories/options.ts.tpl +8 -0
- package/templates/app/src/schemas-index.ts.tpl +1 -0
- package/templates/app/src/test/render.tsx.tpl +31 -0
- package/templates/app/src/test/setup.ts.tpl +4 -0
- package/templates/app/typescript.json.tpl +24 -0
- package/templates/app/vite.config.ts.tpl +16 -0
- package/templates/component/component-test.tsx.tpl +9 -0
- package/templates/component/component.tsx.tpl +11 -0
- package/templates/domain/queries.ts.tpl +62 -0
- package/templates/domain/repository-contract-test.ts.tpl +75 -0
- package/templates/domain/repository-contract.ts.tpl +13 -0
- package/templates/domain/repository-fixtures.ts.tpl +8 -0
- package/templates/domain/repository-index.ts.tpl +12 -0
- package/templates/domain/repository-mock.ts.tpl +69 -0
- package/templates/domain/schema.ts.tpl +23 -0
- package/templates/page/index-domain-test.tsx.tpl +11 -0
- package/templates/page/index-test.tsx.tpl +10 -0
- package/templates/page/index.tsx.tpl +7 -0
- package/templates/page/messages-domain.en.json.tpl +5 -0
- package/templates/page/messages-domain.pt-BR.json.tpl +5 -0
- package/templates/page/messages.en.json.tpl +3 -0
- package/templates/page/messages.pt-BR.json.tpl +3 -0
- package/templates/page/model-domain.ts.tpl +17 -0
- package/templates/page/model.ts.tpl +8 -0
- package/templates/page/view-domain.tsx.tpl +20 -0
- package/templates/page/view.tsx.tpl +9 -0
package/package.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matizze/prumo-cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "O comando prumo: make:domain, check e doctor, e a API para rodar comandos em processo.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/matizze/prumo.git",
|
|
8
|
+
"directory": "packages/cli"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"bin": {
|
|
12
|
+
"prumo": "./dist/bin.js"
|
|
13
|
+
},
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./api": {
|
|
20
|
+
"types": "./dist/api.d.ts",
|
|
21
|
+
"default": "./dist/api.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"templates"
|
|
27
|
+
],
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"registry": "https://registry.npmjs.org",
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"citty": "^0.2.2",
|
|
34
|
+
"ts-morph": "^28.0.0",
|
|
35
|
+
"@matizze/prumo-rules": "0.2.1"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "^24.19.2",
|
|
39
|
+
"typescript": "~6.0.3",
|
|
40
|
+
"vitest": "^5.1.0"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json && node ../../scripts/rewrite-dts-imports.mjs dist",
|
|
44
|
+
"typecheck": "tsc",
|
|
45
|
+
"test": "vitest run"
|
|
46
|
+
},
|
|
47
|
+
"types": "./dist/index.d.ts"
|
|
6
48
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
Guia para agentes de IA neste projeto, o {{app.title}}. Ele foi criado pelo Prumo (`prumo new`), a ferramenta da Matizze que gera a estrutura de um app React e confere a arquitetura. O projeto não traz CSS nem design system: a interface é sua, e as `view` geradas usam só elementos HTML.
|
|
4
|
+
|
|
5
|
+
## Camadas
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
src/
|
|
9
|
+
pages/<tela>/
|
|
10
|
+
index.tsx liga a rota ao model e à view
|
|
11
|
+
model.ts dados (queries), textos e ações da tela; sem JSX
|
|
12
|
+
view.tsx apresentação; recebe tudo por props
|
|
13
|
+
components/ componentes usados só por esta tela
|
|
14
|
+
components/shared/ componentes usados por duas ou mais telas
|
|
15
|
+
schemas/entities/ schemas zod das entidades
|
|
16
|
+
repositories/<domínio>/ contrato, implementação mock e fixtures
|
|
17
|
+
queries/<domínio>.ts hooks de query e mutation (TanStack Query)
|
|
18
|
+
messages/<idioma>/ textos em pt-BR e en, um JSON por tela
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
- Uma tela não importa de outra tela: o que as duas usam vai para `src/components/shared`.
|
|
22
|
+
- A `view` não busca dado nem tem estado de dados: tudo chega do `model` por props.
|
|
23
|
+
- Dado vem de um hook de `src/queries`, que usa o repositório do container (`useRepositories()`), nunca um `fetch` solto.
|
|
24
|
+
- Todo texto da tela mora em `src/messages/<idioma>/<tela>.json`, nos dois idiomas, e é lido por `useTranslations`.
|
|
25
|
+
|
|
26
|
+
## Comandos
|
|
27
|
+
|
|
28
|
+
Crie com os geradores, não à mão: eles registram a rota, as mensagens e os índices, e rodam o `prumo check` no fim.
|
|
29
|
+
|
|
30
|
+
| Comando | O que faz |
|
|
31
|
+
| ------------------------------------------------------ | ------------------------------------------------------------------------------- |
|
|
32
|
+
| `pnpm exec prumo make:domain <nome>` | Schema, repositório com mock e contrato, queries e o teste de contrato |
|
|
33
|
+
| `pnpm exec prumo make:page <nome> [--domain <nome>]` | Tela com index, model, view, teste, mensagens e rota; com `--domain`, lista dele |
|
|
34
|
+
| `pnpm exec prumo make:component <nome> --page <tela>` | Componente só HTML e o teste dele (`--shared` para o `src/components/shared`) |
|
|
35
|
+
| `pnpm exec prumo check` | Confere a arquitetura do projeto inteiro |
|
|
36
|
+
| `pnpm exec prumo doctor` | Confere Node, pnpm e a versão dos pacotes do Prumo |
|
|
37
|
+
|
|
38
|
+
Todos os geradores aceitam `--dry-run` (só lista o que faria). O servidor MCP do Prumo (`.mcp.json`) dá a um agente os mesmos comandos como ferramentas (`make_page`, `make_domain`, `check`...).
|
|
39
|
+
|
|
40
|
+
Scripts do projeto: `pnpm dev`, `pnpm build`, `pnpm typecheck`, `pnpm lint`, `pnpm check`, `pnpm test` e `pnpm verify` (typecheck, lint, check e test; sem navegador). Rode o `pnpm verify` antes de dar uma tarefa por pronta.
|
|
41
|
+
|
|
42
|
+
## Regras
|
|
43
|
+
|
|
44
|
+
- Comentários e documentação em português; nomes de função, variável e arquivo em inglês.
|
|
45
|
+
- Teste o comportamento novo (Vitest, com o `renderWithProviders` de `@/test/render`).
|
|
46
|
+
- Dependência nova só com aprovação de uma pessoa.
|
|
47
|
+
|
|
48
|
+
## Instalação
|
|
49
|
+
|
|
50
|
+
Os pacotes `@matizze/prumo-*` vêm do npm público: o `pnpm install` basta, sem token.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# {{app.title}}
|
|
2
|
+
|
|
3
|
+
App React criado pelo Prumo (`prumo new`). O guia para pessoas e agentes de IA está em [AGENTS.md](AGENTS.md).
|
|
4
|
+
|
|
5
|
+
## Instalação
|
|
6
|
+
|
|
7
|
+
Os pacotes `@matizze/prumo-*` vêm do npm público, sem token nem configuração extra:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm install
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Comandos
|
|
14
|
+
|
|
15
|
+
`pnpm dev`, `pnpm build`, `pnpm typecheck`, `pnpm lint`, `pnpm check`, `pnpm test` e `pnpm verify` (typecheck, lint, check e test).
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import js from '@eslint/js'
|
|
2
|
+
import prumo from '@matizze/prumo-rules/eslint'
|
|
3
|
+
import globals from 'globals'
|
|
4
|
+
import reactHooks from 'eslint-plugin-react-hooks'
|
|
5
|
+
import tseslint from 'typescript-eslint'
|
|
6
|
+
import { defineConfig, globalIgnores } from 'eslint/config'
|
|
7
|
+
|
|
8
|
+
export default defineConfig([
|
|
9
|
+
globalIgnores(['dist', 'node_modules']),
|
|
10
|
+
{
|
|
11
|
+
files: ['**/*.{ts,tsx}'],
|
|
12
|
+
extends: [js.configs.recommended, tseslint.configs.recommended, reactHooks.configs.flat.recommended],
|
|
13
|
+
languageOptions: {
|
|
14
|
+
globals: globals.browser,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
// Regras da arquitetura do Prumo: a estrutura de cada tela e nenhum import entre telas
|
|
18
|
+
prumo.configs.recommended,
|
|
19
|
+
])
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Dependências
|
|
2
|
+
node_modules
|
|
3
|
+
|
|
4
|
+
# Saída de build e caches do TypeScript
|
|
5
|
+
dist
|
|
6
|
+
*.tsbuildinfo
|
|
7
|
+
coverage
|
|
8
|
+
|
|
9
|
+
# Logs
|
|
10
|
+
*.log
|
|
11
|
+
|
|
12
|
+
# Variáveis de ambiente (nunca commite segredos)
|
|
13
|
+
.env
|
|
14
|
+
.env.*
|
|
15
|
+
!.env.example
|
|
16
|
+
*.local
|
|
17
|
+
|
|
18
|
+
# Editores e sistema
|
|
19
|
+
.vscode/*
|
|
20
|
+
!.vscode/extensions.json
|
|
21
|
+
.idea
|
|
22
|
+
.DS_Store
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="pt-BR">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>{{app.title}}</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="root"></div>
|
|
10
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineI18n } from '@matizze/prumo-core/i18n'
|
|
2
|
+
import en from './messages/en'
|
|
3
|
+
import ptBR from './messages/pt-BR'
|
|
4
|
+
|
|
5
|
+
export const { I18nProvider, useTranslations } = defineI18n({
|
|
6
|
+
messages: { 'pt-BR': ptBR, en },
|
|
7
|
+
defaultLocale: 'pt-BR',
|
|
8
|
+
languages: {
|
|
9
|
+
'pt-BR': { name: 'Português (Brasil)', shortName: 'PT' },
|
|
10
|
+
en: { name: 'English', shortName: 'EN' },
|
|
11
|
+
},
|
|
12
|
+
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { StrictMode } from 'react'
|
|
2
|
+
import { createRoot } from 'react-dom/client'
|
|
3
|
+
import App from './App'
|
|
4
|
+
import { AppProvider } from './providers/app'
|
|
5
|
+
|
|
6
|
+
createRoot(document.getElementById('root')!).render(
|
|
7
|
+
<StrictMode>
|
|
8
|
+
<AppProvider>
|
|
9
|
+
<App />
|
|
10
|
+
</AppProvider>
|
|
11
|
+
</StrictMode>,
|
|
12
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default {}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createQueryClient, QueryProvider } from '@matizze/prumo-core/query'
|
|
2
|
+
import type { ReactNode } from 'react'
|
|
3
|
+
import { I18nProvider } from '@/i18n'
|
|
4
|
+
import { RepositoryProvider } from '@/providers/repository'
|
|
5
|
+
|
|
6
|
+
function createClient() {
|
|
7
|
+
return createQueryClient({
|
|
8
|
+
// Sem interface no projeto, o erro vai para o console: troque pela notificação do seu design system
|
|
9
|
+
notify: (message) => console.error(message),
|
|
10
|
+
getErrorMessage: (error) => (error instanceof Error ? error.message : String(error)),
|
|
11
|
+
})
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Os provedores do app: dados (TanStack Query), textos (i18n) e repositórios. */
|
|
15
|
+
export function AppProvider({ children }: { children: ReactNode }) {
|
|
16
|
+
return (
|
|
17
|
+
<QueryProvider createClient={createClient}>
|
|
18
|
+
<I18nProvider>
|
|
19
|
+
<RepositoryProvider>{children}</RepositoryProvider>
|
|
20
|
+
</I18nProvider>
|
|
21
|
+
</QueryProvider>
|
|
22
|
+
)
|
|
23
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { createRepositoryContext } from '@matizze/prumo-core/repositories'
|
|
2
|
+
import { createRepositories, type RepositoryContainer } from '@/repositories'
|
|
3
|
+
|
|
4
|
+
export const { RepositoryProvider, useRepositories } =
|
|
5
|
+
createRepositoryContext<RepositoryContainer>(createRepositories)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Queries e mutations, uma por domínio (prumo make:domain). O comando registra cada uma aqui.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createRepositoryContainer,
|
|
3
|
+
resolveDataSource,
|
|
4
|
+
type RepositoryContainerOf,
|
|
5
|
+
} from '@matizze/prumo-core/repositories'
|
|
6
|
+
import { DATA_SOURCES, type RepositoryOptions } from './options'
|
|
7
|
+
|
|
8
|
+
export { DATA_SOURCES, type DataSource, type RepositoryOptions } from './options'
|
|
9
|
+
|
|
10
|
+
// O container: o prumo make:domain acrescenta uma fábrica por domínio
|
|
11
|
+
const factories = {}
|
|
12
|
+
|
|
13
|
+
export type RepositoryContainer = RepositoryContainerOf<typeof factories>
|
|
14
|
+
|
|
15
|
+
export function createRepositories(options: Partial<RepositoryOptions> = {}): RepositoryContainer {
|
|
16
|
+
const dataSource = options.dataSource ?? resolveDataSource(undefined, DATA_SOURCES, 'memory')
|
|
17
|
+
return createRepositoryContainer(factories, { ...options, dataSource })
|
|
18
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RepositoryOptions as CoreRepositoryOptions } from '@matizze/prumo-core/repositories'
|
|
2
|
+
|
|
3
|
+
/** De onde os repositórios leem: hoje só a memória (o mock). Acrescente a API real aqui. */
|
|
4
|
+
export const DATA_SOURCES = ['memory'] as const
|
|
5
|
+
|
|
6
|
+
export type DataSource = (typeof DATA_SOURCES)[number]
|
|
7
|
+
|
|
8
|
+
export type RepositoryOptions = CoreRepositoryOptions<DataSource>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Schemas das entidades, um por domínio (prumo make:domain). O comando registra cada um aqui.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { QueryClient } from '@tanstack/react-query'
|
|
2
|
+
import { createRenderWithProviders, createTestQueryClient } from '@matizze/prumo-testing'
|
|
3
|
+
import type { ReactNode } from 'react'
|
|
4
|
+
import { I18nProvider } from '@/i18n'
|
|
5
|
+
import { RepositoryProvider } from '@/providers/repository'
|
|
6
|
+
import { createRepositories, type RepositoryContainer } from '@/repositories'
|
|
7
|
+
|
|
8
|
+
function Providers({
|
|
9
|
+
children,
|
|
10
|
+
repositories,
|
|
11
|
+
}: {
|
|
12
|
+
children: ReactNode
|
|
13
|
+
repositories: RepositoryContainer
|
|
14
|
+
}) {
|
|
15
|
+
return (
|
|
16
|
+
<I18nProvider>
|
|
17
|
+
<RepositoryProvider value={repositories}>{children}</RepositoryProvider>
|
|
18
|
+
</I18nProvider>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Renderiza com os provedores do app, a rota em memória e repositórios em memória sem latência. */
|
|
23
|
+
export const renderWithProviders = createRenderWithProviders<RepositoryContainer>({
|
|
24
|
+
Providers,
|
|
25
|
+
createRepositories: (overrides) => ({
|
|
26
|
+
...createRepositories({ dataSource: 'memory', latencyMs: 0 }),
|
|
27
|
+
...overrides,
|
|
28
|
+
}),
|
|
29
|
+
createQueryClient: () =>
|
|
30
|
+
createTestQueryClient((options) => new QueryClient({ defaultOptions: options })),
|
|
31
|
+
})
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2023",
|
|
4
|
+
"lib": ["ES2023", "DOM", "DOM.Iterable"],
|
|
5
|
+
"module": "esnext",
|
|
6
|
+
"types": ["node"],
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
|
+
"allowImportingTsExtensions": true,
|
|
10
|
+
"resolveJsonModule": true,
|
|
11
|
+
"verbatimModuleSyntax": true,
|
|
12
|
+
"moduleDetection": "force",
|
|
13
|
+
"jsx": "react-jsx",
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
"strict": true,
|
|
16
|
+
"noUnusedLocals": true,
|
|
17
|
+
"noUnusedParameters": true,
|
|
18
|
+
"erasableSyntaxOnly": true,
|
|
19
|
+
"noFallthroughCasesInSwitch": true,
|
|
20
|
+
"noUncheckedIndexedAccess": true,
|
|
21
|
+
"paths": { "@/*": ["./src/*"] }
|
|
22
|
+
},
|
|
23
|
+
"include": ["src", "vite.config.ts"]
|
|
24
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import react from '@vitejs/plugin-react'
|
|
3
|
+
import { defineConfig } from 'vitest/config'
|
|
4
|
+
|
|
5
|
+
// https://vite.dev/config/ e https://vitest.dev/config/
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
plugins: [react()],
|
|
8
|
+
resolve: {
|
|
9
|
+
alias: { '@': path.resolve(import.meta.dirname, 'src') },
|
|
10
|
+
},
|
|
11
|
+
test: {
|
|
12
|
+
environment: 'jsdom',
|
|
13
|
+
setupFiles: ['./src/test/setup.ts'],
|
|
14
|
+
include: ['src/**/*.test.{ts,tsx}'],
|
|
15
|
+
},
|
|
16
|
+
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react'
|
|
2
|
+
import { expect, it } from 'vitest'
|
|
3
|
+
import { {{component.pascal}} } from './{{component.kebab}}'
|
|
4
|
+
|
|
5
|
+
it('mostra o título', () => {
|
|
6
|
+
render(<{{component.pascal}} title="Exemplo" />)
|
|
7
|
+
|
|
8
|
+
expect(screen.getByRole('heading', { name: 'Exemplo' })).toBeDefined()
|
|
9
|
+
})
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { createQueryKeys } from '@matizze/prumo-core/query'
|
|
2
|
+
import { queryOptions, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
3
|
+
import { useRepositories } from '@/providers/repository'
|
|
4
|
+
import type { I{{plural.pascal}}Repository } from '@/repositories'
|
|
5
|
+
import type { {{singular.pascal}}Input, {{singular.pascal}}ListQuery } from '@/schemas'
|
|
6
|
+
|
|
7
|
+
// `all` é o prefixo de tudo deste domínio: use para invalidar depois de criar, editar ou remover
|
|
8
|
+
export const {{singular.camel}}Keys = createQueryKeys('{{plural.kebab}}', {
|
|
9
|
+
list: (query: {{singular.pascal}}ListQuery = {}) => ['list', query] as const,
|
|
10
|
+
detail: (id: string) => ['detail', id] as const,
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
export const {{singular.camel}}Queries = {
|
|
14
|
+
list: (repository: I{{plural.pascal}}Repository, query: {{singular.pascal}}ListQuery = {}) =>
|
|
15
|
+
queryOptions({
|
|
16
|
+
queryKey: {{singular.camel}}Keys.list(query),
|
|
17
|
+
queryFn: () => repository.list(query),
|
|
18
|
+
}),
|
|
19
|
+
detail: (repository: I{{plural.pascal}}Repository, id: string) =>
|
|
20
|
+
queryOptions({
|
|
21
|
+
queryKey: {{singular.camel}}Keys.detail(id),
|
|
22
|
+
queryFn: () => repository.get(id),
|
|
23
|
+
}),
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function use{{plural.pascal}}List(query: {{singular.pascal}}ListQuery = {}) {
|
|
27
|
+
const repository = useRepositories().{{plural.camel}}
|
|
28
|
+
return useQuery({{singular.camel}}Queries.list(repository, query))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function use{{singular.pascal}}Detail(id: string) {
|
|
32
|
+
const repository = useRepositories().{{plural.camel}}
|
|
33
|
+
return useQuery({{singular.camel}}Queries.detail(repository, id))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function useCreate{{singular.pascal}}() {
|
|
37
|
+
const repository = useRepositories().{{plural.camel}}
|
|
38
|
+
const queryClient = useQueryClient()
|
|
39
|
+
return useMutation({
|
|
40
|
+
mutationFn: (input: {{singular.pascal}}Input) => repository.create(input),
|
|
41
|
+
onSuccess: () => queryClient.invalidateQueries({ queryKey: {{singular.camel}}Keys.all }),
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function useUpdate{{singular.pascal}}() {
|
|
46
|
+
const repository = useRepositories().{{plural.camel}}
|
|
47
|
+
const queryClient = useQueryClient()
|
|
48
|
+
return useMutation({
|
|
49
|
+
mutationFn: ({ id, input }: { id: string; input: {{singular.pascal}}Input }) =>
|
|
50
|
+
repository.update(id, input),
|
|
51
|
+
onSuccess: () => queryClient.invalidateQueries({ queryKey: {{singular.camel}}Keys.all }),
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function useRemove{{singular.pascal}}() {
|
|
56
|
+
const repository = useRepositories().{{plural.camel}}
|
|
57
|
+
const queryClient = useQueryClient()
|
|
58
|
+
return useMutation({
|
|
59
|
+
mutationFn: (id: string) => repository.remove(id),
|
|
60
|
+
onSuccess: () => queryClient.invalidateQueries({ queryKey: {{singular.camel}}Keys.all }),
|
|
61
|
+
})
|
|
62
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { UIError } from '@matizze/prumo-core/errors'
|
|
2
|
+
import { defineContractSuite, runContractSuite } from '@matizze/prumo-testing/contract'
|
|
3
|
+
import { expect, it } from 'vitest'
|
|
4
|
+
import { MOCK_{{plural.constant}} } from './fixtures'
|
|
5
|
+
import type { I{{plural.pascal}}Repository } from './repository.contract'
|
|
6
|
+
import { Mock{{plural.pascal}}Repository } from './repository.mock'
|
|
7
|
+
|
|
8
|
+
const {{plural.camel}}Contract = defineContractSuite<I{{plural.pascal}}Repository>(
|
|
9
|
+
'I{{plural.pascal}}Repository contract',
|
|
10
|
+
({ repo }) => {
|
|
11
|
+
it('lista as fixtures, com ids únicos', async () => {
|
|
12
|
+
const { items, total } = await repo.list()
|
|
13
|
+
expect(total).toBe(MOCK_{{plural.constant}}.length)
|
|
14
|
+
expect(new Set(items.map((item) => item.id)).size).toBe(MOCK_{{plural.constant}}.length)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('busca pelo nome, sem diferenciar maiúsculas e acentos', async () => {
|
|
18
|
+
const { items } = await repo.list({ search: 'EXEMPLO 2' })
|
|
19
|
+
expect(items.map((item) => item.name)).toEqual(['Exemplo 2'])
|
|
20
|
+
expect((await repo.list({ search: 'nada disso' })).total).toBe(0)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('ordena e pagina, com o total de antes da página', async () => {
|
|
24
|
+
const page = await repo.list({
|
|
25
|
+
sort: { key: 'name', direction: 'desc' },
|
|
26
|
+
page: 1,
|
|
27
|
+
page_size: 2,
|
|
28
|
+
})
|
|
29
|
+
expect(page.total).toBe(MOCK_{{plural.constant}}.length)
|
|
30
|
+
expect(page.items.map((item) => item.name)).toEqual(['Exemplo 3', 'Exemplo 2'])
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('busca um registro e rejeita um id que não existe', async () => {
|
|
34
|
+
expect(await repo.get('{{singular.kebab}}-1')).toEqual(MOCK_{{plural.constant}}[0])
|
|
35
|
+
await expect(repo.get('{{singular.kebab}}-missing')).rejects.toBeInstanceOf(UIError)
|
|
36
|
+
await expect(repo.get('{{singular.kebab}}-missing')).rejects.toMatchObject({
|
|
37
|
+
code: '{{singular.constant}}_NOT_FOUND',
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('cria um registro com id e data, e ele aparece na lista', async () => {
|
|
42
|
+
const created = await repo.create({ name: 'Novo' })
|
|
43
|
+
expect(created).toMatchObject({ name: 'Novo' })
|
|
44
|
+
expect(created.id).not.toBe('')
|
|
45
|
+
expect(Number.isNaN(Date.parse(created.createdAt))).toBe(false)
|
|
46
|
+
const { items, total } = await repo.list()
|
|
47
|
+
expect(total).toBe(MOCK_{{plural.constant}}.length + 1)
|
|
48
|
+
expect(new Set(items.map((item) => item.id)).size).toBe(total)
|
|
49
|
+
expect(await repo.get(created.id)).toEqual(created)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('edita um registro e rejeita um id que não existe', async () => {
|
|
53
|
+
const updated = await repo.update('{{singular.kebab}}-1', { name: 'Renomeado' })
|
|
54
|
+
expect(updated).toMatchObject({ id: '{{singular.kebab}}-1', name: 'Renomeado' })
|
|
55
|
+
expect((await repo.get('{{singular.kebab}}-1')).name).toBe('Renomeado')
|
|
56
|
+
await expect(repo.update('{{singular.kebab}}-missing', { name: 'x' })).rejects.toMatchObject({
|
|
57
|
+
code: '{{singular.constant}}_NOT_FOUND',
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('remove um registro e rejeita um id que não existe', async () => {
|
|
62
|
+
await repo.remove('{{singular.kebab}}-1')
|
|
63
|
+
expect((await repo.list()).total).toBe(MOCK_{{plural.constant}}.length - 1)
|
|
64
|
+
await expect(repo.get('{{singular.kebab}}-1')).rejects.toBeInstanceOf(UIError)
|
|
65
|
+
await expect(repo.remove('{{singular.kebab}}-1')).rejects.toMatchObject({
|
|
66
|
+
code: '{{singular.constant}}_NOT_FOUND',
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
},
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
runContractSuite({{plural.camel}}Contract, {
|
|
73
|
+
name: 'Mock{{plural.pascal}}Repository',
|
|
74
|
+
create: () => new Mock{{plural.pascal}}Repository({ latencyMs: 0 }),
|
|
75
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Page } from '@matizze/prumo-core/data'
|
|
2
|
+
import type { {{singular.pascal}}Input, {{singular.pascal}}ListQuery, {{singular.pascal}}Schema } from '@/schemas'
|
|
3
|
+
|
|
4
|
+
export interface I{{plural.pascal}}Repository {
|
|
5
|
+
list(query?: {{singular.pascal}}ListQuery): Promise<Page<{{singular.pascal}}Schema>>
|
|
6
|
+
/** Rejeita com `UIError('{{singular.constant}}_NOT_FOUND')` quando o id não existe. */
|
|
7
|
+
get(id: string): Promise<{{singular.pascal}}Schema>
|
|
8
|
+
create(input: {{singular.pascal}}Input): Promise<{{singular.pascal}}Schema>
|
|
9
|
+
/** Rejeita com `UIError('{{singular.constant}}_NOT_FOUND')` quando o id não existe. */
|
|
10
|
+
update(id: string, input: {{singular.pascal}}Input): Promise<{{singular.pascal}}Schema>
|
|
11
|
+
/** Rejeita com `UIError('{{singular.constant}}_NOT_FOUND')` quando o id não existe. */
|
|
12
|
+
remove(id: string): Promise<void>
|
|
13
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { {{singular.pascal}}Schema } from '@/schemas'
|
|
2
|
+
|
|
3
|
+
// Dados de exemplo do mock: troque pelos do seu domínio.
|
|
4
|
+
export const MOCK_{{plural.constant}}: {{singular.pascal}}Schema[] = [
|
|
5
|
+
{ id: '{{singular.kebab}}-1', name: 'Exemplo 1', createdAt: '2026-01-05T12:00:00.000Z' },
|
|
6
|
+
{ id: '{{singular.kebab}}-2', name: 'Exemplo 2', createdAt: '2026-01-14T12:00:00.000Z' },
|
|
7
|
+
{ id: '{{singular.kebab}}-3', name: 'Exemplo 3', createdAt: '2026-01-23T12:00:00.000Z' },
|
|
8
|
+
]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RepositoryOptions } from '../options'
|
|
2
|
+
import type { I{{plural.pascal}}Repository } from './repository.contract'
|
|
3
|
+
import { Mock{{plural.pascal}}Repository } from './repository.mock'
|
|
4
|
+
|
|
5
|
+
export type { I{{plural.pascal}}Repository } from './repository.contract'
|
|
6
|
+
export { Mock{{plural.pascal}}Repository, type Mock{{plural.pascal}}RepositoryOptions } from './repository.mock'
|
|
7
|
+
export { MOCK_{{plural.constant}} } from './fixtures'
|
|
8
|
+
|
|
9
|
+
export function create{{plural.pascal}}Repository({ latencyMs }: RepositoryOptions): I{{plural.pascal}}Repository {
|
|
10
|
+
// Só mock por enquanto; a implementação real (API) entra aqui
|
|
11
|
+
return new Mock{{plural.pascal}}Repository({ latencyMs })
|
|
12
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Page } from '@matizze/prumo-core/data'
|
|
2
|
+
import { UIError } from '@matizze/prumo-core/errors'
|
|
3
|
+
import { matchesSearch, paginate, sortBy, wait } from '@matizze/prumo-core/mock'
|
|
4
|
+
import type { {{singular.pascal}}Input, {{singular.pascal}}ListQuery, {{singular.pascal}}Schema } from '@/schemas'
|
|
5
|
+
import { MOCK_{{plural.constant}} } from './fixtures'
|
|
6
|
+
import type { I{{plural.pascal}}Repository } from './repository.contract'
|
|
7
|
+
|
|
8
|
+
export interface Mock{{plural.pascal}}RepositoryOptions {
|
|
9
|
+
/** Latência simulada por operação, em ms (padrão 300). Use 0 em testes. */
|
|
10
|
+
latencyMs?: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class Mock{{plural.pascal}}Repository implements I{{plural.pascal}}Repository {
|
|
14
|
+
private readonly items: {{singular.pascal}}Schema[] = [...MOCK_{{plural.constant}}]
|
|
15
|
+
private readonly latencyMs: number
|
|
16
|
+
private sequence = MOCK_{{plural.constant}}.length
|
|
17
|
+
|
|
18
|
+
constructor({ latencyMs = 300 }: Mock{{plural.pascal}}RepositoryOptions = {}) {
|
|
19
|
+
this.latencyMs = latencyMs
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async list(query: {{singular.pascal}}ListQuery = {}): Promise<Page<{{singular.pascal}}Schema>> {
|
|
23
|
+
await wait(this.latencyMs)
|
|
24
|
+
const filtered = this.items.filter((item) => matchesSearch([item.name], query.search))
|
|
25
|
+
const sorted = sortBy(filtered, query.sort, {
|
|
26
|
+
name: (item) => item.name,
|
|
27
|
+
createdAt: (item) => item.createdAt,
|
|
28
|
+
})
|
|
29
|
+
return paginate(sorted, query.page, query.page_size)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async get(id: string): Promise<{{singular.pascal}}Schema> {
|
|
33
|
+
await wait(this.latencyMs)
|
|
34
|
+
return this.find(id).item
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async create(input: {{singular.pascal}}Input): Promise<{{singular.pascal}}Schema> {
|
|
38
|
+
await wait(this.latencyMs)
|
|
39
|
+
this.sequence += 1
|
|
40
|
+
const item: {{singular.pascal}}Schema = {
|
|
41
|
+
id: `{{singular.kebab}}-${this.sequence}`,
|
|
42
|
+
name: input.name,
|
|
43
|
+
createdAt: new Date().toISOString(),
|
|
44
|
+
}
|
|
45
|
+
this.items.push(item)
|
|
46
|
+
return item
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async update(id: string, input: {{singular.pascal}}Input): Promise<{{singular.pascal}}Schema> {
|
|
50
|
+
await wait(this.latencyMs)
|
|
51
|
+
const { at, item } = this.find(id)
|
|
52
|
+
// Troca o objeto em vez de mexer nele: as fixtures e o que já foi devolvido não mudam
|
|
53
|
+
const updated = { ...item, name: input.name }
|
|
54
|
+
this.items[at] = updated
|
|
55
|
+
return updated
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async remove(id: string): Promise<void> {
|
|
59
|
+
await wait(this.latencyMs)
|
|
60
|
+
this.items.splice(this.find(id).at, 1)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private find(id: string): { at: number; item: {{singular.pascal}}Schema } {
|
|
64
|
+
const at = this.items.findIndex((candidate) => candidate.id === id)
|
|
65
|
+
const item = this.items[at]
|
|
66
|
+
if (!item) throw new UIError('{{singular.constant}}_NOT_FOUND', 'Registro não encontrado.')
|
|
67
|
+
return { at, item }
|
|
68
|
+
}
|
|
69
|
+
}
|