create-nextify 0.1.9 → 0.1.11
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/dist/index.js +136 -75
- package/package.json +5 -2
package/dist/index.js
CHANGED
|
@@ -1,78 +1,139 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import http from 'node:http';
|
|
3
|
-
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
'
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const server = http.createServer((_req, res) => {
|
|
40
|
-
res.setHeader('content-type', 'text/plain; charset=utf-8');
|
|
41
|
-
res.end('Nextify production server ativo.');
|
|
42
|
-
});
|
|
43
|
-
server.listen(port, () => {
|
|
44
|
-
console.log(`Nextify start server em http://localhost:${port}`);
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
function runBuild() {
|
|
48
|
-
mkdirSync(join(process.cwd(), 'dist'), { recursive: true });
|
|
49
|
-
writeFileSync(join(process.cwd(), 'dist', 'route-manifest.json'), JSON.stringify({
|
|
50
|
-
generatedAt: new Date().toISOString(),
|
|
51
|
-
note: 'Manifesto de rotas gerado pelo CLI do Nextify.'
|
|
52
|
-
}, null, 2));
|
|
53
|
-
console.log('Build do Nextify concluído. Artefatos em dist/.');
|
|
54
|
-
}
|
|
55
|
-
const [, , command, ...args] = process.argv;
|
|
56
|
-
const portArg = Number(process.env.PORT ?? args[0] ?? 3000);
|
|
57
|
-
const port = Number.isFinite(portArg) ? portArg : 3000;
|
|
58
|
-
if (!command || command === 'create') {
|
|
59
|
-
createProject(args[0]);
|
|
60
|
-
}
|
|
61
|
-
else if (command === 'dev') {
|
|
62
|
-
runDevServer(port);
|
|
2
|
+
import http from 'node:http';
|
|
3
|
+
import { mkdirSync, writeFileSync, existsSync } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
function createProject(target = 'nextify-app') {
|
|
6
|
+
const root = join(process.cwd(), target);
|
|
7
|
+
if (existsSync(root)) {
|
|
8
|
+
console.error(`Erro: a pasta "${target}" já existe.`);
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
mkdirSync(join(root, 'pages', 'api'), { recursive: true });
|
|
12
|
+
writeFileSync(join(root, 'package.json'), JSON.stringify({
|
|
13
|
+
name: target,
|
|
14
|
+
private: true,
|
|
15
|
+
type: 'module',
|
|
16
|
+
scripts: {
|
|
17
|
+
dev: 'nextify dev',
|
|
18
|
+
build: 'nextify build',
|
|
19
|
+
start: 'nextify start',
|
|
20
|
+
},
|
|
21
|
+
dependencies: {
|
|
22
|
+
react: '^18.3.1',
|
|
23
|
+
'react-dom': '^18.3.1',
|
|
24
|
+
},
|
|
25
|
+
devDependencies: {
|
|
26
|
+
'create-nextify': 'latest',
|
|
27
|
+
'@types/react': '^18.3.1',
|
|
28
|
+
'@types/react-dom': '^18.3.1',
|
|
29
|
+
typescript: '^5.0.0',
|
|
30
|
+
},
|
|
31
|
+
}, null, 2));
|
|
32
|
+
writeFileSync(join(root, 'pages', 'index.tsx'), `export default function Home() {
|
|
33
|
+
return (
|
|
34
|
+
<main style={{ fontFamily: 'sans-serif', padding: '2rem' }}>
|
|
35
|
+
<h1>Bem-vindo ao Nextify.js 🚀</h1>
|
|
36
|
+
<p>Edite <code>pages/index.tsx</code> para começar.</p>
|
|
37
|
+
</main>
|
|
38
|
+
);
|
|
63
39
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
console.log('Uso:');
|
|
72
|
-
console.log(' create-nextify [nome-do-projeto]');
|
|
73
|
-
console.log(' nextify create [nome-do-projeto]');
|
|
74
|
-
console.log(' nextify dev [porta]');
|
|
75
|
-
console.log(' nextify build');
|
|
76
|
-
console.log(' nextify start [porta]');
|
|
77
|
-
process.exit(1);
|
|
40
|
+
`);
|
|
41
|
+
writeFileSync(join(root, 'pages', 'api', 'health.ts'), `export default async function handler() {
|
|
42
|
+
return new Response(JSON.stringify({ ok: true }), {
|
|
43
|
+
headers: { 'content-type': 'application/json' },
|
|
44
|
+
});
|
|
78
45
|
}
|
|
46
|
+
`);
|
|
47
|
+
writeFileSync(join(root, 'tsconfig.json'), JSON.stringify({
|
|
48
|
+
compilerOptions: {
|
|
49
|
+
target: 'ES2022',
|
|
50
|
+
module: 'ESNext',
|
|
51
|
+
moduleResolution: 'bundler',
|
|
52
|
+
jsx: 'react-jsx',
|
|
53
|
+
strict: true,
|
|
54
|
+
esModuleInterop: true,
|
|
55
|
+
skipLibCheck: true,
|
|
56
|
+
},
|
|
57
|
+
include: ['pages', 'src'],
|
|
58
|
+
}, null, 2));
|
|
59
|
+
console.log(`\n✔ Projeto criado em: ${root}`);
|
|
60
|
+
console.log('\nPróximos passos:\n');
|
|
61
|
+
console.log(` cd ${target}`);
|
|
62
|
+
console.log(' npm install');
|
|
63
|
+
console.log(' npm run dev\n');
|
|
64
|
+
}
|
|
65
|
+
async function runDevServer(port) {
|
|
66
|
+
// Tenta usar o @nextify/dev-server real (com Vite)
|
|
67
|
+
try {
|
|
68
|
+
const { startDevServer } = await import('@nextify/dev-server');
|
|
69
|
+
await startDevServer({ root: process.cwd(), port });
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// Fallback: servidor simples se o dev-server não estiver instalado
|
|
73
|
+
console.warn('[nextify] @nextify/dev-server não encontrado — usando servidor básico.\n' +
|
|
74
|
+
' Instale as dependências do projeto com: npm install\n');
|
|
75
|
+
const server = http.createServer((_req, res) => {
|
|
76
|
+
res.setHeader('content-type', 'text/plain; charset=utf-8');
|
|
77
|
+
res.end('Nextify dev server ativo (modo básico)');
|
|
78
|
+
});
|
|
79
|
+
server.listen(port, () => {
|
|
80
|
+
console.log(` ➜ Local: http://localhost:${port}`);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function runProdServer(port) {
|
|
85
|
+
const server = http.createServer((_req, res) => {
|
|
86
|
+
res.setHeader('content-type', 'text/plain; charset=utf-8');
|
|
87
|
+
res.end('Nextify production server ativo 🚀');
|
|
88
|
+
});
|
|
89
|
+
server.listen(port, () => {
|
|
90
|
+
console.log(`Nextify start server em http://localhost:${port}`);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function runBuild() {
|
|
94
|
+
mkdirSync(join(process.cwd(), 'dist'), { recursive: true });
|
|
95
|
+
writeFileSync(join(process.cwd(), 'dist', 'route-manifest.json'), JSON.stringify({
|
|
96
|
+
generatedAt: new Date().toISOString(),
|
|
97
|
+
note: 'Manifesto de rotas gerado pelo CLI do Nextify.',
|
|
98
|
+
}, null, 2));
|
|
99
|
+
console.log('✔ Build do Nextify concluído. Artefatos em dist/');
|
|
100
|
+
}
|
|
101
|
+
function showHelp() {
|
|
102
|
+
console.log(`
|
|
103
|
+
Uso:
|
|
104
|
+
|
|
105
|
+
create-nextify [nome-do-projeto]
|
|
106
|
+
|
|
107
|
+
ou
|
|
108
|
+
|
|
109
|
+
nextify create [nome-do-projeto]
|
|
110
|
+
nextify dev [porta]
|
|
111
|
+
nextify build
|
|
112
|
+
nextify start [porta]
|
|
113
|
+
`);
|
|
114
|
+
}
|
|
115
|
+
const args = process.argv.slice(2);
|
|
116
|
+
if (args.length === 0) {
|
|
117
|
+
showHelp();
|
|
118
|
+
process.exit(0);
|
|
119
|
+
}
|
|
120
|
+
const command = args[0];
|
|
121
|
+
const portArg = Number(process.env.PORT ?? args[1] ?? 3000);
|
|
122
|
+
const port = Number.isFinite(portArg) ? portArg : 3000;
|
|
123
|
+
switch (command) {
|
|
124
|
+
case 'create':
|
|
125
|
+
createProject(args[1]);
|
|
126
|
+
break;
|
|
127
|
+
case 'dev':
|
|
128
|
+
runDevServer(port);
|
|
129
|
+
break;
|
|
130
|
+
case 'build':
|
|
131
|
+
runBuild();
|
|
132
|
+
break;
|
|
133
|
+
case 'start':
|
|
134
|
+
runProdServer(port);
|
|
135
|
+
break;
|
|
136
|
+
default:
|
|
137
|
+
// suporta: npx create-nextify minha-app
|
|
138
|
+
createProject(command);
|
|
139
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-nextify",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "CLI para criar aplicações Nextify.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -22,5 +22,8 @@
|
|
|
22
22
|
"cli"
|
|
23
23
|
],
|
|
24
24
|
"author": "Ricardo Oliveira",
|
|
25
|
-
"license": "MIT"
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"typescript": "^5.9.3"
|
|
28
|
+
}
|
|
26
29
|
}
|