clases-tailwind 1.0.2 → 1.0.3

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.
Files changed (2) hide show
  1. package/package.json +4 -1
  2. package/src/scripts/init.js +22 -13
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "clases-tailwind",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
+ "bin": {
8
+ "clases-init": "./scripts/init.js"
9
+ },
7
10
  "exports": {
8
11
  ".": {
9
12
  "types": "./dist/index.d.ts",
@@ -1,26 +1,35 @@
1
+ #!/usr/bin/env node
1
2
  const fs = require('fs');
2
3
  const path = require('path');
3
4
 
4
- const projectRoot = process.env.INIT_CWD || path.resolve('../../');
5
+ // Intentamos INIT_CWD (npm/pnpm), si no, el directorio actual
6
+ const projectRoot = process.env.INIT_CWD || process.cwd();
5
7
  const hasSrc = fs.existsSync(path.join(projectRoot, 'src'));
6
8
  const targetDir = hasSrc ? path.join(projectRoot, 'src') : projectRoot;
7
9
  const configPath = path.join(targetDir, 'clases.config.ts');
8
10
 
9
- const tailwindTemplate = `import { createCl } from 'clases';
11
+ const template = `import { createCl } from 'clases';
10
12
  import { tailwindRegistry } from 'clases-tailwind';
11
13
 
12
- // Instancia configurada para Tailwind CSS
13
14
  export const tw = createCl(tailwindRegistry);
14
15
  `;
15
16
 
16
- try {
17
- // En este caso, SIEMPRE queremos que si instalan clases-tailwind,
18
- // el archivo tenga la configuración de Tailwind.
19
- fs.writeFileSync(configPath, tailwindTemplate, 'utf8');
20
- console.log(
21
- '\x1b[32m%s\x1b[0m',
22
- ' [clases-tailwind] Configuración vinculada con éxito en ' + (hasSrc ? 'src/' : './')
23
- );
24
- } catch (err) {
25
- console.log(' [clases-tailwind] Aviso: No se pudo auto-configurar el archivo.');
17
+ function init() {
18
+ if (fs.existsSync(configPath)) {
19
+ // Si el usuario lo corre manualmente con npx, avisamos.
20
+ // Si es postinstall, mejor callar.
21
+ if (!process.env.INIT_CWD) {
22
+ console.log('⚠️ El archivo clases.config.ts ya existe.');
23
+ }
24
+ return;
25
+ }
26
+
27
+ try {
28
+ fs.writeFileSync(configPath, template, 'utf8');
29
+ console.log('\x1b[32m%s\x1b[0m', '✅ clases.config.ts generado con éxito.');
30
+ } catch (e) {
31
+ console.error('❌ Error al crear la configuración:', e.message);
32
+ }
26
33
  }
34
+
35
+ init();