klei-cli 1.0.8 → 1.0.10

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/bin/cli.js +473 -6
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -51,7 +51,8 @@ var npmjs = [
51
51
  watch: 'tsup --entry.index src/index.ts --format esm --clean --watch --onSuccess "node dist/index.js"',
52
52
  build: "tsup --entry.index src/index.ts --format esm,cjs --dts --clean",
53
53
  "test:esm": 'tsup --entry.test src/index.ts --format esm --clean --onSuccess "node dist/test.js"',
54
- "test:spec": 'tsup test/test.spec.ts --format esm --clean --onSuccess "cross-env NODE_ENV=test node --test dist/test.spec.js"'
54
+ "test:spec": 'tsup test/test.spec.ts --format esm --clean --onSuccess "cross-env NODE_ENV=test node --test dist/test.spec.js"',
55
+ "publicar": "npm publish --access public"
55
56
  },
56
57
  keywords: [],
57
58
  author: "",
@@ -172,8 +173,16 @@ export default tseslint.config(
172
173
  'comma-dangle': ['error', 'never'],
173
174
  'no-multiple-empty-lines': ['error', { max: 1 }],
174
175
  'no-async-promise-executor': 'off',
175
- 'no-unused-vars': 'warn',
176
- '@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }]
176
+ 'no-unused-vars': 'off',
177
+ '@typescript-eslint/no-unused-vars': ['warn', {
178
+ argsIgnorePattern: '^_',
179
+ varsIgnorePattern: '^_',
180
+ ignoreRestSiblings: true,
181
+ destructuredArrayIgnorePattern: '^_',
182
+ args: 'after-used',
183
+ vars: 'all',
184
+ caughtErrors: 'none'
185
+ }]
177
186
  }
178
187
  }
