@ffstack/turnos 0.2.0 → 0.3.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/bin/turnos.js +55 -61
- package/package.json +4 -1
- package/src/utils/cli-utils.js +19 -0
- package/src/utils/env-templates.js +16 -0
package/bin/turnos.js
CHANGED
|
@@ -1,71 +1,65 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import inquirer from 'inquirer';
|
|
3
4
|
import { generateFiles, resolveTargetDir } from '../src/generator.js';
|
|
4
5
|
import { runPostinstall } from '../src/postinstall.js';
|
|
6
|
+
import { installDependencies } from '../src/utils/cli-utils.js';
|
|
7
|
+
import { ENV_TEMPLATES } from '../src/utils/env-templates.js';
|
|
8
|
+
import fs from 'fs';
|
|
9
|
+
import path from 'path';
|
|
5
10
|
|
|
6
|
-
|
|
7
|
-
* CLI de `turnos`:
|
|
8
|
-
* npx turnos init --firebase [--force] [--dir <ruta>]
|
|
9
|
-
* npx turnos init --supabase [--force] [--dir <ruta>]
|
|
10
|
-
* node bin/turnos.js postinstall (lo lanza npm al instalar)
|
|
11
|
-
*/
|
|
12
|
-
const { values, positionals } = parseArgs({
|
|
13
|
-
args: process.argv.slice(2),
|
|
14
|
-
allowPositionals: true,
|
|
15
|
-
options: {
|
|
16
|
-
firebase: { type: 'boolean' },
|
|
17
|
-
supabase: { type: 'boolean' },
|
|
18
|
-
force: { type: 'boolean' },
|
|
19
|
-
dir: { type: 'string' },
|
|
20
|
-
help: { type: 'boolean' },
|
|
21
|
-
},
|
|
22
|
-
});
|
|
11
|
+
const program = new Command();
|
|
23
12
|
|
|
24
|
-
|
|
13
|
+
program
|
|
14
|
+
.name('turnos')
|
|
15
|
+
.description('CLI para instalar y configurar turnos en tu proyecto')
|
|
16
|
+
.version('0.2.0');
|
|
25
17
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
18
|
+
program
|
|
19
|
+
.command('init')
|
|
20
|
+
.description('Inicializa los componentes de turnos en tu proyecto')
|
|
21
|
+
.option('-f, --force', 'Sobrescribir archivos existentes')
|
|
22
|
+
.option('-d, --dir <ruta>', 'Directorio destino')
|
|
23
|
+
.action(async (options) => {
|
|
24
|
+
let { provider } = await inquirer.prompt([
|
|
25
|
+
{
|
|
26
|
+
type: 'list',
|
|
27
|
+
name: 'provider',
|
|
28
|
+
message: '¿Qué base de datos quieres usar?',
|
|
29
|
+
choices: ['firebase', 'supabase'],
|
|
30
|
+
},
|
|
31
|
+
]);
|
|
36
32
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
const res = await generateFiles({
|
|
34
|
+
provider,
|
|
35
|
+
targetDir: options.dir || resolveTargetDir(),
|
|
36
|
+
force: options.force,
|
|
37
|
+
});
|
|
41
38
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
process.exit(0);
|
|
46
|
-
}
|
|
39
|
+
// Automatizar instalación de dependencias
|
|
40
|
+
const deps = provider === 'supabase' ? ['@supabase/supabase-js'] : ['firebase'];
|
|
41
|
+
installDependencies(deps);
|
|
47
42
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
console.
|
|
52
|
-
process.exit(1);
|
|
53
|
-
}
|
|
54
|
-
const res = await generateFiles({ provider, targetDir: values.dir || resolveTargetDir(), force: values.force });
|
|
55
|
-
if (res.self) {
|
|
56
|
-
console.log('Estás en el propio paquete "turnos" (no-op). Usa --dir <proyecto-consumidor> para generar en otra parte.');
|
|
57
|
-
process.exit(0);
|
|
58
|
-
}
|
|
59
|
-
for (const f of res.generated) console.log(` + ${f}`);
|
|
60
|
-
for (const f of res.skipped) console.log(` = ${f} (ya existía; usa --force para sobrescribir)`);
|
|
61
|
-
if (provider === 'supabase') {
|
|
62
|
-
console.log('\nSiguiente paso: ejecuta la migración en tu Supabase: supabase db push (o psql "$DATABASE_URL" < supabase-migrations/0001_turnos.sql)');
|
|
63
|
-
} else {
|
|
64
|
-
console.log('\nSiguiente paso: publica las reglas: firebase deploy --only firestore:rules');
|
|
65
|
-
}
|
|
66
|
-
process.exit(0);
|
|
67
|
-
}
|
|
43
|
+
// Generar .env.example
|
|
44
|
+
const targetDir = options.dir || resolveTargetDir();
|
|
45
|
+
fs.writeFileSync(path.join(targetDir, '.env.example'), ENV_TEMPLATES[provider].trim());
|
|
46
|
+
console.log(`\n + .env.example creado con configuración para ${provider}`);
|
|
68
47
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
48
|
+
if (res.self) {
|
|
49
|
+
console.log('Estás en el propio paquete "turnos".');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
res.generated.forEach((f) => console.log(` + ${f}`));
|
|
54
|
+
res.skipped.forEach((f) => console.log(` = ${f} (ya existía)`));
|
|
55
|
+
|
|
56
|
+
console.log(`\n¡Turnos inicializado con ${provider}!`);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
program
|
|
60
|
+
.command('postinstall')
|
|
61
|
+
.action(async () => {
|
|
62
|
+
await runPostinstall({ targetDir: resolveTargetDir() });
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
program.parse(process.argv);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ffstack/turnos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"src/adapters",
|
|
28
28
|
"src/generator.js",
|
|
29
29
|
"src/postinstall.js",
|
|
30
|
+
"src/utils",
|
|
30
31
|
"templates",
|
|
31
32
|
"README.md",
|
|
32
33
|
"!**/*.test.js",
|
|
@@ -63,6 +64,8 @@
|
|
|
63
64
|
"supabase"
|
|
64
65
|
],
|
|
65
66
|
"dependencies": {
|
|
67
|
+
"commander": "^13.0.0",
|
|
68
|
+
"inquirer": "^12.0.0",
|
|
66
69
|
"date-fns": "^4.4.0",
|
|
67
70
|
"lucide-react": "^1.71.0",
|
|
68
71
|
"react": "^19.3.1",
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
|
|
4
|
+
export function getPackageManager() {
|
|
5
|
+
if (fs.existsSync('package-lock.json')) return 'npm';
|
|
6
|
+
if (fs.existsSync('pnpm-lock.yaml')) return 'pnpm';
|
|
7
|
+
if (fs.existsSync('yarn.lock')) return 'yarn';
|
|
8
|
+
if (fs.existsSync('bun.lockb')) return 'bun';
|
|
9
|
+
return 'npm';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function installDependencies(dependencies) {
|
|
13
|
+
const pm = getPackageManager();
|
|
14
|
+
const installCmd = pm === 'npm' ? 'install' : 'add';
|
|
15
|
+
const command = `${pm} ${installCmd} ${dependencies.join(' ')}`;
|
|
16
|
+
|
|
17
|
+
console.log(`\nEjecutando: ${command}...`);
|
|
18
|
+
execSync(command, { stdio: 'inherit' });
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const ENV_TEMPLATES = {
|
|
2
|
+
firebase: `
|
|
3
|
+
# Firebase Configuration
|
|
4
|
+
VITE_FIREBASE_API_KEY=
|
|
5
|
+
VITE_FIREBASE_AUTH_DOMAIN=
|
|
6
|
+
VITE_FIREBASE_PROJECT_ID=
|
|
7
|
+
VITE_FIREBASE_STORAGE_BUCKET=
|
|
8
|
+
VITE_FIREBASE_MESSAGING_SENDER_ID=
|
|
9
|
+
VITE_FIREBASE_APP_ID=
|
|
10
|
+
`,
|
|
11
|
+
supabase: `
|
|
12
|
+
# Supabase Configuration
|
|
13
|
+
VITE_SUPABASE_URL=
|
|
14
|
+
VITE_SUPABASE_ANON_KEY=
|
|
15
|
+
`,
|
|
16
|
+
};
|