@object-ui/cli 0.3.0 → 0.5.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/cli.js CHANGED
@@ -6,11 +6,11 @@ import {
6
6
  parseSchemaFile,
7
7
  scanPagesDirectory,
8
8
  serve
9
- } from "./chunk-WOV6EOMH.js";
9
+ } from "./chunk-O3QIU2WQ.js";
10
10
 
11
11
  // src/cli.ts
12
12
  import { Command } from "commander";
13
- import chalk11 from "chalk";
13
+ import chalk14 from "chalk";
14
14
 
15
15
  // src/commands/dev.ts
16
16
  import { createServer } from "vite";
@@ -130,7 +130,14 @@ Run 'objectui init' to create a sample schema.`);
130
130
  "@object-ui/react": join(cwd, "packages/react/src/index.ts"),
131
131
  "@object-ui/components": join(cwd, "packages/components/src/index.ts"),
132
132
  "@object-ui/core": join(cwd, "packages/core/src/index.ts"),
133
- "@object-ui/types": join(cwd, "packages/types/src/index.ts")
133
+ "@object-ui/types": join(cwd, "packages/types/src/index.ts"),
134
+ "@object-ui/plugin-charts": join(cwd, "packages/plugin-charts/src/index.tsx"),
135
+ "@object-ui/plugin-editor": join(cwd, "packages/plugin-editor/src/index.tsx"),
136
+ "@object-ui/plugin-kanban": join(cwd, "packages/plugin-kanban/src/index.tsx"),
137
+ "@object-ui/plugin-markdown": join(cwd, "packages/plugin-markdown/src/index.tsx"),
138
+ "@object-ui/plugin-form": join(cwd, "packages/plugin-form/src/index.tsx"),
139
+ "@object-ui/plugin-grid": join(cwd, "packages/plugin-grid/src/index.tsx"),
140
+ "@object-ui/plugin-view": join(cwd, "packages/plugin-view/src/index.tsx")
134
141
  };
135
142
  try {
136
143
  const lucidePath = require2.resolve("lucide-react", { paths: [join(cwd, "packages/components")] });
@@ -588,14 +595,215 @@ async function check() {
588
595
  }
589
596
  }
590
597
 
591
- // src/cli.ts
592
- import { readFileSync as readFileSync3 } from "fs";
598
+ // src/commands/validate.ts
599
+ import chalk11 from "chalk";
600
+ import { readFileSync as readFileSync3, existsSync as existsSync8 } from "fs";
601
+ import { resolve as resolve4 } from "path";
602
+ import { load as loadYaml } from "js-yaml";
603
+ import { safeValidateSchema } from "@object-ui/types/zod";
604
+ async function validate(schemaPath) {
605
+ console.log(chalk11.blue("\u{1F50D} ObjectUI Schema Validator\n"));
606
+ const resolvedPath = resolve4(process.cwd(), schemaPath);
607
+ if (!existsSync8(resolvedPath)) {
608
+ console.error(chalk11.red(`\u2717 Error: Schema file not found: ${schemaPath}`));
609
+ process.exit(1);
610
+ }
611
+ try {
612
+ const fileContent = readFileSync3(resolvedPath, "utf-8");
613
+ let schema;
614
+ if (schemaPath.endsWith(".yaml") || schemaPath.endsWith(".yml")) {
615
+ console.log(chalk11.gray(`Reading YAML schema from: ${schemaPath}`));
616
+ schema = loadYaml(fileContent);
617
+ } else if (schemaPath.endsWith(".json")) {
618
+ console.log(chalk11.gray(`Reading JSON schema from: ${schemaPath}`));
619
+ schema = JSON.parse(fileContent);
620
+ } else {
621
+ try {
622
+ schema = JSON.parse(fileContent);
623
+ console.log(chalk11.gray(`Reading schema from: ${schemaPath} (detected as JSON)`));
624
+ } catch {
625
+ schema = loadYaml(fileContent);
626
+ console.log(chalk11.gray(`Reading schema from: ${schemaPath} (detected as YAML)`));
627
+ }
628
+ }
629
+ console.log(chalk11.gray("Validating schema...\n"));
630
+ const result = safeValidateSchema(schema);
631
+ if (result.success) {
632
+ console.log(chalk11.green("\u2713 Schema is valid!\n"));
633
+ const data = result.data;
634
+ console.log(chalk11.bold("Schema Information:"));
635
+ console.log(chalk11.gray(" Type:"), data.type || "unknown");
636
+ if (data.id) {
637
+ console.log(chalk11.gray(" ID:"), data.id);
638
+ }
639
+ if (data.label || data.title) {
640
+ console.log(chalk11.gray(" Label:"), data.label || data.title);
641
+ }
642
+ if (data.children && Array.isArray(data.children)) {
643
+ console.log(chalk11.gray(" Children:"), data.children.length);
644
+ }
645
+ console.log("");
646
+ process.exit(0);
647
+ } else {
648
+ console.error(chalk11.red("\u2717 Schema validation failed!\n"));
649
+ console.error(chalk11.bold("Validation Errors:"));
650
+ const errors = result.error.errors;
651
+ errors.forEach((error, index) => {
652
+ console.error(chalk11.red(`
653
+ ${index + 1}. ${error.message}`));
654
+ if (error.path && error.path.length > 0) {
655
+ console.error(chalk11.gray(` Path: ${error.path.join(" \u2192 ")}`));
656
+ }
657
+ if (error.code) {
658
+ console.error(chalk11.gray(` Code: ${error.code}`));
659
+ }
660
+ });
661
+ console.error("");
662
+ process.exit(1);
663
+ }
664
+ } catch (error) {
665
+ console.error(chalk11.red("\n\u2717 Error reading or parsing schema file:"));
666
+ console.error(chalk11.red(error.message));
667
+ console.error("");
668
+ process.exit(1);
669
+ }
670
+ }
671
+
672
+ // src/commands/create-plugin.ts
673
+ import chalk12 from "chalk";
674
+ import { spawn } from "child_process";
675
+ import { resolve as resolve5, dirname as dirname2 } from "path";
593
676
  import { fileURLToPath } from "url";
594
- import { dirname as dirname2, join as join9 } from "path";
595
677
  var __filename = fileURLToPath(import.meta.url);
596
678
  var __dirname = dirname2(__filename);
679
+ async function createPlugin(pluginName) {
680
+ console.log(chalk12.blue("\u{1F680} Creating ObjectUI plugin...\n"));
681
+ const createPluginScript = resolve5(
682
+ __dirname,
683
+ "../../../create-plugin/dist/index.js"
684
+ );
685
+ return new Promise((resolve7, reject) => {
686
+ const child = spawn("node", [createPluginScript, pluginName], {
687
+ stdio: "inherit",
688
+ shell: true
689
+ });
690
+ child.on("error", (error) => {
691
+ console.error(chalk12.red("Failed to create plugin:"), error);
692
+ reject(error);
693
+ });
694
+ child.on("exit", (code) => {
695
+ if (code === 0) {
696
+ resolve7();
697
+ } else {
698
+ reject(new Error(`create-plugin exited with code ${code}`));
699
+ }
700
+ });
701
+ });
702
+ }
703
+
704
+ // src/commands/analyze.ts
705
+ import chalk13 from "chalk";
706
+ import { existsSync as existsSync9, statSync as statSync2, readdirSync } from "fs";
707
+ import { resolve as resolve6, join as join9, extname } from "path";
708
+ async function analyzeBundleSize() {
709
+ console.log(chalk13.bold("\n\u{1F4E6} Bundle Size Analysis\n"));
710
+ const distDir = resolve6(process.cwd(), "dist");
711
+ if (!existsSync9(distDir)) {
712
+ console.log(chalk13.yellow("\u26A0 No dist directory found. Run build first."));
713
+ return;
714
+ }
715
+ const files = [];
716
+ function scanDirectory(dir) {
717
+ const items = readdirSync(dir);
718
+ for (const item of items) {
719
+ const fullPath = join9(dir, item);
720
+ const stat = statSync2(fullPath);
721
+ if (stat.isDirectory()) {
722
+ scanDirectory(fullPath);
723
+ } else {
724
+ files.push({
725
+ path: fullPath.replace(distDir + "/", ""),
726
+ size: stat.size
727
+ });
728
+ }
729
+ }
730
+ }
731
+ scanDirectory(distDir);
732
+ files.sort((a, b) => b.size - a.size);
733
+ const totalSize = files.reduce((sum, file) => sum + file.size, 0);
734
+ const jsFiles = files.filter((f) => extname(f.path) === ".js");
735
+ const cssFiles = files.filter((f) => extname(f.path) === ".css");
736
+ const jsSize = jsFiles.reduce((sum, file) => sum + file.size, 0);
737
+ const cssSize = cssFiles.reduce((sum, file) => sum + file.size, 0);
738
+ console.log(chalk13.bold("Summary:"));
739
+ console.log(chalk13.gray(" Total Size:"), formatBytes(totalSize));
740
+ console.log(chalk13.gray(" JavaScript:"), formatBytes(jsSize), chalk13.dim(`(${jsFiles.length} files)`));
741
+ console.log(chalk13.gray(" CSS: "), formatBytes(cssSize), chalk13.dim(`(${cssFiles.length} files)`));
742
+ console.log(chalk13.gray(" Other: "), formatBytes(totalSize - jsSize - cssSize));
743
+ console.log(chalk13.bold("\nLargest Files:"));
744
+ files.slice(0, 10).forEach((file) => {
745
+ const sizeStr = formatBytes(file.size).padStart(10);
746
+ console.log(chalk13.gray(` ${sizeStr}`), file.path);
747
+ });
748
+ console.log(chalk13.bold("\n\u{1F4A1} Recommendations:"));
749
+ if (totalSize > 1024 * 1024) {
750
+ console.log(chalk13.yellow(" \u26A0 Total bundle size is large (> 1MB)"));
751
+ console.log(chalk13.gray(" Consider code splitting or lazy loading"));
752
+ }
753
+ if (jsSize > 500 * 1024) {
754
+ console.log(chalk13.yellow(" \u26A0 JavaScript bundle is large (> 500KB)"));
755
+ console.log(chalk13.gray(" Consider:"));
756
+ console.log(chalk13.gray(" - Tree shaking unused code"));
757
+ console.log(chalk13.gray(" - Lazy loading components"));
758
+ console.log(chalk13.gray(" - Using dynamic imports"));
759
+ }
760
+ if (files.length > 100) {
761
+ console.log(chalk13.yellow(` \u26A0 Large number of files (${files.length})`));
762
+ console.log(chalk13.gray(" Consider bundling or combining files"));
763
+ }
764
+ console.log("");
765
+ }
766
+ async function analyzeRenderPerformance() {
767
+ console.log(chalk13.bold("\n\u26A1 Render Performance Analysis\n"));
768
+ console.log(chalk13.gray("Performance analysis features:"));
769
+ console.log(chalk13.gray(" \u2713 Expression caching enabled"));
770
+ console.log(chalk13.gray(" \u2713 Component memoization available"));
771
+ console.log(chalk13.gray(" \u2713 Virtual scrolling support for large lists"));
772
+ console.log(chalk13.bold("\n\u{1F4A1} Performance Tips:"));
773
+ console.log(chalk13.gray(" \u2022 Use virtual scrolling for lists > 100 items"));
774
+ console.log(chalk13.gray(" \u2022 Cache frequently evaluated expressions"));
775
+ console.log(chalk13.gray(" \u2022 Use React.memo for expensive components"));
776
+ console.log(chalk13.gray(" \u2022 Implement pagination for large datasets"));
777
+ console.log(chalk13.gray(" \u2022 Use code splitting for large apps"));
778
+ console.log("");
779
+ }
780
+ function formatBytes(bytes) {
781
+ if (bytes === 0) return "0 B";
782
+ const k = 1024;
783
+ const sizes = ["B", "KB", "MB", "GB"];
784
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
785
+ return `${(bytes / Math.pow(k, i)).toFixed(2)} ${sizes[i]}`;
786
+ }
787
+ async function analyze(options = {}) {
788
+ console.log(chalk13.blue("\u{1F50D} ObjectUI Performance Analyzer\n"));
789
+ const runAll = !options.bundleSize && !options.renderPerformance;
790
+ if (options.bundleSize || runAll) {
791
+ await analyzeBundleSize();
792
+ }
793
+ if (options.renderPerformance || runAll) {
794
+ await analyzeRenderPerformance();
795
+ }
796
+ console.log(chalk13.green("\u2713 Analysis complete!\n"));
797
+ }
798
+
799
+ // src/cli.ts
800
+ import { readFileSync as readFileSync4 } from "fs";
801
+ import { fileURLToPath as fileURLToPath2 } from "url";
802
+ import { dirname as dirname3, join as join10 } from "path";
803
+ var __filename2 = fileURLToPath2(import.meta.url);
804
+ var __dirname2 = dirname3(__filename2);
597
805
  var packageJson = JSON.parse(
598
- readFileSync3(join9(__dirname, "../package.json"), "utf-8")
806
+ readFileSync4(join10(__dirname2, "../package.json"), "utf-8")
599
807
  );
600
808
  var program = new Command();
601
809
  program.name("objectui").description("CLI tool for Object UI - Build applications from JSON schemas").version(packageJson.version);
@@ -603,7 +811,7 @@ program.command("serve").description("Start a development server with your JSON/
603
811
  try {
604
812
  await serve(schema, options);
605
813
  } catch (error) {
606
- console.error(chalk11.red("Error:"), error instanceof Error ? error.message : error);
814
+ console.error(chalk14.red("Error:"), error instanceof Error ? error.message : error);
607
815
  process.exit(1);
608
816
  }
609
817
  });
@@ -611,7 +819,7 @@ program.command("dev").description("Start development server (alias for serve)")
611
819
  try {
612
820
  await dev(schema, options);
613
821
  } catch (error) {
614
- console.error(chalk11.red("Error:"), error instanceof Error ? error.message : error);
822
+ console.error(chalk14.red("Error:"), error instanceof Error ? error.message : error);
615
823
  process.exit(1);
616
824
  }
617
825
  });
@@ -619,7 +827,7 @@ program.command("build").description("Build application for production").argumen
619
827
  try {
620
828
  await buildApp(schema, options);
621
829
  } catch (error) {
622
- console.error(chalk11.red("Error:"), error instanceof Error ? error.message : error);
830
+ console.error(chalk14.red("Error:"), error instanceof Error ? error.message : error);
623
831
  process.exit(1);
624
832
  }
625
833
  });
@@ -627,7 +835,7 @@ program.command("start").description("Start production server").option("-p, --po
627
835
  try {
628
836
  await start(options);
629
837
  } catch (error) {
630
- console.error(chalk11.red("Error:"), error instanceof Error ? error.message : error);
838
+ console.error(chalk14.red("Error:"), error instanceof Error ? error.message : error);
631
839
  process.exit(1);
632
840
  }
633
841
  });
@@ -635,7 +843,7 @@ program.command("init").description("\u521D\u59CB\u5316\u65B0\u7684Object UI\u5E
635
843
  try {
636
844
  await init(name, options);
637
845
  } catch (error) {
638
- console.error(chalk11.red("\u9519\u8BEF Error:"), error instanceof Error ? error.message : error);
846
+ console.error(chalk14.red("\u9519\u8BEF Error:"), error instanceof Error ? error.message : error);
639
847
  process.exit(1);
640
848
  }
641
849
  });
@@ -643,7 +851,7 @@ program.command("lint").description("Lint the generated application code").optio
643
851
  try {
644
852
  await lint(options);
645
853
  } catch (error) {
646
- console.error(chalk11.red("Error:"), error instanceof Error ? error.message : error);
854
+ console.error(chalk14.red("Error:"), error instanceof Error ? error.message : error);
647
855
  process.exit(1);
648
856
  }
649
857
  });
@@ -651,15 +859,20 @@ program.command("test").description("Run tests for the application").option("-w,
651
859
  try {
652
860
  await test(options);
653
861
  } catch (error) {
654
- console.error(chalk11.red("Error:"), error instanceof Error ? error.message : error);
862
+ console.error(chalk14.red("Error:"), error instanceof Error ? error.message : error);
655
863
  process.exit(1);
656
864
  }
657
865
  });
658
- program.command("generate").alias("g").description("Generate new resources (objects, pages, plugins)").argument("<type>", "Type of resource to generate (resource/object, page, plugin)").argument("<name>", "Name of the resource").action(async (type, name) => {
866
+ program.command("generate").alias("g").description("Generate new resources (objects, pages, plugins)").argument("<type>", "Type of resource to generate (resource/object, page, plugin)").argument("<name>", "Name of the resource").option("--from <source>", "Generate schema from external source (openapi.yaml, prisma.schema)").option("--output <dir>", "Output directory for generated schemas", "schemas/").action(async (type, name, options) => {
659
867
  try {
868
+ if (options.from) {
869
+ console.log(chalk14.yellow("\n\u26A0 Schema generation from external sources (OpenAPI/Prisma) is not yet implemented."));
870
+ console.log(chalk14.gray("This feature will be available in a future release.\n"));
871
+ process.exit(0);
872
+ }
660
873
  await generate(type, name);
661
874
  } catch (error) {
662
- console.error(chalk11.red("Error:"), error instanceof Error ? error.message : error);
875
+ console.error(chalk14.red("Error:"), error instanceof Error ? error.message : error);
663
876
  process.exit(1);
664
877
  }
665
878
  });
@@ -667,7 +880,7 @@ program.command("doctor").description("Diagnose and fix common issues").action(a
667
880
  try {
668
881
  await doctor();
669
882
  } catch (error) {
670
- console.error(chalk11.red("Error:"), error instanceof Error ? error.message : error);
883
+ console.error(chalk14.red("Error:"), error instanceof Error ? error.message : error);
671
884
  process.exit(1);
672
885
  }
673
886
  });
@@ -675,7 +888,7 @@ program.command("add").description("Add a new component renderer to your project
675
888
  try {
676
889
  await add(component);
677
890
  } catch (error) {
678
- console.error(chalk11.red("Error:"), error instanceof Error ? error.message : error);
891
+ console.error(chalk14.red("Error:"), error instanceof Error ? error.message : error);
679
892
  process.exit(1);
680
893
  }
681
894
  });
@@ -683,7 +896,7 @@ program.command("studio").description("Start the visual designer").action(async
683
896
  try {
684
897
  await studio();
685
898
  } catch (error) {
686
- console.error(chalk11.red("Error:"), error instanceof Error ? error.message : error);
899
+ console.error(chalk14.red("Error:"), error instanceof Error ? error.message : error);
687
900
  process.exit(1);
688
901
  }
689
902
  });
@@ -691,16 +904,37 @@ program.command("check").description("Validate schema files").action(async () =>
691
904
  try {
692
905
  await check();
693
906
  } catch (error) {
694
- console.error(chalk11.red("Error:"), error instanceof Error ? error.message : error);
907
+ console.error(chalk14.red("Error:"), error instanceof Error ? error.message : error);
908
+ process.exit(1);
909
+ }
910
+ });
911
+ program.command("validate").description("Validate a schema file against ObjectUI specifications").argument("[schema]", "Path to schema file (JSON or YAML)", "app.json").action(async (schema) => {
912
+ try {
913
+ await validate(schema);
914
+ } catch (error) {
915
+ console.error(chalk14.red("Error:"), error instanceof Error ? error.message : error);
916
+ process.exit(1);
917
+ }
918
+ });
919
+ program.command("create").description("Create new resources").argument("<type>", "Type of resource to create (plugin)").argument("<name>", "Name of the resource").action(async (type, name) => {
920
+ try {
921
+ if (type === "plugin") {
922
+ await createPlugin(name);
923
+ } else {
924
+ console.error(chalk14.red(`Unknown resource type: ${type}`));
925
+ console.log(chalk14.gray("Available types: plugin"));
926
+ process.exit(1);
927
+ }
928
+ } catch (error) {
929
+ console.error(chalk14.red("Error:"), error instanceof Error ? error.message : error);
695
930
  process.exit(1);
696
931
  }
697
932
  });
698
- program.command("showcase").description("Start the built-in showcase example").option("-p, --port <port>", "Port to run the server on", "3000").option("-h, --host <host>", "Host to bind the server to", "localhost").option("--no-open", "Do not open browser automatically").action(async (options) => {
933
+ program.command("analyze").description("Analyze application performance").option("--bundle-size", "Analyze bundle size").option("--render-performance", "Analyze render performance").action(async (options) => {
699
934
  try {
700
- const showcaseSchema = join9(__dirname, "../../..", "examples", "showcase", "app.json");
701
- await dev(showcaseSchema, options);
935
+ await analyze(options);
702
936
  } catch (error) {
703
- console.error(chalk11.red("Error:"), error instanceof Error ? error.message : error);
937
+ console.error(chalk14.red("Error:"), error instanceof Error ? error.message : error);
704
938
  process.exit(1);
705
939
  }
706
940
  });