@lytjs/cli 6.5.0 → 6.7.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/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { existsSync, readFileSync, mkdirSync, writeFileSync, readdirSync } from 'fs';
2
+ import { existsSync, readFileSync, mkdirSync, writeFileSync, readdirSync as readdirSync$1 } from 'fs';
3
3
  import * as path from 'path';
4
4
  import { join, resolve, dirname } from 'path';
5
5
  import { execSync, spawn } from 'child_process';
@@ -66,7 +66,7 @@ function exists(path2) {
66
66
  }
67
67
  function isEmptyDir(dir) {
68
68
  if (!existsSync(dir)) return true;
69
- const files = readdirSync(dir);
69
+ const files = readdirSync$1(dir);
70
70
  return files.length === 0;
71
71
  }
72
72
  function detectPackageManager(cwd = process.cwd()) {
@@ -169,7 +169,7 @@ function generateProjectFiles(targetDir, projectName, template) {
169
169
  },
170
170
  devDependencies: {
171
171
  "@lytjs/plugin-vite": "^6.0.0",
172
- "vite": "^5.0.0"
172
+ vite: "^5.0.0"
173
173
  }
174
174
  };
175
175
  if (!isMinimal) {
@@ -725,9 +725,10 @@ async function test(options = {}) {
725
725
  var TEMPLATES2 = {
726
726
  component(name, basePath) {
727
727
  const filePath = join(basePath, `${name}.lyt`);
728
- return [{
729
- filePath,
730
- content: `<template>
728
+ return [
729
+ {
730
+ filePath,
731
+ content: `<template>
731
732
  <div class="${name}">
732
733
  <slot />
733
734
  </div>
@@ -749,14 +750,16 @@ defineEmits<{
749
750
  }
750
751
  </style>
751
752
  `
752
- }];
753
+ }
754
+ ];
753
755
  },
754
756
  page(name, basePath) {
755
757
  const pascalName = toPascalCase(name);
756
758
  const filePath = join(basePath, `${name}.lyt`);
757
- return [{
758
- filePath,
759
- content: `<template>
759
+ return [
760
+ {
761
+ filePath,
762
+ content: `<template>
760
763
  <div class="page-${name}">
761
764
  <h1>${pascalName}</h1>
762
765
  </div>
@@ -772,13 +775,15 @@ defineEmits<{
772
775
  }
773
776
  </style>
774
777
  `
775
- }];
778
+ }
779
+ ];
776
780
  },
777
781
  store(name, basePath) {
778
782
  const filePath = join(basePath, `${name}.ts`);
779
- return [{
780
- filePath,
781
- content: `import { defineStore } from '@lytjs/store';
783
+ return [
784
+ {
785
+ filePath,
786
+ content: `import { defineStore } from '@lytjs/store';
782
787
  import { signal, computed } from '@lytjs/reactivity';
783
788
 
784
789
  export const use${toPascalCase(name)}Store = defineStore('${name}', () => {
@@ -810,14 +815,16 @@ export const use${toPascalCase(name)}Store = defineStore('${name}', () => {
810
815
  };
811
816
  });
812
817
  `
813
- }];
818
+ }
819
+ ];
814
820
  },
815
821
  directive(name, basePath) {
816
822
  const filePath = join(basePath, `${name}.ts`);
817
823
  const camelCaseName = toCamelCase(name);
818
- return [{
819
- filePath,
820
- content: `import type { Directive } from '@lytjs/core';
824
+ return [
825
+ {
826
+ filePath,
827
+ content: `import type { Directive } from '@lytjs/core';
821
828
 
822
829
  /**
823
830
  * ${toPascalCase(name)} Directive
@@ -841,13 +848,15 @@ export const v${toPascalCase(name)}: Directive = {
841
848
  },
842
849
  };
843
850
  `
844
- }];
851
+ }
852
+ ];
845
853
  },
846
854
  composable(name, basePath) {
847
855
  const filePath = join(basePath, `use${toPascalCase(name)}.ts`);
848
- return [{
849
- filePath,
850
- content: `import { signal, computed } from '@lytjs/reactivity';
856
+ return [
857
+ {
858
+ filePath,
859
+ content: `import { signal, computed } from '@lytjs/reactivity';
851
860
 
852
861
  /**
853
862
  * ${toPascalCase(name)} Composable
@@ -896,13 +905,15 @@ export function use${toPascalCase(name)}() {
896
905
  };
897
906
  }
898
907
  `
899
- }];
908
+ }
909
+ ];
900
910
  },
901
911
  hook(name, basePath) {
902
912
  const filePath = join(basePath, `use${toPascalCase(name)}.ts`);
903
- return [{
904
- filePath,
905
- content: `import { signal, onMounted, onUnmounted } from '@lytjs/core';
913
+ return [
914
+ {
915
+ filePath,
916
+ content: `import { signal, onMounted, onUnmounted } from '@lytjs/core';
906
917
 
907
918
  /**
908
919
  * ${toPascalCase(name)} Hook
@@ -923,13 +934,15 @@ export function use${toPascalCase(name)}() {
923
934
  };
924
935
  }
925
936
  `
926
- }];
937
+ }
938
+ ];
927
939
  },
928
940
  util(name, basePath) {
929
941
  const filePath = join(basePath, `${name}.ts`);
930
- return [{
931
- filePath,
932
- content: `/**
942
+ return [
943
+ {
944
+ filePath,
945
+ content: `/**
933
946
  * ${toPascalCase(name)} Utility Functions
934
947
  */
935
948
 
@@ -944,13 +957,15 @@ export function ${toCamelCase(name)}(input: any) {
944
957
  return input;
945
958
  }
946
959
  `
947
- }];
960
+ }
961
+ ];
948
962
  },
949
963
  middleware(name, basePath) {
950
964
  const filePath = join(basePath, `${name}.ts`);
951
- return [{
952
- filePath,
953
- content: `import type { NavigationGuard } from '@lytjs/router';
965
+ return [
966
+ {
967
+ filePath,
968
+ content: `import type { NavigationGuard } from '@lytjs/router';
954
969
 
955
970
  /**
956
971
  * ${toPascalCase(name)} Middleware
@@ -961,7 +976,8 @@ export const ${toCamelCase(name)}Middleware: NavigationGuard = (to, from, next)
961
976
  next();
962
977
  };
963
978
  `
964
- }];
979
+ }
980
+ ];
965
981
  }
966
982
  };
967
983
  function toPascalCase(str) {
@@ -1516,11 +1532,7 @@ async function generate(options) {
1516
1532
  layout: "layouts",
1517
1533
  middleware: "middleware"
1518
1534
  };
1519
- const targetDir = path.join(
1520
- process.cwd(),
1521
- basePath,
1522
- typeDirs[type] || "components"
1523
- );
1535
+ const targetDir = path.join(process.cwd(), basePath, typeDirs[type] || "components");
1524
1536
  await ensureDir(targetDir);
1525
1537
  const templateFn = TEMPLATES3[type];
1526
1538
  if (!templateFn) {
@@ -1552,7 +1564,9 @@ async function generate(options) {
1552
1564
  }
1553
1565
  logger.info("\nNext steps:");
1554
1566
  logger.info(` cd ${targetDir}`);
1555
- logger.info(` Import your ${type}: import { ${template === "sfc" ? "default" : templateData.pascalName} } from './${templateData.kebabName}'`);
1567
+ logger.info(
1568
+ ` Import your ${type}: import { ${template === "sfc" ? "default" : templateData.pascalName} } from './${templateData.kebabName}'`
1569
+ );
1556
1570
  logger.info("\nAvailable options:");
1557
1571
  logger.info(" --template=sfc : Single File Component (.lyt)");
1558
1572
  logger.info(" --template=functional : Functional component");
@@ -1566,45 +1580,53 @@ var PLUGIN_TEMPLATES = {
1566
1580
  function getTemplateContent(template, pluginName) {
1567
1581
  const packageName = `@lytjs/plugin-${pluginName}`;
1568
1582
  const files = {};
1569
- files["package.json"] = JSON.stringify({
1570
- name: packageName,
1571
- version: "0.1.0",
1572
- description: `LytJS plugin: ${pluginName}`,
1573
- main: "dist/index.cjs",
1574
- module: "dist/index.mjs",
1575
- types: "dist/index.d.ts",
1576
- exports: {
1577
- ".": {
1578
- import: "./dist/index.mjs",
1579
- require: "./dist/index.cjs",
1580
- types: "./dist/index.d.ts"
1583
+ files["package.json"] = JSON.stringify(
1584
+ {
1585
+ name: packageName,
1586
+ version: "0.1.0",
1587
+ description: `LytJS plugin: ${pluginName}`,
1588
+ main: "dist/index.cjs",
1589
+ module: "dist/index.mjs",
1590
+ types: "dist/index.d.ts",
1591
+ exports: {
1592
+ ".": {
1593
+ import: "./dist/index.mjs",
1594
+ require: "./dist/index.cjs",
1595
+ types: "./dist/index.d.ts"
1596
+ }
1597
+ },
1598
+ files: ["dist"],
1599
+ scripts: {
1600
+ build: "tsup",
1601
+ dev: "tsup --watch",
1602
+ test: "vitest",
1603
+ lint: "eslint src",
1604
+ prepublishOnly: "npm run build"
1605
+ },
1606
+ keywords: ["lytjs", "plugin"],
1607
+ license: "MIT",
1608
+ peerDependencies: {
1609
+ "@lytjs/core": ">=6.0.0"
1581
1610
  }
1582
1611
  },
1583
- files: ["dist"],
1584
- scripts: {
1585
- build: "tsup",
1586
- dev: "tsup --watch",
1587
- test: "vitest",
1588
- lint: "eslint src",
1589
- "prepublishOnly": "npm run build"
1590
- },
1591
- keywords: ["lytjs", "plugin"],
1592
- license: "MIT",
1593
- peerDependencies: {
1594
- "@lytjs/core": ">=6.0.0"
1595
- }
1596
- }, null, 2);
1597
- files["tsconfig.json"] = JSON.stringify({
1598
- extends: "@lytjs/core/tsconfig.json",
1599
- compilerOptions: {
1600
- outDir: "./dist",
1601
- rootDir: "./src",
1602
- declaration: true,
1603
- declarationMap: true
1612
+ null,
1613
+ 2
1614
+ );
1615
+ files["tsconfig.json"] = JSON.stringify(
1616
+ {
1617
+ extends: "@lytjs/core/tsconfig.json",
1618
+ compilerOptions: {
1619
+ outDir: "./dist",
1620
+ rootDir: "./src",
1621
+ declaration: true,
1622
+ declarationMap: true
1623
+ },
1624
+ include: ["src"],
1625
+ exclude: ["node_modules", "dist", "tests"]
1604
1626
  },
1605
- include: ["src"],
1606
- exclude: ["node_modules", "dist", "tests"]
1607
- }, null, 2);
1627
+ null,
1628
+ 2
1629
+ );
1608
1630
  files["tsup.config.ts"] = `import { defineConfig } from 'tsup';
1609
1631
 
1610
1632
  export default defineConfig({
@@ -1816,7 +1838,16 @@ async function buildPlugin(options = {}) {
1816
1838
  logger.info("Building plugin...");
1817
1839
  try {
1818
1840
  const buildCmd = "tsup";
1819
- const args = ["--entry", "src/index.ts", "--outDir", outDir, "--format", "esm,cjs", "--dts", "--sourcemap"];
1841
+ const args = [
1842
+ "--entry",
1843
+ "src/index.ts",
1844
+ "--outDir",
1845
+ outDir,
1846
+ "--format",
1847
+ "esm,cjs",
1848
+ "--dts",
1849
+ "--sourcemap"
1850
+ ];
1820
1851
  if (options.minify) {
1821
1852
  args.push("--minify");
1822
1853
  }
@@ -1882,8 +1913,8 @@ async function validatePlugin(options = {}) {
1882
1913
  if (!existsSync(tsupConfigPath)) {
1883
1914
  warnings.push("tsup.config.ts not found (recommended for builds)");
1884
1915
  }
1885
- let hasErrors = errors.length > 0;
1886
- let hasWarnings = warnings.length > 0;
1916
+ const hasErrors = errors.length > 0;
1917
+ const hasWarnings = warnings.length > 0;
1887
1918
  if (hasErrors) {
1888
1919
  logger.error("Validation failed with errors:");
1889
1920
  for (const err of errors) {
@@ -1912,7 +1943,7 @@ async function validatePlugin(options = {}) {
1912
1943
  }
1913
1944
  function isEmptyDir2(dir) {
1914
1945
  if (!existsSync(dir)) return true;
1915
- const files = __require("fs").readdirSync(dir);
1946
+ const files = readdirSync(dir);
1916
1947
  return files.length === 0;
1917
1948
  }
1918
1949
  function listPluginTemplates() {
@@ -1931,7 +1962,7 @@ async function runCli(rawArgs = process.argv.slice(2)) {
1931
1962
  return;
1932
1963
  }
1933
1964
  if (options.version || command === "version" || command === "-v" || command === "--version") {
1934
- console.log(`LytJS CLI v${VERSION}`);
1965
+ console.warn(`LytJS CLI v${VERSION}`);
1935
1966
  return;
1936
1967
  }
1937
1968
  switch (command) {
@@ -1965,8 +1996,17 @@ async function runCli(rawArgs = process.argv.slice(2)) {
1965
1996
  grep: options.grep
1966
1997
  });
1967
1998
  break;
1968
- case "add":
1969
- const addTypes = ["component", "page", "store", "directive", "composable", "util", "middleware", "hook"];
1999
+ case "add": {
2000
+ const addTypes = [
2001
+ "component",
2002
+ "page",
2003
+ "store",
2004
+ "directive",
2005
+ "composable",
2006
+ "util",
2007
+ "middleware",
2008
+ "hook"
2009
+ ];
1970
2010
  if (!args[0] || !addTypes.includes(args[0])) {
1971
2011
  logger.error("Usage: lyt add <type> <name>");
1972
2012
  logger.info("Types: component, page, store, directive, composable, util, middleware, hook");
@@ -1977,8 +2017,9 @@ async function runCli(rawArgs = process.argv.slice(2)) {
1977
2017
  force: options.force
1978
2018
  });
1979
2019
  break;
2020
+ }
1980
2021
  case "generate":
1981
- case "g":
2022
+ case "g": {
1982
2023
  const genTypes = ["component", "page", "service", "hook", "store"];
1983
2024
  if (!args[0] || !genTypes.includes(args[0])) {
1984
2025
  logger.error("Usage: lyt generate <type> <name>");
@@ -1995,7 +2036,8 @@ async function runCli(rawArgs = process.argv.slice(2)) {
1995
2036
  withStorybook: options.storybook
1996
2037
  });
1997
2038
  break;
1998
- case "plugin":
2039
+ }
2040
+ case "plugin": {
1999
2041
  if (!args[0]) {
2000
2042
  logger.error("Usage: lyt plugin <create|build|validate|templates>");
2001
2043
  logger.info("Example: lyt plugin create my-plugin");
@@ -2032,6 +2074,7 @@ async function runCli(rawArgs = process.argv.slice(2)) {
2032
2074
  process.exit(1);
2033
2075
  }
2034
2076
  break;
2077
+ }
2035
2078
  default:
2036
2079
  if (command) {
2037
2080
  logger.error(`Unknown command: ${command}`);
@@ -2078,7 +2121,7 @@ function parseArgs(args) {
2078
2121
  return { command, args: positional, options };
2079
2122
  }
2080
2123
  function showHelp() {
2081
- console.log(`
2124
+ console.warn(`
2082
2125
  ${logger.bold("LytJS CLI")} v${VERSION}
2083
2126
 
2084
2127
  ${logger.bold("Usage:")}