create-codeverse 0.0.0-stage → 0.0.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 +457 -0
- package/bin/cli.js +280 -0
- package/lib/apply/front.js +122 -0
- package/lib/apply/test.js +67 -0
- package/lib/copyTemplate.js +73 -0
- package/lib/desktop.js +13 -0
- package/lib/installDependencies.js +37 -0
- package/lib/openInEditor.js +14 -0
- package/lib/packageJson.js +19 -0
- package/lib/paths.js +4 -0
- package/lib/prompts.js +68 -0
- package/lib/runCommand.js +40 -0
- package/lib/secret.js +80 -0
- package/lib/templates.js +79 -0
- package/lib/validateProjectName.js +24 -0
- package/lib/versions.js +50 -0
- package/package.json +46 -6
- package/templates/codeskills.enc +0 -0
- package/templates/extras/test-componentes/cypress/component/Login.cy.jsx +120 -0
- package/templates/extras/test-componentes/cypress/fixtures/example.json +5 -0
- package/templates/extras/test-componentes/cypress/support/commands.js +25 -0
- package/templates/extras/test-componentes/cypress/support/component-index.html +14 -0
- package/templates/extras/test-componentes/cypress/support/component.js +24 -0
- package/templates/extras/test-componentes/cypress.config.js +10 -0
- package/templates/extras/test-componentes/src/app/page.jsx +5 -0
- package/templates/extras/test-componentes/src/components/Login.jsx +47 -0
- package/templates/extras/test-dependencias/tests/nome-do-script.test.js +79 -0
- package/templates/front/.env.example +0 -0
- package/templates/front/ReadMe.MD +36 -0
- package/templates/front/_gitignore +42 -0
- package/templates/front/biome.json +42 -0
- package/templates/front/jsconfig.json +8 -0
- package/templates/front/next.config.mjs +11 -0
- package/templates/front/package.template.json +41 -0
- package/templates/front/public/fonts/gitkeep +0 -0
- package/templates/front/public/icons/gitkeep +0 -0
- package/templates/front/public/images/gitkeep +0 -0
- package/templates/front/public/media/gitkeep +0 -0
- package/templates/front/public/sounds/gitkeep +0 -0
- package/templates/front/src/app/favicon.ico +0 -0
- package/templates/front/src/app/globals.css +9 -0
- package/templates/front/src/app/layout.js +14 -0
- package/templates/front/src/app/nome-da-rota/nome-da-rota.module.css +0 -0
- package/templates/front/src/app/nome-da-rota/page.jsx +5 -0
- package/templates/front/src/app/page.jsx +39 -0
- package/templates/front/src/app/page.module.css +98 -0
- package/templates/front/src/components/Nome-do-componente.jsx +5 -0
- package/templates/front/src/components/Nome-do-componente.module.css +0 -0
- package/templates/integracao/cypress/e2e/meu-teste.cy.js +75 -0
- package/templates/integracao/cypress/fixtures/example.json +5 -0
- package/templates/integracao/cypress/support/commands.js +25 -0
- package/templates/integracao/cypress/support/e2e.js +17 -0
- package/templates/integracao/cypress.config.js +7 -0
- package/templates/integracao/package.template.json +37 -0
- package/templates/test/.env.example +0 -0
- package/templates/test/_gitignore +25 -0
- package/templates/test/jest.reporters.config.mjs +14 -0
- package/templates/test/package.template.json +42 -0
- package/templates/test/src/nome-do-seu-script.js +4 -0
- package/templates/test/tests/nome-do-script.test.js +40 -0
- package/templates/versions.json +81 -0
- package/README.md +0 -3
package/lib/prompts.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { setTimeout } from 'node:timers/promises';
|
|
2
|
+
import { styleText } from 'node:util';
|
|
3
|
+
|
|
4
|
+
import { cancel, isCancel, spinner, updateSettings } from '@clack/prompts';
|
|
5
|
+
|
|
6
|
+
// Traduz os textos internos do clack que aceitam configuração. As instruções
|
|
7
|
+
// de teclado (↑/↓, Enter) são fixas em inglês, por isso os menus usam
|
|
8
|
+
// `showInstructions: false`.
|
|
9
|
+
export function configurePrompts() {
|
|
10
|
+
updateSettings({
|
|
11
|
+
messages: {
|
|
12
|
+
cancel: 'Operação cancelada. 😢',
|
|
13
|
+
error: 'Algo deu errado. 😢',
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Troca a linha de resposta que o clack acabou de escrever (a última, "│ ...").
|
|
19
|
+
// Chamada logo depois da resposta: sobe uma linha, pula a barra e os 2 espaços
|
|
20
|
+
// (3 colunas), apaga até o fim da linha e escreve `text`. `previous` é o texto
|
|
21
|
+
// que o clack escreveu: se ele não coube numa linha do terminal, não mexe (subir
|
|
22
|
+
// uma linha só apagaria parte dele). É só cosmético: se a saída não for um
|
|
23
|
+
// terminal ou algo falhar, a linha original do clack continua e o fluxo segue.
|
|
24
|
+
export function replaceAnswerLine(text, previous, output = process.stdout) {
|
|
25
|
+
try {
|
|
26
|
+
if (!output.isTTY) return;
|
|
27
|
+
if (output.columns && previous.length + 3 > output.columns) return;
|
|
28
|
+
output.write(`\x1b[1A\r\x1b[3C\x1b[0K${styleText('dim', text)}\n`);
|
|
29
|
+
} catch {
|
|
30
|
+
// mantém a linha original
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Opções de select/multiselect com os hints alinhados. O clack escreve
|
|
35
|
+
// "label (hint)" só na opção com o cursor, então os labels são completados com
|
|
36
|
+
// espaços até o maior deles e o "(" fica sempre na mesma coluna. Só `ready: false`
|
|
37
|
+
// ganha o "em breve" (os extras não têm `ready`). No multiselect, o resumo junta
|
|
38
|
+
// os labels com vírgula e os espaços aparecem: corrigir com `replaceAnswerLine`.
|
|
39
|
+
export function alignedOptions(items) {
|
|
40
|
+
const width = Math.max(...items.map(({ label }) => label.length));
|
|
41
|
+
return items.map(({ id, label, hint, ready }) => ({
|
|
42
|
+
value: id,
|
|
43
|
+
label: label.padEnd(width),
|
|
44
|
+
hint: ready === false ? `${hint} · em breve` : hint,
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Spinner com contagem regressiva ("<message> em 3s...", 2s, 1s) que termina
|
|
49
|
+
// com `message`. Serve para dar tempo de o aluno ler antes de uma ação.
|
|
50
|
+
export async function countdown(message, seconds) {
|
|
51
|
+
const wait = spinner();
|
|
52
|
+
wait.start(`${message} em ${seconds}s...`);
|
|
53
|
+
for (let left = seconds; left > 0; left--) {
|
|
54
|
+
wait.message(`${message} em ${left}s...`);
|
|
55
|
+
await setTimeout(1000);
|
|
56
|
+
}
|
|
57
|
+
wait.stop(message);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Envolve qualquer resposta do clack: se o aluno cancelou (Ctrl+C), encerra
|
|
61
|
+
// com uma mensagem amigável; senão devolve o valor respondido.
|
|
62
|
+
export function exitIfCancel(value) {
|
|
63
|
+
if (isCancel(value)) {
|
|
64
|
+
cancel('Operação cancelada. 😢');
|
|
65
|
+
process.exit(130);
|
|
66
|
+
}
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
|
|
3
|
+
const TAIL_LINES = 12;
|
|
4
|
+
|
|
5
|
+
// No Windows, comandos como npm e code são atalhos .cmd, que o spawn só
|
|
6
|
+
// consegue abrir por um shell. O comando vai como uma string única (sem array
|
|
7
|
+
// de argumentos, evitando o aviso DEP0190). Os argumentos vêm sempre de textos
|
|
8
|
+
// fixos do CLI e dos nomes de pacote do versions.json, nunca do que o aluno
|
|
9
|
+
// digita, então não há o que escapar.
|
|
10
|
+
//
|
|
11
|
+
// `capture: true` guarda a saída para mostrar o final dela se o comando falhar;
|
|
12
|
+
// `capture: false` descarta tudo (usado para abrir o VS Code, que não pode
|
|
13
|
+
// prender o CLI esperando a janela fechar).
|
|
14
|
+
export function runCommand(command, args, { cwd, capture = true } = {}) {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const stdio = capture ? ['ignore', 'pipe', 'pipe'] : 'ignore';
|
|
17
|
+
const child =
|
|
18
|
+
process.platform === 'win32'
|
|
19
|
+
? spawn([command, ...args].join(' '), [], { cwd, stdio, shell: true })
|
|
20
|
+
: spawn(command, args, { cwd, stdio });
|
|
21
|
+
|
|
22
|
+
let output = '';
|
|
23
|
+
child.stdout?.on('data', (chunk) => {
|
|
24
|
+
output += chunk;
|
|
25
|
+
});
|
|
26
|
+
child.stderr?.on('data', (chunk) => {
|
|
27
|
+
output += chunk;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
child.on('error', reject);
|
|
31
|
+
child.on('close', (code) => {
|
|
32
|
+
if (code === 0) {
|
|
33
|
+
resolve(output);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const tail = output.trim().split(/\r?\n/).slice(-TAIL_LINES).join('\n');
|
|
37
|
+
reject(new Error(`${[command, ...args].join(' ')} saiu com código ${code}.${tail ? `\n${tail}` : ''}`));
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
package/lib/secret.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { createCipheriv, createDecipheriv, randomBytes, scrypt } from 'node:crypto';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { promisify } from 'node:util';
|
|
5
|
+
import { gunzipSync, gzipSync } from 'node:zlib';
|
|
6
|
+
|
|
7
|
+
import { TEMPLATES_DIR } from './paths.js';
|
|
8
|
+
|
|
9
|
+
// Template secreto: todos os arquivos viram um único arquivo .enc, que só abre
|
|
10
|
+
// com o código certo. O código nunca é salvo; ele é a própria chave.
|
|
11
|
+
//
|
|
12
|
+
// Formato do .enc: MAGIC(4) + salt(16) + iv(12) + tag(16) + dados
|
|
13
|
+
// dados = AES-256-GCM( gzip( JSON [{ path, data (base64) }] ) )
|
|
14
|
+
// A chave sai do código via scrypt (lento de propósito, contra força bruta).
|
|
15
|
+
// O GCM confere a tag: com o código errado a abertura falha, sem meio-termo.
|
|
16
|
+
|
|
17
|
+
const MAGIC = Buffer.from('CVSK');
|
|
18
|
+
const SALT_LENGTH = 16;
|
|
19
|
+
const IV_LENGTH = 12;
|
|
20
|
+
const TAG_LENGTH = 16;
|
|
21
|
+
const SCRYPT_OPTIONS = { N: 2 ** 17, r: 8, p: 1, maxmem: 256 * 1024 * 1024 };
|
|
22
|
+
|
|
23
|
+
const scryptAsync = promisify(scrypt);
|
|
24
|
+
const deriveKey = (code, salt) => scryptAsync(code, salt, 32, SCRYPT_OPTIONS);
|
|
25
|
+
|
|
26
|
+
export const secretFile = (templateId) => join(TEMPLATES_DIR, `${templateId}.enc`);
|
|
27
|
+
|
|
28
|
+
// files: [{ path: 'src/index.js', data: Buffer }]
|
|
29
|
+
export async function encryptFiles(files, code) {
|
|
30
|
+
const json = JSON.stringify(files.map(({ path, data }) => ({ path, data: data.toString('base64') })));
|
|
31
|
+
const salt = randomBytes(SALT_LENGTH);
|
|
32
|
+
const iv = randomBytes(IV_LENGTH);
|
|
33
|
+
const key = await deriveKey(code, salt);
|
|
34
|
+
|
|
35
|
+
const cipher = createCipheriv('aes-256-gcm', key, iv);
|
|
36
|
+
const encrypted = Buffer.concat([cipher.update(gzipSync(json)), cipher.final()]);
|
|
37
|
+
|
|
38
|
+
return Buffer.concat([MAGIC, salt, iv, cipher.getAuthTag(), encrypted]);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Devolve [{ path, data: Buffer }] ou null se o código estiver errado.
|
|
42
|
+
export async function decryptFiles(buffer, code) {
|
|
43
|
+
if (!buffer.subarray(0, MAGIC.length).equals(MAGIC)) {
|
|
44
|
+
throw new Error('Arquivo do template secreto inválido.');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let offset = MAGIC.length;
|
|
48
|
+
const salt = buffer.subarray(offset, (offset += SALT_LENGTH));
|
|
49
|
+
const iv = buffer.subarray(offset, (offset += IV_LENGTH));
|
|
50
|
+
const tag = buffer.subarray(offset, (offset += TAG_LENGTH));
|
|
51
|
+
const encrypted = buffer.subarray(offset);
|
|
52
|
+
|
|
53
|
+
const key = await deriveKey(code, salt);
|
|
54
|
+
const decipher = createDecipheriv('aes-256-gcm', key, iv);
|
|
55
|
+
decipher.setAuthTag(tag);
|
|
56
|
+
|
|
57
|
+
let compressed;
|
|
58
|
+
try {
|
|
59
|
+
compressed = Buffer.concat([decipher.update(encrypted), decipher.final()]);
|
|
60
|
+
} catch {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return JSON.parse(gunzipSync(compressed).toString('utf8')).map(({ path, data }) => ({
|
|
65
|
+
path,
|
|
66
|
+
data: Buffer.from(data, 'base64'),
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Lê templates/<id>.enc e tenta abrir com o código digitado pelo aluno.
|
|
71
|
+
export async function openSecretTemplate(templateId, code) {
|
|
72
|
+
let buffer;
|
|
73
|
+
try {
|
|
74
|
+
buffer = await readFile(secretFile(templateId));
|
|
75
|
+
} catch (err) {
|
|
76
|
+
if (err.code === 'ENOENT') throw new Error('Este template ainda não está disponível. 🚧');
|
|
77
|
+
throw err;
|
|
78
|
+
}
|
|
79
|
+
return decryptFiles(buffer, code);
|
|
80
|
+
}
|
package/lib/templates.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { applyFront } from './apply/front.js';
|
|
2
|
+
import { applyTestComponentes, applyTestDependencias } from './apply/test.js';
|
|
3
|
+
|
|
4
|
+
// Registro dos templates. O menu principal lê esta lista: para adicionar um
|
|
5
|
+
// template novo, basta incluir um objeto aqui. `last: true` fixa o template no
|
|
6
|
+
// fim do menu, independente da ordem alfabética. `ready: false` mostra o aviso
|
|
7
|
+
// de "em breve" em vez de seguir para as perguntas do template.
|
|
8
|
+
// `options` (opcional) vira um multiselect de extras. Cada `id` é a mesma chave
|
|
9
|
+
// usada no bloco do template em templates/versions.json.
|
|
10
|
+
// `apply(projectDir, optionIds)` (opcional) altera o código do projeto copiado
|
|
11
|
+
// conforme os extras marcados. A pasta do template é templates/<id>.
|
|
12
|
+
// `choice: true` troca o multiselect por um select de sub-templates: cada item
|
|
13
|
+
// de `options` tem a própria pasta (`dir`), os blocos de versão (`versions`, lista
|
|
14
|
+
// de caminhos em versions.json, ex.: "front.base") e `apply`.
|
|
15
|
+
export const templates = [
|
|
16
|
+
{
|
|
17
|
+
id: 'front',
|
|
18
|
+
label: 'FrontEnd',
|
|
19
|
+
hint: 'NextJS App Router',
|
|
20
|
+
ready: true,
|
|
21
|
+
apply: applyFront,
|
|
22
|
+
options: [
|
|
23
|
+
{ id: 'antd', label: 'Ant Design', hint: 'componentes UI' },
|
|
24
|
+
{ id: 'axios', label: 'Axios', hint: 'requisições HTTP' },
|
|
25
|
+
{ id: 'lucide', label: 'Lucide Icons', hint: 'ícones' },
|
|
26
|
+
{ id: 'tailwind', label: 'TailwindCss', hint: 'estilização CSS' },
|
|
27
|
+
{ id: 'toast', label: 'Toast-Hot', hint: 'notificações' },
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
{ id: 'backend', label: 'BackEnd', hint: 'NodeJS Express', ready: false },
|
|
31
|
+
{ id: 'mobile', label: 'Mobile', hint: 'Expo + Native', ready: false },
|
|
32
|
+
{
|
|
33
|
+
id: 'test',
|
|
34
|
+
label: 'Test',
|
|
35
|
+
hint: 'Jest ou Cypress',
|
|
36
|
+
ready: true,
|
|
37
|
+
choice: true,
|
|
38
|
+
options: [
|
|
39
|
+
{
|
|
40
|
+
id: 'unitario',
|
|
41
|
+
label: 'Unitário',
|
|
42
|
+
hint: 'Jest - funções, classes e regras de negócio',
|
|
43
|
+
ready: true,
|
|
44
|
+
dir: 'test',
|
|
45
|
+
versions: ['test.jest.base'],
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: 'dependencias',
|
|
49
|
+
label: 'Dependências',
|
|
50
|
+
hint: 'Jest - API, Promise e mock',
|
|
51
|
+
ready: true,
|
|
52
|
+
dir: 'test',
|
|
53
|
+
versions: ['test.jest.base', 'test.jest.dependencias'],
|
|
54
|
+
apply: applyTestDependencias,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: 'componentes',
|
|
58
|
+
label: 'Component Testing',
|
|
59
|
+
hint: 'Cypress - componentes React',
|
|
60
|
+
ready: true,
|
|
61
|
+
dir: 'front',
|
|
62
|
+
versions: ['front.base', 'test.cypress.base'],
|
|
63
|
+
apply: applyTestComponentes,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: 'integracao',
|
|
67
|
+
label: 'Integração E2E',
|
|
68
|
+
hint: 'Cypress - End To End',
|
|
69
|
+
ready: true,
|
|
70
|
+
dir: 'integracao',
|
|
71
|
+
versions: ['test.cypress.base'],
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
// `secret: true`: o template fica criptografado em templates/<id>.enc e só
|
|
76
|
+
// abre com o código secreto (ver lib/secret.js e scripts/encrypt.js). Só os
|
|
77
|
+
// arquivos são secretos: as versões ficam no versions.json (bloco "codeskills.base").
|
|
78
|
+
{ id: 'codeskills', label: 'CodeSkills', hint: 'FullStack', ready: true, last: true, secret: true },
|
|
79
|
+
];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const NAME_PATTERN = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
2
|
+
const MAX_LENGTH = 214;
|
|
3
|
+
|
|
4
|
+
export function validateProjectName(raw) {
|
|
5
|
+
const value = String(raw ?? '').trim();
|
|
6
|
+
|
|
7
|
+
if (!value) {
|
|
8
|
+
return { valid: false, message: 'O nome do projeto não pode ser vazio, fera ...' };
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (value.length > MAX_LENGTH) {
|
|
12
|
+
return { valid: false, message: `Nome muito longo (máx. ${MAX_LENGTH} caracteres).` };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (!NAME_PATTERN.test(value)) {
|
|
16
|
+
return {
|
|
17
|
+
valid: false,
|
|
18
|
+
message:
|
|
19
|
+
'Nome inválido. Use apenas letras minúsculas, números e hífen (sem espaços, sem começar ou terminar com hífen).',
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return { valid: true, value };
|
|
24
|
+
}
|
package/lib/versions.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
import { TEMPLATES_DIR } from './paths.js';
|
|
5
|
+
|
|
6
|
+
const GROUPS = ['dependencies', 'devDependencies'];
|
|
7
|
+
|
|
8
|
+
function sortByName(object) {
|
|
9
|
+
return Object.fromEntries(Object.entries(object).sort(([a], [b]) => a.localeCompare(b)));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function findBlock(all, blockPath) {
|
|
13
|
+
const block = blockPath.split('.').reduce((node, key) => node?.[key], all);
|
|
14
|
+
if (!block) {
|
|
15
|
+
throw new Error(`Bloco "${blockPath}" não encontrado em versions.json.`);
|
|
16
|
+
}
|
|
17
|
+
return block;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Lê templates/versions.json e junta os blocos pedidos em `blockPaths` (caminhos
|
|
21
|
+
// separados por ponto, ex.: "front.base", "test.cypress.base"). Cada bloco pode
|
|
22
|
+
// ser reaproveitado por outros templates, sem repetir os pacotes. Devolve:
|
|
23
|
+
// pinned: { dependencies: { nome: 'X.Y.Z' }, devDependencies: {...} }
|
|
24
|
+
// versão fixada, vai direto para o package.json do aluno
|
|
25
|
+
// latest: { dependencies: ['nome'], devDependencies: [...] }
|
|
26
|
+
// valor "latest", instalado depois com `npm install <nome>@latest`
|
|
27
|
+
export async function resolvePackages(blockPaths) {
|
|
28
|
+
const all = JSON.parse(await readFile(join(TEMPLATES_DIR, 'versions.json'), 'utf8'));
|
|
29
|
+
|
|
30
|
+
const pinned = { dependencies: {}, devDependencies: {} };
|
|
31
|
+
const latest = { dependencies: new Set(), devDependencies: new Set() };
|
|
32
|
+
|
|
33
|
+
for (const blockPath of blockPaths) {
|
|
34
|
+
const block = findBlock(all, blockPath);
|
|
35
|
+
for (const group of GROUPS) {
|
|
36
|
+
for (const [name, version] of Object.entries(block[group] ?? {})) {
|
|
37
|
+
if (version === 'latest') latest[group].add(name);
|
|
38
|
+
else pinned[group][name] = version;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const sortedLatest = {};
|
|
44
|
+
for (const group of GROUPS) {
|
|
45
|
+
pinned[group] = sortByName(pinned[group]);
|
|
46
|
+
sortedLatest[group] = [...latest[group]].sort((a, b) => a.localeCompare(b));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return { pinned, latest: sortedLatest };
|
|
50
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "create-codeverse",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Scaffolding CLI for Codeverse students to learn",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-codeverse": "bin/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"encrypt": "cls && node scripts/encrypt.js"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"bin",
|
|
14
|
+
"lib",
|
|
15
|
+
"templates",
|
|
16
|
+
"ReadMe.MD"
|
|
17
|
+
],
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=20"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"create-codeverse",
|
|
23
|
+
"codeverse",
|
|
24
|
+
"cli",
|
|
25
|
+
"scaffold",
|
|
26
|
+
"generator",
|
|
27
|
+
"starter",
|
|
28
|
+
"template",
|
|
29
|
+
"education"
|
|
30
|
+
],
|
|
31
|
+
"author": {
|
|
32
|
+
"name": "Marcello",
|
|
33
|
+
"url": "https://github.com/mapcarboni/"
|
|
34
|
+
},
|
|
35
|
+
"contributors": [
|
|
36
|
+
{
|
|
37
|
+
"name": "Thiago",
|
|
38
|
+
"url": "https://github.com/thiago-rferreira/"
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
"homepage": "https://codeverse.dev.br",
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@clack/prompts": "1.9.0"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { mount } from 'cypress/react';
|
|
2
|
+
import Login from '../../src/components/Login';
|
|
3
|
+
|
|
4
|
+
describe('Componente Login', () => {
|
|
5
|
+
it('estrutura inicial da tela', () => {
|
|
6
|
+
mount(<Login />);
|
|
7
|
+
|
|
8
|
+
// exist: o elemento existe no DOM
|
|
9
|
+
cy.get('form').should('exist');
|
|
10
|
+
|
|
11
|
+
// not.exist: a mensagem ainda não foi criada
|
|
12
|
+
cy.get('p').should('not.exist');
|
|
13
|
+
|
|
14
|
+
// be.visible: o formulário está visível na tela
|
|
15
|
+
cy.get('form').should('be.visible');
|
|
16
|
+
|
|
17
|
+
// have.text: texto exato do título
|
|
18
|
+
cy.get('h1').should('have.text', 'Login');
|
|
19
|
+
|
|
20
|
+
// have.html: HTML exato do título
|
|
21
|
+
cy.get('h1').should('have.html', 'Login');
|
|
22
|
+
|
|
23
|
+
// eq: compara o texto com igualdade (chai)
|
|
24
|
+
cy.get('h1').invoke('text').should('eq', 'Login');
|
|
25
|
+
|
|
26
|
+
// match: compara o texto com uma expressão regular
|
|
27
|
+
cy.get('h1').invoke('text').should('match', /login/i);
|
|
28
|
+
|
|
29
|
+
// contain.text: o texto contém um trecho
|
|
30
|
+
cy.get('h1').should('contain.text', 'Log');
|
|
31
|
+
|
|
32
|
+
// contain: o formulário contém o texto do botão
|
|
33
|
+
cy.get('form').should('contain', 'Entrar');
|
|
34
|
+
|
|
35
|
+
// have.length: existem 2 labels
|
|
36
|
+
cy.get('label').should('have.length', 2);
|
|
37
|
+
|
|
38
|
+
// deep.equal: lista de textos dos labels, comparada item a item
|
|
39
|
+
cy.get('label')
|
|
40
|
+
.then(($labels) => $labels.toArray().map((el) => el.textContent))
|
|
41
|
+
.should('deep.equal', ['Usuário', 'Senha']);
|
|
42
|
+
|
|
43
|
+
// be.enabled: o botão pode ser clicado
|
|
44
|
+
cy.get('button').should('be.enabled');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('atributos dos campos', () => {
|
|
48
|
+
mount(<Login />);
|
|
49
|
+
|
|
50
|
+
// have.attr: atributo type do campo de usuário
|
|
51
|
+
cy.get('#usuario').should('have.attr', 'type', 'text');
|
|
52
|
+
|
|
53
|
+
// not.be.undefined: a propriedade type existe, lida via jQuery
|
|
54
|
+
cy.get('#senha').invoke('prop', 'type').should('not.be.undefined');
|
|
55
|
+
|
|
56
|
+
// be.undefined: o campo não tem placeholder
|
|
57
|
+
cy.get('#senha').invoke('attr', 'placeholder').should('be.undefined');
|
|
58
|
+
|
|
59
|
+
// be.oneOf: o tipo do campo é um dos valores permitidos
|
|
60
|
+
cy.get('#usuario').invoke('attr', 'type').should('be.oneOf', ['text', 'password']);
|
|
61
|
+
|
|
62
|
+
// be.empty: o campo começa vazio
|
|
63
|
+
cy.get('#usuario').invoke('val').should('be.empty');
|
|
64
|
+
|
|
65
|
+
// be.a: o valor do campo é uma string
|
|
66
|
+
cy.get('#usuario').invoke('val').should('be.a', 'string');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('foco nos campos', () => {
|
|
70
|
+
mount(<Login />);
|
|
71
|
+
|
|
72
|
+
// be.false: nenhum campo está com foco ao abrir a tela
|
|
73
|
+
cy.get('#usuario').then(($el) => $el.is(':focus')).should('be.false');
|
|
74
|
+
|
|
75
|
+
// have.focus: o campo recebe o foco ao ser clicado
|
|
76
|
+
cy.get('#usuario').focus().should('have.focus');
|
|
77
|
+
|
|
78
|
+
// be.true: confirma que o campo está com foco
|
|
79
|
+
cy.get('#usuario').then(($el) => $el.is(':focus')).should('be.true');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('digitação e limpeza', () => {
|
|
83
|
+
mount(<Login />);
|
|
84
|
+
|
|
85
|
+
// have.value: o valor digitado aparece no campo
|
|
86
|
+
cy.get('#usuario').type('admin').should('have.value', 'admin');
|
|
87
|
+
|
|
88
|
+
// not.have.value: depois de limpar, o valor não é mais o digitado
|
|
89
|
+
cy.get('#usuario').clear().should('not.have.value', 'admin');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('erro com usuário ou senha inválidos', () => {
|
|
93
|
+
mount(<Login />);
|
|
94
|
+
|
|
95
|
+
cy.get('#usuario').type('errado');
|
|
96
|
+
cy.get('#senha').type('000');
|
|
97
|
+
cy.contains('button', 'Entrar').click();
|
|
98
|
+
|
|
99
|
+
// include: o texto da mensagem contém a palavra-chave
|
|
100
|
+
cy.get('p').invoke('text').should('include', 'inválidos');
|
|
101
|
+
|
|
102
|
+
// not.include: a mensagem de sucesso não aparece
|
|
103
|
+
cy.get('p').invoke('text').should('not.include', 'sucesso');
|
|
104
|
+
|
|
105
|
+
// equal: texto exato da mensagem de erro
|
|
106
|
+
cy.get('p').invoke('text').should('equal', 'Usuário ou senha inválidos.');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('sucesso com admin e 123, enviado pela tecla Enter', () => {
|
|
110
|
+
mount(<Login />);
|
|
111
|
+
|
|
112
|
+
cy.get('#usuario').type('admin');
|
|
113
|
+
|
|
114
|
+
// {enter} envia o formulário sem clicar no botão
|
|
115
|
+
cy.get('#senha').type('123{enter}');
|
|
116
|
+
|
|
117
|
+
// not.be.empty: a mensagem de resultado foi preenchida
|
|
118
|
+
cy.get('p').invoke('text').should('not.be.empty');
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// ***********************************************
|
|
2
|
+
// This example commands.js shows you how to
|
|
3
|
+
// create various custom commands and overwrite
|
|
4
|
+
// existing commands.
|
|
5
|
+
//
|
|
6
|
+
// For more comprehensive examples of custom
|
|
7
|
+
// commands please read more here:
|
|
8
|
+
// https://on.cypress.io/custom-commands
|
|
9
|
+
// ***********************************************
|
|
10
|
+
//
|
|
11
|
+
//
|
|
12
|
+
// -- This is a parent command --
|
|
13
|
+
// Cypress.Commands.add('login', (email, password) => { ... })
|
|
14
|
+
//
|
|
15
|
+
//
|
|
16
|
+
// -- This is a child command --
|
|
17
|
+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
|
|
18
|
+
//
|
|
19
|
+
//
|
|
20
|
+
// -- This is a dual command --
|
|
21
|
+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
|
|
22
|
+
//
|
|
23
|
+
//
|
|
24
|
+
// -- This will overwrite an existing command --
|
|
25
|
+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
6
|
+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
|
7
|
+
<title>Components App</title>
|
|
8
|
+
<!-- Used by Next.js to inject CSS. -->
|
|
9
|
+
<div id="__next_css__DO_NOT_USE__"></div>
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<div data-cy-root></div>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// ***********************************************************
|
|
2
|
+
// This example support/component.js is processed and
|
|
3
|
+
// loaded automatically before your test files.
|
|
4
|
+
//
|
|
5
|
+
// This is a great place to put global configuration and
|
|
6
|
+
// behavior that modifies Cypress.
|
|
7
|
+
//
|
|
8
|
+
// You can change the location of this file or turn off
|
|
9
|
+
// automatically serving support files with the
|
|
10
|
+
// 'supportFile' configuration option.
|
|
11
|
+
//
|
|
12
|
+
// You can read more here:
|
|
13
|
+
// https://on.cypress.io/configuration
|
|
14
|
+
// ***********************************************************
|
|
15
|
+
|
|
16
|
+
// Import commands.js using ES2015 syntax:
|
|
17
|
+
import './commands'
|
|
18
|
+
|
|
19
|
+
import { mount } from 'cypress/react'
|
|
20
|
+
|
|
21
|
+
Cypress.Commands.add('mount', mount)
|
|
22
|
+
|
|
23
|
+
// Example use:
|
|
24
|
+
// cy.mount(<MyComponent />)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
|
|
5
|
+
export default function Login() {
|
|
6
|
+
const [usuario, setUsuario] = useState('');
|
|
7
|
+
const [senha, setSenha] = useState('');
|
|
8
|
+
const [mensagem, setMensagem] = useState('');
|
|
9
|
+
|
|
10
|
+
function handleLogin(event) {
|
|
11
|
+
event.preventDefault();
|
|
12
|
+
|
|
13
|
+
if (usuario === 'admin' && senha === '123') {
|
|
14
|
+
setMensagem('Login realizado com sucesso!');
|
|
15
|
+
} else {
|
|
16
|
+
setMensagem('Usuário ou senha inválidos.');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<form onSubmit={handleLogin}>
|
|
22
|
+
<h1>Login</h1>
|
|
23
|
+
|
|
24
|
+
<label htmlFor="usuario">Usuário</label>
|
|
25
|
+
|
|
26
|
+
<input
|
|
27
|
+
id="usuario"
|
|
28
|
+
type="text"
|
|
29
|
+
value={usuario}
|
|
30
|
+
onChange={(event) => setUsuario(event.target.value)}
|
|
31
|
+
/>
|
|
32
|
+
|
|
33
|
+
<label htmlFor="senha">Senha</label>
|
|
34
|
+
|
|
35
|
+
<input
|
|
36
|
+
id="senha"
|
|
37
|
+
type="password"
|
|
38
|
+
value={senha}
|
|
39
|
+
onChange={(event) => setSenha(event.target.value)}
|
|
40
|
+
/>
|
|
41
|
+
|
|
42
|
+
<button type="submit">Entrar</button>
|
|
43
|
+
|
|
44
|
+
{mensagem && <p>{mensagem}</p>}
|
|
45
|
+
</form>
|
|
46
|
+
);
|
|
47
|
+
}
|