create-codeverse 0.0.1 → 0.1.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/LICENSE +21 -0
- package/ReadMe.MD +484 -457
- package/bin/cli.js +160 -94
- package/lib/apply/front.js +122 -122
- package/lib/apply/test.js +8 -2
- package/lib/desktop.js +61 -9
- package/lib/installDependencies.js +96 -37
- package/lib/openInEditor.js +14 -14
- package/lib/packageJson.js +33 -19
- package/lib/paths.js +4 -4
- package/lib/prompts.js +147 -68
- package/lib/runCommand.js +44 -40
- package/lib/templates.js +25 -7
- package/lib/validateProjectName.js +24 -24
- package/lib/versions.js +110 -50
- package/package.json +5 -2
- package/templates/codeskills.enc +0 -0
- package/templates/extras/test-componentes/ReadMe.MD +44 -0
- package/templates/front/ReadMe.MD +51 -36
- package/templates/front/biome.json +42 -42
- package/templates/front/next.config.mjs +11 -11
- package/templates/integracao/ReadMe.MD +41 -0
- package/templates/integracao/package.template.json +2 -1
- package/templates/test/ReadMe.MD +49 -0
- package/templates/versions.json +84 -81
package/bin/cli.js
CHANGED
|
@@ -1,102 +1,79 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { existsSync } from 'node:fs';
|
|
3
|
+
import { existsSync, rmSync } from 'node:fs';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
cancel,
|
|
8
|
-
confirm,
|
|
9
|
-
intro,
|
|
10
|
-
log,
|
|
11
|
-
multiselect,
|
|
12
|
-
note,
|
|
13
|
-
outro,
|
|
14
|
-
password,
|
|
15
|
-
select,
|
|
16
|
-
spinner,
|
|
17
|
-
text,
|
|
18
|
-
} from '@clack/prompts';
|
|
6
|
+
import { intro, log, multiselect, note, outro, password, select, text } from '@clack/prompts';
|
|
19
7
|
|
|
20
8
|
import { copyTemplate, writeSecretTemplate } from '../lib/copyTemplate.js';
|
|
21
|
-
import { getDesktopDir } from '../lib/desktop.js';
|
|
22
|
-
import {
|
|
23
|
-
buildInstallCommands,
|
|
24
|
-
formatCommand,
|
|
25
|
-
installDependencies,
|
|
26
|
-
} from '../lib/installDependencies.js';
|
|
9
|
+
import { getDesktopDir, startDesktopLookup } from '../lib/desktop.js';
|
|
10
|
+
import { buildInstallCommands, formatCommand, startInstall } from '../lib/installDependencies.js';
|
|
27
11
|
import { isInsideVsCode, openInEditor } from '../lib/openInEditor.js';
|
|
28
|
-
import { writePackageJson } from '../lib/packageJson.js';
|
|
12
|
+
import { setPackageInfo, writePackageJson } from '../lib/packageJson.js';
|
|
29
13
|
import {
|
|
30
14
|
alignedOptions,
|
|
15
|
+
cancellableSpinner,
|
|
31
16
|
configurePrompts,
|
|
32
17
|
countdown,
|
|
33
18
|
exitIfCancel,
|
|
19
|
+
onCancel,
|
|
20
|
+
readingPause,
|
|
34
21
|
replaceAnswerLine,
|
|
35
22
|
} from '../lib/prompts.js';
|
|
36
23
|
import { openSecretTemplate } from '../lib/secret.js';
|
|
37
24
|
import { templates } from '../lib/templates.js';
|
|
38
25
|
import { validateProjectName } from '../lib/validateProjectName.js';
|
|
39
|
-
import {
|
|
26
|
+
import { mergePackages, prepareVersions } from '../lib/versions.js';
|
|
40
27
|
|
|
41
28
|
const OPEN_DELAY_SECONDS = 5;
|
|
42
29
|
|
|
30
|
+
// Apaga a pasta do projeto no Ctrl+C. Logo depois de o npm ser encerrado, o Windows
|
|
31
|
+
// (ou o antivírus) ainda pode estar soltando os arquivos, então tenta várias vezes;
|
|
32
|
+
// se não der, avisa para apagar manualmente.
|
|
33
|
+
function removeProjectFolder(targetDir) {
|
|
34
|
+
try {
|
|
35
|
+
rmSync(targetDir, { recursive: true, force: true, maxRetries: 10, retryDelay: 300 });
|
|
36
|
+
} catch {
|
|
37
|
+
log.warn(`Não consegui apagar a pasta do projeto. Apague manualmente:\n${targetDir}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const READING_PAUSE_MS = 2000;
|
|
41
|
+
|
|
42
|
+
// true se o projeto tem cypress e o programa dessa versão ainda não está no PC.
|
|
43
|
+
// Aceita "X.Y.Z" e "^X.Y.Z" (o "latest" já consultado no registry vira "^X.Y.Z",
|
|
44
|
+
// que é a própria última versão, a mesma que o npm instala). Na dúvida ("latest"
|
|
45
|
+
// sem consulta, outro formato ou sem LOCALAPPDATA), considera que vai baixar.
|
|
46
|
+
function needsCypressDownload({ pinned, latest }) {
|
|
47
|
+
if (latest.devDependencies.includes('cypress')) return true;
|
|
48
|
+
const version = pinned.devDependencies.cypress?.replace(/^\^/, '');
|
|
49
|
+
if (!version) return false;
|
|
50
|
+
const cacheRoot = process.env.LOCALAPPDATA;
|
|
51
|
+
if (!cacheRoot || !/^\d+\.\d+\.\d+$/.test(version)) return true;
|
|
52
|
+
return !existsSync(join(cacheRoot, 'Cypress', 'Cache', version));
|
|
53
|
+
}
|
|
54
|
+
|
|
43
55
|
async function main() {
|
|
56
|
+
startDesktopLookup();
|
|
44
57
|
console.clear();
|
|
45
58
|
configurePrompts();
|
|
46
59
|
intro('Bem-vindo(a) ao CodeVerse ⚡');
|
|
47
|
-
note(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
await text({
|
|
54
|
-
message: 'Qual é o seu nome, DEV? 👧',
|
|
55
|
-
placeholder: 'Buguilino Undefined NotNull',
|
|
56
|
-
validate: (raw) => {
|
|
57
|
-
if (!String(raw ?? '').trim()) return 'Digite o seu nome, fera ...';
|
|
58
|
-
},
|
|
59
|
-
}),
|
|
60
|
-
).trim();
|
|
60
|
+
note('Seu ambiente de desenvolvimento começa aqui ... 💫', 'O que vamos construir hoje? 🙌');
|
|
61
|
+
// 1 s para o aluno ler as boas-vindas antes do menu (teclas nesse tempo são ignoradas).
|
|
62
|
+
// A consulta da Área de Trabalho (PowerShell, começou no início do CLI) termina
|
|
63
|
+
// ANTES do primeiro menu: um processo encerrando com um menu aberto pode mexer no
|
|
64
|
+
// modo do teclado do terminal e travar o menu. Normalmente já terminou na pausa.
|
|
65
|
+
const [baseDir] = await Promise.all([getDesktopDir(), readingPause(READING_PAUSE_MS)]);
|
|
61
66
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (existsSync(join(baseDir, result.value))) {
|
|
73
|
-
return `Já existe uma pasta com esse nome ${placeLabel}. Escolha outro nome.`;
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
}),
|
|
77
|
-
).trim();
|
|
78
|
-
|
|
79
|
-
const targetDir = join(baseDir, projectName);
|
|
80
|
-
|
|
81
|
-
// Sem Área de Trabalho, o projeto vai para a pasta onde o comando rodou, mas
|
|
82
|
-
// só depois de o aluno confirmar (Enter = S). Com "n", nada é criado.
|
|
83
|
-
if (!isDesktop) {
|
|
84
|
-
note(
|
|
85
|
-
`O projeto será salvo na pasta atual do terminal:\n \u001b[32m${targetDir}\u001b[0m`,
|
|
86
|
-
'Não encontrei a Área de Trabalho 😢',
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
const keepGoing = exitIfCancel(
|
|
90
|
-
await confirm({
|
|
91
|
-
message: 'Continuar e salvar aqui?',
|
|
92
|
-
initialValue: true,
|
|
93
|
-
}),
|
|
94
|
-
);
|
|
95
|
-
if (!keepGoing) {
|
|
96
|
-
cancel('Operação cancelada. Nada foi criado. 😢');
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
67
|
+
// Assim que cada pergunta do menu é respondida, a consulta das versões
|
|
68
|
+
// "latest" daqueles blocos começa em segundo plano, enquanto o aluno responde
|
|
69
|
+
// as próximas. Os resultados são juntados na hora de criar o projeto; um erro
|
|
70
|
+
// aqui só aparece lá (o `.catch` vazio evita o aviso de erro não tratado).
|
|
71
|
+
const versionLookups = [];
|
|
72
|
+
const lookupVersions = (blockPaths) => {
|
|
73
|
+
const lookup = prepareVersions(blockPaths);
|
|
74
|
+
lookup.catch(() => {});
|
|
75
|
+
versionLookups.push(lookup);
|
|
76
|
+
};
|
|
100
77
|
|
|
101
78
|
// Ordem alfabética, exceto os templates com `last: true`, que ficam sempre no fim.
|
|
102
79
|
const sortedTemplates = [...templates].sort(
|
|
@@ -119,7 +96,10 @@ async function main() {
|
|
|
119
96
|
template = templates.find((item) => item.id === templateId);
|
|
120
97
|
|
|
121
98
|
if (!template.ready) {
|
|
122
|
-
note(
|
|
99
|
+
note(
|
|
100
|
+
'Em breve teremos muito mais novidades para vocês!!!',
|
|
101
|
+
'Estamos trabalhando nisso 🚧',
|
|
102
|
+
);
|
|
123
103
|
outro('Até a próxima, DEV! 🚀');
|
|
124
104
|
return;
|
|
125
105
|
}
|
|
@@ -135,7 +115,7 @@ async function main() {
|
|
|
135
115
|
}),
|
|
136
116
|
);
|
|
137
117
|
|
|
138
|
-
const checking =
|
|
118
|
+
const checking = cancellableSpinner();
|
|
139
119
|
checking.start('Verificando o código...');
|
|
140
120
|
try {
|
|
141
121
|
secretFiles = await openSecretTemplate(template.id, code);
|
|
@@ -151,10 +131,14 @@ async function main() {
|
|
|
151
131
|
checking.error('Código inválido. Escolha o template de novo. 😢');
|
|
152
132
|
}
|
|
153
133
|
|
|
134
|
+
// Sem `choice`, os blocos já são conhecidos aqui: `versions` do template (ex.:
|
|
135
|
+
// CodeSkills = "front.base" + "codeskills.base") ou "<id>.base". Com `choice`,
|
|
136
|
+
// os blocos vêm do sub-template escolhido.
|
|
137
|
+
if (!template.choice) lookupVersions(template.versions ?? [`${template.id}.base`]);
|
|
138
|
+
|
|
154
139
|
// Templates com `choice` (ex.: Test) escolhem um sub-template de seleção única,
|
|
155
140
|
// com pasta (`dir`), extras e `apply` próprios. Os demais usam multiselect de extras.
|
|
156
141
|
let dir = template.id;
|
|
157
|
-
let versionPaths = null;
|
|
158
142
|
let chosenOptions = [];
|
|
159
143
|
let apply = template.apply;
|
|
160
144
|
if (template.choice) {
|
|
@@ -178,8 +162,8 @@ async function main() {
|
|
|
178
162
|
}
|
|
179
163
|
|
|
180
164
|
dir = choice.dir;
|
|
181
|
-
versionPaths = choice.versions;
|
|
182
165
|
apply = choice.apply;
|
|
166
|
+
lookupVersions(choice.versions);
|
|
183
167
|
} else if (template.options?.length) {
|
|
184
168
|
const sortedOptions = [...template.options].sort((a, b) =>
|
|
185
169
|
a.label.localeCompare(b.label, 'pt-BR'),
|
|
@@ -206,47 +190,109 @@ async function main() {
|
|
|
206
190
|
chosenLabels.map((label) => label.trimEnd()).join(', '),
|
|
207
191
|
chosenLabels.join(', '),
|
|
208
192
|
);
|
|
193
|
+
// Cada extra usa o próprio `versions` (ex.: Ant Design = "front.antd" +
|
|
194
|
+
// "front.antdRegistry") ou, sem ele, o bloco "<template>.<extra>".
|
|
195
|
+
lookupVersions(
|
|
196
|
+
chosenOptions.flatMap(
|
|
197
|
+
(id) =>
|
|
198
|
+
template.options.find((item) => item.id === id).versions ?? [
|
|
199
|
+
`${template.id}.${id}`,
|
|
200
|
+
],
|
|
201
|
+
),
|
|
202
|
+
);
|
|
209
203
|
}
|
|
210
204
|
}
|
|
211
205
|
|
|
212
|
-
|
|
206
|
+
// O projeto é sempre criado na Área de Trabalho do Windows (`baseDir`, a real,
|
|
207
|
+
// inclusive no OneDrive), descoberta antes do primeiro menu.
|
|
208
|
+
|
|
209
|
+
const projectName = exitIfCancel(
|
|
210
|
+
await text({
|
|
211
|
+
message: 'Qual é o nome do seu projeto/app? 💻',
|
|
212
|
+
placeholder: 'num-crasha-por-favor',
|
|
213
|
+
validate: (raw) => {
|
|
214
|
+
const result = validateProjectName(raw);
|
|
215
|
+
if (!result.valid) return result.message;
|
|
216
|
+
if (existsSync(join(baseDir, result.value))) {
|
|
217
|
+
return 'Já existe uma pasta com esse nome na Área de Trabalho. Escolha outro nome.';
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
}),
|
|
221
|
+
).trim();
|
|
222
|
+
|
|
223
|
+
const targetDir = join(baseDir, projectName);
|
|
224
|
+
|
|
225
|
+
// Com o nome do projeto, o projeto já é criado e o `npm install` começa em
|
|
226
|
+
// segundo plano, enquanto o aluno responde as últimas perguntas.
|
|
227
|
+
// Ctrl+C daqui até o fim da instalação (pergunta ou spinner): para o npm e apaga
|
|
228
|
+
// a pasta, para nada sobrar no disco. A pasta não existia (o nome foi validado),
|
|
229
|
+
// então só é apagado o que o próprio CLI criou.
|
|
230
|
+
let install = null;
|
|
231
|
+
const stopCleanup = onCancel(() => {
|
|
232
|
+
install?.cancel();
|
|
233
|
+
removeProjectFolder(targetDir);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
const progress = cancellableSpinner();
|
|
213
237
|
progress.start('Criando o seu projeto...');
|
|
214
238
|
|
|
215
239
|
let commands;
|
|
240
|
+
let packages;
|
|
216
241
|
try {
|
|
217
242
|
// Template secreto: os arquivos vêm do .enc já aberto; as versões, como nos
|
|
218
|
-
// demais, vêm do versions.json
|
|
243
|
+
// demais, vêm do versions.json.
|
|
219
244
|
if (secretFiles) await writeSecretTemplate(secretFiles, targetDir);
|
|
220
245
|
else await copyTemplate(dir, targetDir);
|
|
221
246
|
|
|
222
|
-
//
|
|
223
|
-
//
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
...chosenOptions.map((id) => `${template.id}.${id}`),
|
|
227
|
-
];
|
|
228
|
-
const packages = await resolvePackages(blockPaths);
|
|
247
|
+
// Junta as consultas feitas durante o menu (base + extras, ou o sub-template).
|
|
248
|
+
// Com as versões "latest" já consultadas, o package.json sai completo e roda
|
|
249
|
+
// um único `npm install`. Sem acesso ao registry, segue com os `@latest`.
|
|
250
|
+
packages = mergePackages(await Promise.all(versionLookups));
|
|
229
251
|
commands = buildInstallCommands(packages);
|
|
230
|
-
await writePackageJson(targetDir, { projectName
|
|
252
|
+
await writePackageJson(targetDir, { projectName }, packages.pinned);
|
|
231
253
|
await apply?.(targetDir, chosenOptions);
|
|
232
254
|
progress.stop('Projeto criado! 👍');
|
|
233
255
|
} catch (err) {
|
|
256
|
+
stopCleanup();
|
|
234
257
|
progress.error(err.message);
|
|
235
258
|
process.exitCode = 1;
|
|
236
259
|
return;
|
|
237
260
|
}
|
|
238
261
|
|
|
262
|
+
install = startInstall(targetDir, commands);
|
|
263
|
+
|
|
264
|
+
// Opcional: em branco, o package.json fica com a descrição do template.
|
|
265
|
+
const description = String(
|
|
266
|
+
exitIfCancel(
|
|
267
|
+
await text({
|
|
268
|
+
message: 'Qual é a descrição do seu projeto/app? (opcional) 📝',
|
|
269
|
+
placeholder: 'Meu app vai mudar o mundo',
|
|
270
|
+
}),
|
|
271
|
+
) ?? '',
|
|
272
|
+
).trim();
|
|
273
|
+
|
|
274
|
+
const devName = exitIfCancel(
|
|
275
|
+
await text({
|
|
276
|
+
message: 'Qual é o seu nome, DEV? 👧',
|
|
277
|
+
placeholder: 'Buguilino Undefined NotNull',
|
|
278
|
+
validate: (raw) => {
|
|
279
|
+
if (!String(raw ?? '').trim()) return 'Digite o seu nome, fera ...';
|
|
280
|
+
},
|
|
281
|
+
}),
|
|
282
|
+
).trim();
|
|
283
|
+
|
|
284
|
+
// Espera o que faltar da instalação (se já terminou, fecha na hora).
|
|
239
285
|
// Se a instalação falhar, a pasta é mantida e `pending` guarda o que faltou.
|
|
240
|
-
// O cypress baixa o próprio programa (~200 MB) ao ser instalado, então avisa o aluno
|
|
286
|
+
// O cypress baixa o próprio programa (~200 MB) ao ser instalado, então avisa o aluno,
|
|
287
|
+
// a não ser que essa versão já esteja no cache do PC (%LOCALAPPDATA%\Cypress\Cache\<versão>).
|
|
241
288
|
let pending = [];
|
|
242
|
-
const hasCypress = commands.some((args) => args.some((arg) => arg.startsWith('cypress@')));
|
|
243
289
|
progress.start(
|
|
244
|
-
|
|
290
|
+
needsCypressDownload(packages)
|
|
245
291
|
? 'Baixando o Cypress, pode demorar alguns minutos ⏳ '
|
|
246
292
|
: 'Instalando dependências ⏳ ',
|
|
247
293
|
);
|
|
248
294
|
try {
|
|
249
|
-
await
|
|
295
|
+
await install.done;
|
|
250
296
|
progress.stop('Dependências instaladas!');
|
|
251
297
|
} catch (err) {
|
|
252
298
|
pending = err.pending ?? commands;
|
|
@@ -254,12 +300,23 @@ async function main() {
|
|
|
254
300
|
log.error(err.message);
|
|
255
301
|
}
|
|
256
302
|
|
|
303
|
+
// Instalação encerrada (com ou sem falha): a partir daqui o projeto fica, mesmo
|
|
304
|
+
// com Ctrl+C (ex.: na contagem para abrir o VS Code).
|
|
305
|
+
stopCleanup();
|
|
306
|
+
|
|
307
|
+
// Descrição e autor entram depois do install, para não disputar o package.json com o npm.
|
|
308
|
+
try {
|
|
309
|
+
await setPackageInfo(targetDir, { description, devName });
|
|
310
|
+
} catch (err) {
|
|
311
|
+
log.warn(`Não consegui gravar a descrição e o autor no package.json: ${err.message}`);
|
|
312
|
+
}
|
|
313
|
+
|
|
257
314
|
if (pending.length > 0) {
|
|
258
315
|
const manualSteps = [`cd "${targetDir}"`, ...pending.map(formatCommand)].join('\n');
|
|
259
316
|
note(manualSteps, 'Falta instalar as dependências. Rode no terminal:');
|
|
260
317
|
process.exitCode = 1;
|
|
261
318
|
} else {
|
|
262
|
-
note(
|
|
319
|
+
note("Para rodar, abra o terminal do VS Code (Ctrl + ') e execute:\nnpm run dev");
|
|
263
320
|
}
|
|
264
321
|
|
|
265
322
|
// A abertura do VS Code é o último passo, depois de uma contagem que dá tempo
|
|
@@ -277,4 +334,13 @@ async function main() {
|
|
|
277
334
|
log.warn(`VS Code não encontrado. Abra manualmente a pasta do projeto: ${targetDir}`);
|
|
278
335
|
}
|
|
279
336
|
|
|
280
|
-
|
|
337
|
+
// Encerra assim que o fluxo termina (inclusive no "em breve" e nos erros). No
|
|
338
|
+
// Windows, depois dos menus o terminal fica esperando uma linha do teclado e o
|
|
339
|
+
// processo só terminaria com um Enter. O código de saída (process.exitCode) é mantido.
|
|
340
|
+
// Um erro inesperado ainda aparece na tela e sai com código 1.
|
|
341
|
+
main()
|
|
342
|
+
.catch((err) => {
|
|
343
|
+
console.error(err);
|
|
344
|
+
process.exitCode = 1;
|
|
345
|
+
})
|
|
346
|
+
.finally(() => process.exit());
|
package/lib/apply/front.js
CHANGED
|
@@ -1,122 +1,122 @@
|
|
|
1
|
-
import { readFile, rm, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
|
|
4
|
-
const POSTCSS_CONFIG = `const config = {
|
|
5
|
-
plugins: {
|
|
6
|
-
'@tailwindcss/postcss': {},
|
|
7
|
-
},
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export default config;
|
|
11
|
-
`;
|
|
12
|
-
|
|
13
|
-
// Com Tailwind, o globals.css fica só com o import (o preflight do Tailwind
|
|
14
|
-
// substitui o reset que existia antes).
|
|
15
|
-
const TAILWIND_GLOBALS = '@import "tailwindcss";\n';
|
|
16
|
-
|
|
17
|
-
// Mesma tela do page.jsx original, com classes do Tailwind no lugar do
|
|
18
|
-
// page.module.css (que é removido nesse caso).
|
|
19
|
-
const TAILWIND_PAGE = `export default function Home() {
|
|
20
|
-
return (
|
|
21
|
-
<main className="flex min-h-screen w-full flex-col items-center justify-start bg-[image:linear-gradient(to_bottom,rgba(10,15,30,0.35),rgba(10,15,30,0.5)),url('https://minio.codeverse.dev.br/mural/1785759396834-148tgv.jpeg')] bg-cover bg-center bg-no-repeat px-6 py-8 text-center font-sans">
|
|
22
|
-
<div className="mt-60 flex flex-col items-center">
|
|
23
|
-
<h1 className="m-0 bg-[linear-gradient(135deg,#a5b4fc_0%,#38bdf8_100%)] bg-clip-text text-[clamp(2.5rem,6vw,4.5rem)] font-extrabold tracking-[-0.02em] text-transparent">
|
|
24
|
-
Codeverse
|
|
25
|
-
</h1>
|
|
26
|
-
<p className="mt-1 text-[clamp(1rem,2.5vw,1.4rem)] font-normal tracking-[0.15em] text-slate-300 uppercase">
|
|
27
|
-
Explore. Aprenda. Colabore.
|
|
28
|
-
</p>
|
|
29
|
-
|
|
30
|
-
<a
|
|
31
|
-
href="https://codeverse.dev.br"
|
|
32
|
-
target="_blank"
|
|
33
|
-
rel="noopener noreferrer"
|
|
34
|
-
className="mt-4 inline-flex items-center gap-[0.6rem] rounded-full bg-[linear-gradient(135deg,#a5b4fc_0%,#38bdf8_100%)] px-9 py-[0.85rem] font-bold text-[#0a0f1e] no-underline transition-[transform,box-shadow] duration-200 ease-in-out hover:-translate-y-0.5 hover:shadow-[0_10px_30px_rgba(56,189,248,0.35)]">
|
|
35
|
-
<svg
|
|
36
|
-
className="h-[25px] w-[25px] animate-[spin_6s_linear_infinite]"
|
|
37
|
-
viewBox="-11.5 -10.23174 23 20.46348"
|
|
38
|
-
width="25"
|
|
39
|
-
height="25"
|
|
40
|
-
aria-hidden="true">
|
|
41
|
-
<circle r="2.05" fill="currentColor" />
|
|
42
|
-
<g stroke="currentColor" strokeWidth="1" fill="none">
|
|
43
|
-
<ellipse rx="11" ry="4.2" />
|
|
44
|
-
<ellipse rx="11" ry="4.2" transform="rotate(60)" />
|
|
45
|
-
<ellipse rx="11" ry="4.2" transform="rotate(120)" />
|
|
46
|
-
</g>
|
|
47
|
-
</svg>
|
|
48
|
-
Ver material tutorial
|
|
49
|
-
</a>
|
|
50
|
-
|
|
51
|
-
<p className="mt-4 text-[0.85rem] tracking-[0.1em] text-slate-400 uppercase">
|
|
52
|
-
Scaffolding oficial - Codeverse
|
|
53
|
-
</p>
|
|
54
|
-
</div>
|
|
55
|
-
|
|
56
|
-
<footer className="text-[0.85rem] text-slate-400/60">
|
|
57
|
-
<p>Pouco pra quem vê..., muito pra quem aprende.</p>
|
|
58
|
-
</footer>
|
|
59
|
-
</main>
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
`;
|
|
63
|
-
|
|
64
|
-
const GLOBALS_IMPORT_RE = /import '\.\/globals\.css';\r?\n/;
|
|
65
|
-
const BODY_MARKER = '<body>{children}</body>';
|
|
66
|
-
|
|
67
|
-
// CSS modules que o Tailwind substitui. Só são removidos com Tailwind; sem ele,
|
|
68
|
-
// ficam todos no projeto.
|
|
69
|
-
const MODULE_CSS_TO_REMOVE = [
|
|
70
|
-
['src', 'app', 'page.module.css'],
|
|
71
|
-
['src', 'app', 'nome-da-rota', 'nome-da-rota.module.css'],
|
|
72
|
-
['src', 'components', 'Nome-do-componente.module.css'],
|
|
73
|
-
];
|
|
74
|
-
|
|
75
|
-
async function applyTailwind(projectDir) {
|
|
76
|
-
await writeFile(join(projectDir, 'postcss.config.mjs'), POSTCSS_CONFIG, 'utf8');
|
|
77
|
-
|
|
78
|
-
await writeFile(join(projectDir, 'src', 'app', 'globals.css'), TAILWIND_GLOBALS, 'utf8');
|
|
79
|
-
await writeFile(join(projectDir, 'src', 'app', 'page.jsx'), TAILWIND_PAGE, 'utf8');
|
|
80
|
-
|
|
81
|
-
for (const parts of MODULE_CSS_TO_REMOVE) {
|
|
82
|
-
await rm(join(projectDir, ...parts), { force: true });
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async function applyLayoutIntegrations(projectDir, { antd, toast, tailwind }) {
|
|
87
|
-
if (!antd && !toast && !tailwind) return;
|
|
88
|
-
|
|
89
|
-
const layoutPath = join(projectDir, 'src', 'app', 'layout.js');
|
|
90
|
-
let content = await readFile(layoutPath, 'utf8');
|
|
91
|
-
|
|
92
|
-
const imports = [];
|
|
93
|
-
if (antd) imports.push("import { AntdRegistry } from '@ant-design/nextjs-registry';");
|
|
94
|
-
if (toast) imports.push("import { Toaster } from 'react-hot-toast';");
|
|
95
|
-
if (imports.length > 0) {
|
|
96
|
-
content = content.replace(GLOBALS_IMPORT_RE, (match) => {
|
|
97
|
-
const eol = match.endsWith('\r\n') ? '\r\n' : '\n';
|
|
98
|
-
return `${match}${imports.join(eol)}${eol}`;
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const children = antd ? '<AntdRegistry>{children}</AntdRegistry>' : '{children}';
|
|
103
|
-
const toaster = toast ? '\n <Toaster />' : '';
|
|
104
|
-
const body = `\n ${children}${toaster}\n `;
|
|
105
|
-
|
|
106
|
-
const bodyOpenTag = tailwind ? '<body className="min-h-screen antialiased">' : '<body>';
|
|
107
|
-
content = content.replace(BODY_MARKER, `${bodyOpenTag}${body}</body>`);
|
|
108
|
-
|
|
109
|
-
await writeFile(layoutPath, content, 'utf8');
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Alterações no código do template FrontEnd conforme os extras marcados.
|
|
113
|
-
export async function applyFront(projectDir, optionIds) {
|
|
114
|
-
const selected = {
|
|
115
|
-
antd: optionIds.includes('antd'),
|
|
116
|
-
toast: optionIds.includes('toast'),
|
|
117
|
-
tailwind: optionIds.includes('tailwind'),
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
if (selected.tailwind) await applyTailwind(projectDir);
|
|
121
|
-
await applyLayoutIntegrations(projectDir, selected);
|
|
122
|
-
}
|
|
1
|
+
import { readFile, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
const POSTCSS_CONFIG = `const config = {
|
|
5
|
+
plugins: {
|
|
6
|
+
'@tailwindcss/postcss': {},
|
|
7
|
+
},
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default config;
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
// Com Tailwind, o globals.css fica só com o import (o preflight do Tailwind
|
|
14
|
+
// substitui o reset que existia antes).
|
|
15
|
+
const TAILWIND_GLOBALS = '@import "tailwindcss";\n';
|
|
16
|
+
|
|
17
|
+
// Mesma tela do page.jsx original, com classes do Tailwind no lugar do
|
|
18
|
+
// page.module.css (que é removido nesse caso).
|
|
19
|
+
const TAILWIND_PAGE = `export default function Home() {
|
|
20
|
+
return (
|
|
21
|
+
<main className="flex min-h-screen w-full flex-col items-center justify-start bg-[image:linear-gradient(to_bottom,rgba(10,15,30,0.35),rgba(10,15,30,0.5)),url('https://minio.codeverse.dev.br/mural/1785759396834-148tgv.jpeg')] bg-cover bg-center bg-no-repeat px-6 py-8 text-center font-sans">
|
|
22
|
+
<div className="mt-60 flex flex-col items-center">
|
|
23
|
+
<h1 className="m-0 bg-[linear-gradient(135deg,#a5b4fc_0%,#38bdf8_100%)] bg-clip-text text-[clamp(2.5rem,6vw,4.5rem)] font-extrabold tracking-[-0.02em] text-transparent">
|
|
24
|
+
Codeverse
|
|
25
|
+
</h1>
|
|
26
|
+
<p className="mt-1 text-[clamp(1rem,2.5vw,1.4rem)] font-normal tracking-[0.15em] text-slate-300 uppercase">
|
|
27
|
+
Explore. Aprenda. Colabore.
|
|
28
|
+
</p>
|
|
29
|
+
|
|
30
|
+
<a
|
|
31
|
+
href="https://codeverse.dev.br"
|
|
32
|
+
target="_blank"
|
|
33
|
+
rel="noopener noreferrer"
|
|
34
|
+
className="mt-4 inline-flex items-center gap-[0.6rem] rounded-full bg-[linear-gradient(135deg,#a5b4fc_0%,#38bdf8_100%)] px-9 py-[0.85rem] font-bold text-[#0a0f1e] no-underline transition-[transform,box-shadow] duration-200 ease-in-out hover:-translate-y-0.5 hover:shadow-[0_10px_30px_rgba(56,189,248,0.35)]">
|
|
35
|
+
<svg
|
|
36
|
+
className="h-[25px] w-[25px] animate-[spin_6s_linear_infinite]"
|
|
37
|
+
viewBox="-11.5 -10.23174 23 20.46348"
|
|
38
|
+
width="25"
|
|
39
|
+
height="25"
|
|
40
|
+
aria-hidden="true">
|
|
41
|
+
<circle r="2.05" fill="currentColor" />
|
|
42
|
+
<g stroke="currentColor" strokeWidth="1" fill="none">
|
|
43
|
+
<ellipse rx="11" ry="4.2" />
|
|
44
|
+
<ellipse rx="11" ry="4.2" transform="rotate(60)" />
|
|
45
|
+
<ellipse rx="11" ry="4.2" transform="rotate(120)" />
|
|
46
|
+
</g>
|
|
47
|
+
</svg>
|
|
48
|
+
Ver material tutorial
|
|
49
|
+
</a>
|
|
50
|
+
|
|
51
|
+
<p className="mt-4 text-[0.85rem] tracking-[0.1em] text-slate-400 uppercase">
|
|
52
|
+
Scaffolding oficial - Codeverse
|
|
53
|
+
</p>
|
|
54
|
+
</div>
|
|
55
|
+
|
|
56
|
+
<footer className="text-[0.85rem] text-slate-400/60">
|
|
57
|
+
<p>Pouco pra quem vê..., muito pra quem aprende.</p>
|
|
58
|
+
</footer>
|
|
59
|
+
</main>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
`;
|
|
63
|
+
|
|
64
|
+
const GLOBALS_IMPORT_RE = /import '\.\/globals\.css';\r?\n/;
|
|
65
|
+
const BODY_MARKER = '<body>{children}</body>';
|
|
66
|
+
|
|
67
|
+
// CSS modules que o Tailwind substitui. Só são removidos com Tailwind; sem ele,
|
|
68
|
+
// ficam todos no projeto.
|
|
69
|
+
const MODULE_CSS_TO_REMOVE = [
|
|
70
|
+
['src', 'app', 'page.module.css'],
|
|
71
|
+
['src', 'app', 'nome-da-rota', 'nome-da-rota.module.css'],
|
|
72
|
+
['src', 'components', 'Nome-do-componente.module.css'],
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
async function applyTailwind(projectDir) {
|
|
76
|
+
await writeFile(join(projectDir, 'postcss.config.mjs'), POSTCSS_CONFIG, 'utf8');
|
|
77
|
+
|
|
78
|
+
await writeFile(join(projectDir, 'src', 'app', 'globals.css'), TAILWIND_GLOBALS, 'utf8');
|
|
79
|
+
await writeFile(join(projectDir, 'src', 'app', 'page.jsx'), TAILWIND_PAGE, 'utf8');
|
|
80
|
+
|
|
81
|
+
for (const parts of MODULE_CSS_TO_REMOVE) {
|
|
82
|
+
await rm(join(projectDir, ...parts), { force: true });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function applyLayoutIntegrations(projectDir, { antd, toast, tailwind }) {
|
|
87
|
+
if (!antd && !toast && !tailwind) return;
|
|
88
|
+
|
|
89
|
+
const layoutPath = join(projectDir, 'src', 'app', 'layout.js');
|
|
90
|
+
let content = await readFile(layoutPath, 'utf8');
|
|
91
|
+
|
|
92
|
+
const imports = [];
|
|
93
|
+
if (antd) imports.push("import { AntdRegistry } from '@ant-design/nextjs-registry';");
|
|
94
|
+
if (toast) imports.push("import { Toaster } from 'react-hot-toast';");
|
|
95
|
+
if (imports.length > 0) {
|
|
96
|
+
content = content.replace(GLOBALS_IMPORT_RE, (match) => {
|
|
97
|
+
const eol = match.endsWith('\r\n') ? '\r\n' : '\n';
|
|
98
|
+
return `${match}${imports.join(eol)}${eol}`;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const children = antd ? '<AntdRegistry>{children}</AntdRegistry>' : '{children}';
|
|
103
|
+
const toaster = toast ? '\n <Toaster />' : '';
|
|
104
|
+
const body = `\n ${children}${toaster}\n `;
|
|
105
|
+
|
|
106
|
+
const bodyOpenTag = tailwind ? '<body className="min-h-screen antialiased">' : '<body>';
|
|
107
|
+
content = content.replace(BODY_MARKER, `${bodyOpenTag}${body}</body>`);
|
|
108
|
+
|
|
109
|
+
await writeFile(layoutPath, content, 'utf8');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Alterações no código do template FrontEnd conforme os extras marcados.
|
|
113
|
+
export async function applyFront(projectDir, optionIds) {
|
|
114
|
+
const selected = {
|
|
115
|
+
antd: optionIds.includes('antd'),
|
|
116
|
+
toast: optionIds.includes('toast'),
|
|
117
|
+
tailwind: optionIds.includes('tailwind'),
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
if (selected.tailwind) await applyTailwind(projectDir);
|
|
121
|
+
await applyLayoutIntegrations(projectDir, selected);
|
|
122
|
+
}
|
package/lib/apply/test.js
CHANGED
|
@@ -21,6 +21,11 @@ const COMPONENTES_KEYWORDS = [
|
|
|
21
21
|
'codeverse',
|
|
22
22
|
];
|
|
23
23
|
|
|
24
|
+
// Mesmo script do templates/integracao/package.template.json. O `rem` é o
|
|
25
|
+
// comentário do cmd: roda sem mostrar nada (o package.json não aceita comentários).
|
|
26
|
+
const CYPRESS_CLEAN_SCRIPT =
|
|
27
|
+
'cls && npx cypress cache prune && rem Apaga do PC as versões antigas do programa Cypress, cerca de 200 MB cada, e mantém só a usada neste projeto';
|
|
28
|
+
|
|
24
29
|
const CYPRESS_GITIGNORE = `
|
|
25
30
|
# Gerados pelo Cypress ao rodar os testes
|
|
26
31
|
cypress/screenshots/
|
|
@@ -50,7 +55,8 @@ const COMPONENTES_TO_REMOVE = [
|
|
|
50
55
|
|
|
51
56
|
// Opção "Component Testing": parte do template FrontEnd e acrescenta o Cypress.
|
|
52
57
|
// O page.jsx passa a mostrar só o componente Login (teste em cypress/component/Login.cy.jsx).
|
|
53
|
-
// O package.json já gerado ganha
|
|
58
|
+
// O package.json já gerado ganha os scripts de teste e de limpeza do cache do Cypress
|
|
59
|
+
// e a descrição própria (se o aluno digitar uma, ela substitui esta depois).
|
|
54
60
|
export async function applyTestComponentes(projectDir) {
|
|
55
61
|
await cp(COMPONENTES_DIR, projectDir, { recursive: true });
|
|
56
62
|
for (const parts of COMPONENTES_TO_REMOVE) {
|
|
@@ -62,6 +68,6 @@ export async function applyTestComponentes(projectDir) {
|
|
|
62
68
|
const pkg = JSON.parse(await readFile(pkgPath, 'utf8'));
|
|
63
69
|
pkg.description = COMPONENTES_DESCRIPTION;
|
|
64
70
|
pkg.keywords = COMPONENTES_KEYWORDS;
|
|
65
|
-
pkg.scripts = { ...pkg.scripts, test: 'cls && cypress open' };
|
|
71
|
+
pkg.scripts = { ...pkg.scripts, test: 'cls && cypress open', clean: CYPRESS_CLEAN_SCRIPT };
|
|
66
72
|
await writeFile(pkgPath, `${JSON.stringify(pkg, null, 4)}\n`, 'utf8');
|
|
67
73
|
}
|