179
188
  )`,
@@ -303,6 +312,461 @@ describe('greetUser', () => {
303
312
  }
304
313
  ];
305
314
 
315
+ // src/templates/astro.ts
316
+ var astro = [
317
+ {
318
+ content: "# Proyecto generado por Klei CLI.",
319
+ pathFileName: "README.md"
320
+ },
321
+ {
322
+ content: JSON.stringify({
323
+ name: "my-astro-project",
324
+ type: "module",
325
+ version: "0.0.1",
326
+ scripts: {
327
+ dev: "astro dev --host",
328
+ build: "astro build",
329
+ preview: "astro preview",
330
+ astro: "astro"
331
+ },
332
+ devDependencies: {
333
+ "@eslint/js": "latest",
334
+ "@types/node": "latest",
335
+ "@types/react": "latest",
336
+ "@types/react-dom": "latest",
337
+ "@typescript-eslint/parser": "latest",
338
+ eslint: "latest",
339
+ "eslint-plugin-astro": "latest",
340
+ "typescript-eslint": "latest"
341
+ },
342
+ dependencies: {
343
+ "@astrojs/node": "latest",
344
+ "@astrojs/react": "latest",
345
+ "@astrojs/sitemap": "latest",
346
+ "@astrojs/vercel": "^8.0.4",
347
+ "@kreisler/i18n": "latest",
348
+ "@kreisler/vite-pwa-astro": "latest",
349
+ "@tailwindcss/vite": "latest",
350
+ astro: "latest",
351
+ "astro-robots-txt": "latest",
352
+ "astro-webmanifest": "latest",
353
+ react: "latest",
354
+ "react-dom": "latest",
355
+ tailwindcss: "latest"
356
+ }
357
+ }, null, 2),
358
+ pathFileName: "package.json"
359
+ },
360
+ {
361
+ content: `# Environment variables
362
+ SITE_URL=https://my-astro-project.vercel.app/
363
+ `,
364
+ pathFileName: ".env.example"
365
+ },
366
+ {
367
+ content: `// @ts-check
368
+ import { defineConfig } from 'astro/config'
369
+ import AstroPWA from '@kreisler/vite-pwa-astro'
370
+ import sitemap from '@astrojs/sitemap'
371
+ import robotsTxt from 'astro-robots-txt'
372
+ import webmanifest from 'astro-webmanifest'
373
+ import vercel from '@astrojs/vercel'
374
+ import node from '@astrojs/node'
375
+ import react from '@astrojs/react'
376
+ import tailwindcss from '@tailwindcss/vite'
377
+
378
+ const allFilesAssets = import.meta.glob('./src/assets/**/*')
379
+ const allFilesPublic = import.meta.glob('./public/**/*')
380
+
381
+ const adapter = import.meta.env.PROD
382
+ ? vercel({ includeFiles: [...Object.keys(allFilesAssets), ...Object.keys(allFilesPublic)] })
383
+ : node({ mode: 'standalone' })
384
+
385
+ // https://astro.build/config
386
+ export default defineConfig({
387
+ prefetch: true,
388
+ vite: {
389
+ server: {
390
+ allowedHosts: true
391
+ },
392
+ plugins: [tailwindcss()]
393
+ },
394
+ site: 'https://my-astro-project.vercel.app/',
395
+ adapter,
396
+ integrations: [
397
+ react(),
398
+ sitemap(),
399
+ robotsTxt(),
400
+ webmanifest({
401
+ name: 'My Astro Project',
402
+ icon: 'public/favicon.svg',
403
+ short_name: 'MyProject',
404
+ description: 'My Astro Project Description',
405
+ start_url: '/',
406
+ theme_color: '#1E90FF',
407
+ background_color: '#ffffff',
408
+ display: 'standalone',
409
+ config: {
410
+ insertAppleTouchLinks: true,
411
+ insertThemeColorMeta: false
412
+ }
413
+ }),
414
+ AstroPWA({
415
+ includeAssets: ['fonts/**/*.otf', '**/*.svg', '**/*.png', '**/*.webp'],
416
+ registerType: 'autoUpdate',
417
+ workbox: {
418
+ globPatterns: ['**/*.{js,css,html,svg,png,webp}']
419
+ }
420
+ })
421
+ ],
422
+ build: {
423
+ format: 'file'
424
+ }
425
+ })
426
+ `,
427
+ pathFileName: "astro.config.mjs"
428
+ },
429
+ {
430
+ content: JSON.stringify({
431
+ extends: "astro/tsconfigs/strict",
432
+ include: [".astro/types.d.ts", "**/*"],
433
+ exclude: ["dist"],
434
+ compilerOptions: {
435
+ baseUrl: ".",
436
+ paths: {
437
+ "@src/*": ["./src/*"]
438
+ },
439
+ jsx: "react-jsx",
440
+ jsxImportSource: "react"
441
+ }
442
+ }, null, 2),
443
+ pathFileName: "tsconfig.json"
444
+ },
445
+ {
446
+ content: `import globals from 'globals'
447
+ import pluginJs from '@eslint/js'
448
+ import tseslint from 'typescript-eslint'
449
+ import eslintPluginAstro from 'eslint-plugin-astro'
450
+
451
+ /** @type {import('eslint').Linter.Config[]} */
452
+ export default [
453
+ { ignores: ['node_modules', 'dist/'] },
454
+ { files: ['src/*.{js,mjs,cjs,ts,tsx,jsx}'] },
455
+ { files: ['**/*.{js}'], languageOptions: { sourceType: 'commonjs' } },
456
+ { languageOptions: { globals: globals.browser } },
457
+ pluginJs.configs.recommended,
458
+ ...tseslint.configs.recommended,
459
+ ...eslintPluginAstro.configs.recommended,
460
+ {
461
+ rules: {
462
+ quotes: [2, 'single', { avoidEscape: true }],
463
+ 'prefer-const': ['error', { ignoreReadBeforeAssign: true }],
464
+ 'space-before-function-paren': 'off',
465
+ '@typescript-eslint/no-explicit-any': 'off',
466
+ 'no-useless-escape': 'off',
467
+ 'eol-last': 'error',
468
+ semi: 'error',
469
+ 'quote-props': 'error',
470
+ 'spaced-comment': 'error',
471
+ 'comma-dangle': 'error',
472
+ 'no-multiple-empty-lines': 'error',
473
+ 'no-async-promise-executor': 'off',
474
+ 'no-unused-vars': 'off',
475
+ '@typescript-eslint/no-unused-vars': 'warn'
476
+ }
477
+ }
478
+ ]
479
+ `,
480
+ pathFileName: "eslint.config.mjs"
481
+ },
482
+ {
483
+ content: `# build output
484
+ dist/
485
+
486
+ # generated types
487
+ .astro/
488
+
489
+ # dependencies
490
+ node_modules/
491
+
492
+ # logs
493
+ npm-debug.log*
494
+ yarn-debug.log*
495
+ yarn-error.log*
496
+ pnpm-debug.log*
497
+
498
+ # environment variables
499
+ .env
500
+ .env.production
501
+
502
+ # macOS-specific files
503
+ .DS_Store
504
+
505
+ # jetbrains setting folder
506
+ .idea/
507
+ .vercel/
508
+ `,
509
+ pathFileName: ".gitignore"
510
+ },
511
+ {
512
+ content: `---
513
+ import Layout from '../layouts/Layout.astro'
514
+ ---
515
+
516
+ <Layout>
517
+ <header>Header</header>
518
+ <main>Main Content</main>
519
+ <footer>Footer</footer>
520
+ </Layout>
521
+ `,
522
+ pathFileName: "src/pages/index.astro"
523
+ },
524
+ {
525
+ content: `---
526
+ import "@src/styles/global.css";
527
+
528
+ const { title, description } = Astro.props;
529
+ ---
530
+
531
+ <!doctype html>
532
+ <html lang="es">
533
+ <head>
534
+ <meta charset="UTF-8" />
535
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
536
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
537
+ <meta name="generator" content={Astro.generator} />
538
+ <title>{title}</title>
539
+ <meta name="description" content={description} />
540
+
541
+ <!-- PWA -->
542
+ <link rel="manifest" href="/manifest.webmanifest" />
543
+ <meta name="application-name" content="My Project" />
544
+ <meta name="apple-mobile-web-app-capable" content="yes" />
545
+ <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
546
+ <meta name="apple-mobile-web-app-title" content="My Project" />
547
+ <link rel="apple-touch-icon" href="/favicon.svg" />
548
+ <meta name="mobile-web-app-capable" content="yes" />
549
+ <meta name="msapplication-starturl" content="/" />
550
+ <meta name="msapplication-TileColor" content="#1E90FF" />
551
+ <meta name="theme-color" content="#1E90FF" />
552
+
553
+ <script is:inline>
554
+ if ("serviceWorker" in navigator) {
555
+ let refreshing = false;
556
+ navigator.serviceWorker.addEventListener("controllerchange", () => {
557
+ if (refreshing) return;
558
+ refreshing = true;
559
+ window.location.reload();
560
+ });
561
+ }
562
+ </script>
563
+ </head>
564
+ <body class="grid min-h-dvh grid-rows-[auto_1fr_auto]">
565
+ <slot />
566
+ </body>
567
+ </html>
568
+ `,
569
+ pathFileName: "src/layouts/Layout.astro"
570
+ },
571
+ {
572
+ content: `import path from 'path'
573
+ import fs from 'fs'
574
+
575
+ export const {
576
+ NODE_ENV = 'development',
577
+ CWD = process.cwd(),
578
+ PROD,
579
+ DEV,
580
+ SITE = import.meta.env.SITE_URL || 'https://my-astro-project.vercel.app/'
581
+ } = import.meta.env || process.env
582
+
583
+ export const publicTemp = (...paths: string[]): string => {
584
+ const folderWithArchive = DEV ? path.join(CWD, ...paths) : path.join('/tmp', ...paths)
585
+ const directory = path.dirname(folderWithArchive)
586
+ if (!fs.existsSync(directory)) {
587
+ fs.mkdirSync(directory, { recursive: true })
588
+ }
589
+ return folderWithArchive
590
+ }
591
+
592
+ export const publicSrc = (...paths: string[]) => path.join(CWD, ...paths)
593
+ `,
594
+ pathFileName: "src/env.ts"
595
+ },
596
+ {
597
+ content: `import path from 'path'
598
+ import fs from 'fs'
599
+
600
+ export const {
601
+ NODE_ENV = 'development',
602
+ CWD = process.cwd(),
603
+ PROD,
604
+ DEV,
605
+ SITE = import.meta.env.SITE_URL || 'https://my-astro-project.vercel.app/'
606
+ } = import.meta.env || process.env
607
+
608
+ export const publicTemp = (...paths: string[]): string => {
609
+ const folderWithArchive = DEV ? path.join(CWD, ...paths) : path.join('/tmp', ...paths)
610
+ const directory = path.dirname(folderWithArchive)
611
+ if (!fs.existsSync(directory)) {
612
+ fs.mkdirSync(directory, { recursive: true })
613
+ }
614
+ return folderWithArchive
615
+ }
616
+
617
+ export const publicSrc = (...paths: string[]) => path.join(CWD, ...paths)
618
+ `,
619
+ pathFileName: "src/libs/env.ts"
620
+ },
621
+ {
622
+ content: `import { createI18n } from '@kreisler/i18n'
623
+ import { es } from '@src/i18n/langs/es'
624
+ import { en } from '@src/i18n/langs/en'
625
+ import { z } from 'astro/zod'
626
+
627
+ export const translations = {
628
+ es,
629
+ en
630
+ }
631
+
632
+ export const i18n = createI18n({
633
+ defaultLocale: 'es',
634
+ messages: {
635
+ es,
636
+ en
637
+ }
638
+ })
639
+
640
+ export const { getAvailableLocales, getDefaultLocale, useTranslations } = i18n
641
+
642
+ export const defaultLang = getDefaultLocale()
643
+
644
+ export const languagesKeys = getAvailableLocales()
645
+
646
+ export const SchemaLang = z.enum(languagesKeys, { message: 'Invalid lang' })
647
+
648
+ export const SchemaParamsLang = z.object({ lang: SchemaLang }, { message: 'Invalid param lang' })
649
+
650
+ export type UILanguageKeys = z.infer<typeof SchemaLang>
651
+
652
+ export type Lang = z.infer<typeof SchemaParamsLang>
653
+
654
+ export type Languages = z.infer<typeof SchemaLang>
655
+
656
+ export function getStaticPathsLang(): { params: { lang: UILanguageKeys } }[] {
657
+ return languagesKeys.map(lang => ({ params: { lang } }))
658
+ }
659
+
660
+ export const getLangFromUrl = (astroUrl: URL): UILanguageKeys => {
661
+ const url = new URL(astroUrl.toString().toLowerCase())
662
+ const [, lang] = url.pathname.split('/')
663
+ return lang in translations ? lang as UILanguageKeys : getDefaultLocale()
664
+ }
665
+
666
+ export const t18n = (astroUrl: URL) => {
667
+ const url = new URL(astroUrl.toString().toLowerCase())
668
+ const lang = getLangFromUrl(url)
669
+ return useTranslations(lang)
670
+ }
671
+ `,
672
+ pathFileName: "src/i18n/translate.ts"
673
+ },
674
+ {
675
+ content: `export const es = {
676
+ page: {
677
+ home: {
678
+ helloworld: 'Hola Mundo',
679
+ select: {
680
+ label: 'Selecciona un formato',
681
+ placeholder: 'Elige una opci\xF3n',
682
+ movie: 'Pel\xEDcula',
683
+ series: 'Serie'
684
+ }
685
+ }
686
+ }
687
+ } as const
688
+
689
+ export type SchemaEs = typeof es
690
+ `,
691
+ pathFileName: "src/i18n/langs/es.ts"
692
+ },
693
+ {
694
+ content: `export const en = {
695
+ page: {
696
+ home: {
697
+ helloworld: 'Hello World',
698
+ select: {
699
+ label: 'Select a format',
700
+ placeholder: 'Choose an option',
701
+ movie: 'Movie',
702
+ series: 'Series'
703
+ }
704
+ }
705
+ }
706
+ } as const
707
+
708
+ export type SchemaEn = typeof en
709
+ `,
710
+ pathFileName: "src/i18n/langs/en.ts"
711
+ },
712
+ {
713
+ content: `/// <reference path="../.astro/types.d.ts" />
714
+ /// <reference types="astro/client" />
715
+ `,
716
+ pathFileName: "src/env.d.ts"
717
+ },
718
+ {
719
+ content: `/// <reference types="astro/client" />
720
+
721
+ interface WindowEventMap {
722
+ 'sw:updated': CustomEvent<ServiceWorkerRegistration>
723
+ }
724
+
725
+ declare global {
726
+ interface Navigator {
727
+ serviceWorker: Navigator['serviceWorker']
728
+ }
729
+ }
730
+
731
+ import 'react'
732
+
733
+ declare module 'react' {
734
+ interface HTMLAttributes<T> extends AriaAttributes, DOMAttributes<T> {
735
+ tw?: string
736
+ }
737
+ }
738
+ `,
739
+ pathFileName: "src/global.d.ts"
740
+ },
741
+ {
742
+ content: `@import "tailwindcss";
743
+
744
+ * {
745
+ margin: 0;
746
+ padding: 0;
747
+ box-sizing: border-box;
748
+ }
749
+
750
+ html {
751
+ font-family: system-ui, sans-serif;
752
+ }
753
+
754
+ body {
755
+ min-height: 100vh;
756
+ }
757
+ `,
758
+ pathFileName: "src/styles/global.css"
759
+ },
760
+ {
761
+ content: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
762
+ <circle cx="50" cy="50" r="50" fill="#1E90FF"/>
763
+ <text x="50" y="55" font-size="40" text-anchor="middle" fill="white" font-family="system-ui">A</text>
764
+ </svg>
765
+ `,
766
+ pathFileName: "public/favicon.svg"
767
+ }
768
+ ];
769
+
306
770
  // src/lib/utils/npm-utils.ts
