@matizze/prumo-cli 0.0.0-stage → 0.5.1
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 +121 -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 +87 -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 +184 -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 +29 -0
- package/dist/generate/app.js +137 -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/pnpm.d.ts +14 -0
- package/dist/pnpm.js +37 -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
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import type { PageQuery, Sort } from '@matizze/prumo-core/data'
|
|
3
|
+
|
|
4
|
+
export const {{singular.camel}}Schema = z.object({
|
|
5
|
+
id: z.string(),
|
|
6
|
+
name: z.string(),
|
|
7
|
+
createdAt: z.string(),
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
export type {{singular.pascal}}Schema = z.infer<typeof {{singular.camel}}Schema>
|
|
11
|
+
|
|
12
|
+
/** O que se envia para criar ou editar: o `id` e a data são do repositório. */
|
|
13
|
+
export const {{singular.camel}}InputSchema = {{singular.camel}}Schema.pick({ name: true })
|
|
14
|
+
|
|
15
|
+
export type {{singular.pascal}}Input = z.infer<typeof {{singular.camel}}InputSchema>
|
|
16
|
+
|
|
17
|
+
export type {{singular.pascal}}SortKey = 'name' | 'createdAt'
|
|
18
|
+
|
|
19
|
+
export interface {{singular.pascal}}ListQuery extends PageQuery {
|
|
20
|
+
/** Busca pelo nome, sem diferenciar maiúsculas e acentos. */
|
|
21
|
+
search?: string
|
|
22
|
+
sort?: Sort<{{singular.pascal}}SortKey>
|
|
23
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { screen } from '@testing-library/react'
|
|
2
|
+
import { expect, it } from 'vitest'
|
|
3
|
+
import { renderWithProviders } from '@/test/render'
|
|
4
|
+
import {{page.pascal}}Page from '.'
|
|
5
|
+
|
|
6
|
+
it('mostra o título e, depois de carregar, a lista do domínio', async () => {
|
|
7
|
+
renderWithProviders(<{{page.pascal}}Page />, { path: '/{{page.kebab}}' })
|
|
8
|
+
|
|
9
|
+
expect(screen.getByRole('heading', { name: '{{page.title}}' })).toBeDefined()
|
|
10
|
+
expect(await screen.findByRole('list')).toBeDefined()
|
|
11
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { screen } from '@testing-library/react'
|
|
2
|
+
import { expect, it } from 'vitest'
|
|
3
|
+
import { renderWithProviders } from '@/test/render'
|
|
4
|
+
import {{page.pascal}}Page from '.'
|
|
5
|
+
|
|
6
|
+
it('mostra o título da tela', () => {
|
|
7
|
+
renderWithProviders(<{{page.pascal}}Page />, { path: '/{{page.kebab}}' })
|
|
8
|
+
|
|
9
|
+
expect(screen.getByRole('heading', { name: '{{page.title}}' })).toBeDefined()
|
|
10
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useTranslations } from '@/i18n'
|
|
2
|
+
import { use{{domain.pascal}}List } from '@/queries/{{domain.kebab}}'
|
|
3
|
+
|
|
4
|
+
export function use{{page.pascal}}Model() {
|
|
5
|
+
const t = useTranslations('{{page.camel}}')
|
|
6
|
+
const list = use{{domain.pascal}}List()
|
|
7
|
+
return {
|
|
8
|
+
title: t('title'),
|
|
9
|
+
loadingText: t('loading'),
|
|
10
|
+
failedText: t('failed'),
|
|
11
|
+
items: list.data?.items ?? [],
|
|
12
|
+
loading: list.isPending,
|
|
13
|
+
failed: list.isError,
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type {{page.pascal}}Model = ReturnType<typeof use{{page.pascal}}Model>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { {{page.pascal}}Model } from './model'
|
|
2
|
+
|
|
3
|
+
export function {{page.pascal}}View(m: {{page.pascal}}Model) {
|
|
4
|
+
return (
|
|
5
|
+
<main>
|
|
6
|
+
<h1>{m.title}</h1>
|
|
7
|
+
{m.loading ? (
|
|
8
|
+
<p>{m.loadingText}</p>
|
|
9
|
+
) : m.failed ? (
|
|
10
|
+
<p role="alert">{m.failedText}</p>
|
|
11
|
+
) : (
|
|
12
|
+
<ul>
|
|
13
|
+
{m.items.map((i) => (
|
|
14
|
+
<li key={i.id}>{i.name}</li>
|
|
15
|
+
))}
|
|
16
|
+
</ul>
|
|
17
|
+
)}
|
|
18
|
+
</main>
|
|
19
|
+
)
|
|
20
|
+
}
|