307
771
  import fs from "node:fs";
308
772
  import spawn from "cross-spawn";
@@ -353,7 +817,8 @@ var createProjectStructure = async (answers, spinner) => {
353
817
  return new Promise((resolve, reject) => {
354
818
  const projects = {
355
819
  npmjs,
356
- monorepo: []
820
+ monorepo: [],
821
+ astro
357
822
  };
358
823
  const projectStr = projects[answers.projectType];
359
824
  if (!projectStr) {
@@ -414,7 +879,8 @@ var createProjectStructure = async (answers, spinner) => {
414
879
  const packageJson = getPkgs(packageJsonPath);
415
880
  const pkgs = Object.keys(packageJson.devDependencies).map((pkgName) => parsePackageName(pkgName)).map((pkg) => pkg.name);
416
881
  spinner.info(`Instalando dependencias: ${chalk2.yellow(pkgs.join(" "))}`);
417
- installSyncSaveDev(pkgs, answers.projectPackageManager, projectDir);
882
+ const installFlags = answers.projectType === "astro" ? ["-D", "--legacy-peer-deps"] : ["-D"];
883
+ installSyncSaveDev(pkgs, answers.projectPackageManager, projectDir, installFlags);
418
884
  spinner.info(chalk2.green("Dependencias instaladas exitosamente"));
419
885
  }
420
886
  spinner.succeed(`${chalk2.green(` Proyecto ${chalk2.bold(projectDir)} creado exitosamente`)}`);
@@ -432,7 +898,8 @@ var questionsMain = [
432
898
  name: "projectType",
433
899
  message: " \xBFQu\xE9 tipo de proyecto quieres crear?",
434
900
  choices: [
435
- { name: "npmjs package (Node.js)", value: "npmjs" }
901
+ { name: "npmjs package (Node.js)", value: "npmjs" },
902
+ { name: "Astro (Web framework)", value: "astro" }
436
903
  // { name: 'Aplicación Monorepo (Node.js)', value: 'monorepo' }
437
904
  // { name: 'Aplicación CLI (Node.js)', value: 'cli' }
438
905
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "klei-cli",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "cli for creating and managing packages",
5
5
  "type": "module",
6
6
  "funding": {