@typecad/cuttlefish 1.0.0-alpha.6 → 1.0.0-alpha.7

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 (90) hide show
  1. package/dist/api/shared/display-adapter.d.ts +2 -1
  2. package/dist/api/shared/display-adapter.js +8 -1
  3. package/dist/api/shared/display-adapters/sdl.js +9 -2
  4. package/dist/api/shared/display-profile.d.ts +20 -3
  5. package/dist/api/shared/display-profile.js +21 -6
  6. package/dist/api/shared/framework-manifest-registry.d.ts +9 -0
  7. package/dist/api/shared/framework-manifest-registry.js +25 -0
  8. package/dist/api/shared/framework-manifest.d.ts +462 -0
  9. package/dist/api/shared/framework-manifest.js +149 -0
  10. package/dist/api/shared/glcdfont.d.ts +12 -0
  11. package/dist/api/shared/glcdfont.js +124 -0
  12. package/dist/api/shared/graphics-strategy.d.ts +28 -0
  13. package/dist/api/shared/hal-op-ir.d.ts +418 -1
  14. package/dist/api/shared/hal-op-ir.js +95 -1
  15. package/dist/api/shared/index.d.ts +11 -1
  16. package/dist/api/shared/index.js +14 -0
  17. package/dist/api/shared/native-display-op-resolver.d.ts +10 -0
  18. package/dist/api/shared/native-display-op-resolver.js +64 -0
  19. package/dist/api/shared/platform-strategy.d.ts +9 -0
  20. package/dist/api/shared/promise-runtime.js +78 -0
  21. package/dist/api/shared/validate-framework-manifest.d.ts +28 -0
  22. package/dist/api/shared/validate-framework-manifest.js +417 -0
  23. package/dist/cli.js +109 -4
  24. package/dist/config-loader.js +20 -1
  25. package/dist/config-schema.d.ts +36 -36
  26. package/dist/create/board-spec.d.ts +4 -4
  27. package/dist/create/init-scaffold.d.ts +3 -0
  28. package/dist/create/init-scaffold.js +48 -0
  29. package/dist/create/init-templates.d.ts +2 -0
  30. package/dist/create/init-templates.js +28 -8
  31. package/dist/create/init-wizard.js +20 -1
  32. package/dist/emit/cpp-emitter.js +4 -3
  33. package/dist/emit/emitters/emitter-context.d.ts +5 -0
  34. package/dist/emit/emitters/function-emitter-impl.js +69 -59
  35. package/dist/emit/emitters/output-finalizer.d.ts +6 -0
  36. package/dist/emit/emitters/output-finalizer.js +21 -11
  37. package/dist/emit/emitters/setup.js +40 -0
  38. package/dist/emit/emitters/top-level-prep.js +2 -0
  39. package/dist/emit/emitters/ui-emitter.js +23 -8
  40. package/dist/emit/expression-renderer.js +10 -1
  41. package/dist/emit/snprintf-helpers.js +8 -0
  42. package/dist/emit/statement-renderer.js +13 -0
  43. package/dist/emit/utils/async-state-machine.js +185 -116
  44. package/dist/emit/utils/hal-op-cpp-type.d.ts +6 -0
  45. package/dist/emit/utils/hal-op-cpp-type.js +40 -0
  46. package/dist/ir/build-ir.js +5 -1
  47. package/dist/ir/expression-to-ir.js +14 -0
  48. package/dist/ir/feature-registry.js +7 -25
  49. package/dist/ir/hal/hal-emitter.d.ts +5 -2
  50. package/dist/ir/hal/hal-emitter.js +40 -12
  51. package/dist/ir/hal/hal-parser.d.ts +6 -0
  52. package/dist/ir/hal/hal-parser.js +74 -0
  53. package/dist/ir/hal/hal-plugins.js +561 -0
  54. package/dist/ir/identifier-collector.js +18 -0
  55. package/dist/ir/network-validation.d.ts +4 -0
  56. package/dist/ir/network-validation.js +184 -0
  57. package/dist/ir/ownership-analysis.js +14 -1
  58. package/dist/ir/program-analysis.d.ts +23 -0
  59. package/dist/ir/program-analysis.js +81 -2
  60. package/dist/ir/timing-validation.d.ts +6 -1
  61. package/dist/ir/timing-validation.js +50 -12
  62. package/dist/ir/transformers/expressions.js +58 -0
  63. package/dist/ir/transformers/hal-emit-helpers.js +1 -1
  64. package/dist/ir/transformers/variables.js +41 -3
  65. package/dist/ir/validation-orchestrator.js +3 -1
  66. package/dist/libdef/c-to-decl.d.ts +27 -0
  67. package/dist/libdef/c-to-decl.js +397 -0
  68. package/dist/libdef/component-decls.d.ts +2 -0
  69. package/dist/libdef/component-decls.js +6 -0
  70. package/dist/libdef/component-discovery.d.ts +43 -0
  71. package/dist/libdef/component-discovery.js +83 -0
  72. package/dist/libdef/cpp-to-decl.d.ts +9 -0
  73. package/dist/libdef/cpp-to-decl.js +72 -0
  74. package/dist/libdef/idf-discovery.d.ts +7 -0
  75. package/dist/libdef/idf-discovery.js +59 -0
  76. package/dist/libdef/registry.js +5 -2
  77. package/dist/lint-cache.d.ts +59 -0
  78. package/dist/lint-cache.js +257 -0
  79. package/dist/orchestrator/graph-builder.js +6 -2
  80. package/dist/stores/display-profile-store.d.ts +1 -0
  81. package/dist/stores/display-profile-store.js +1 -0
  82. package/dist/testing.d.ts +3 -1
  83. package/dist/testing.js +3 -1
  84. package/dist/transpile.d.ts +3 -0
  85. package/dist/transpile.js +72 -27
  86. package/dist/ui-hook.d.ts +17 -1
  87. package/dist/utils/cli.js +27 -1
  88. package/dist/utils/fs.d.ts +13 -0
  89. package/dist/utils/fs.js +50 -0
  90. package/package.json +8 -4
package/dist/ui-hook.d.ts CHANGED
@@ -58,7 +58,23 @@ export interface TranspilerUIHook {
58
58
  lowerOnMount(htmlPath: string, opts: LowerOptions): LoweredUI;
59
59
  resolveColor(input: string, format: "rgb565" | "rgb666" | "rgb888" | "mono"): number;
60
60
  resolveColorInternal(input: string, format: "rgb565" | "rgb666" | "rgb888" | "mono"): number;
61
- emitRuntimeHeader(): string;
61
+ /**
62
+ * Emits ONLY the CuttlefishGFX class definition (the shared GFX base for
63
+ * native display paths). Called separately from emitRuntimeHeader so the
64
+ * class can be emitted BEFORE display adapter declarations that
65
+ * instantiate CuttlefishGFX by value. Returns "" when active is false
66
+ * (Arduino path).
67
+ */
68
+ emitCuttlefishGfx(active: boolean): string;
69
+ /**
70
+ * Options controlling runtime-header emission.
71
+ * - nativeDisplayActive: when true, emit the shared CuttlefishGFX class
72
+ * (used by native display adapters on AVR/ESP32). Arduino paths pass
73
+ * false (default) and use Adafruit_GFX directly.
74
+ */
75
+ emitRuntimeHeader(opts?: {
76
+ nativeDisplayActive?: boolean;
77
+ }): string;
62
78
  splitUiFile(src: string): UiFileParts;
63
79
  generateProjectUITypeDeclarations(projectRoot: string): {
64
80
  written: string[];
package/dist/utils/cli.js CHANGED
@@ -431,12 +431,16 @@ export function parseCommandLine(argv) {
431
431
  // gen-decls - generate .d.ts from C++ files
432
432
  if (command === "gen-decls") {
433
433
  const allFlag = argv.includes("--all");
434
+ const componentsFlag = argv.includes("--components");
435
+ if (allFlag && componentsFlag) {
436
+ throw new Error("gen-decls: --components and --all are mutually exclusive. Use one or the other.");
437
+ }
434
438
  // The positional path may sit at argv[3] or argv[4] depending on whether
435
439
  // --all precedes or follows it. Scan argv starting after the subcommand
436
440
  // name (argv[2]) for the first token that is not a flag and not a known
437
441
  // flag's value. This mirrors the default-pipeline approach of "first
438
442
  // non-flag token wins".
439
- const booleanFlags = new Set(["--all"]);
443
+ const booleanFlags = new Set(["--all", "--components"]);
440
444
  const valueFlags = new Set([
441
445
  "--emit", "--target", "--outDir", "--out-dir", "--emit-maps", "--build-target",
442
446
  ]);
@@ -457,6 +461,28 @@ export function parseCommandLine(argv) {
457
461
  inputPath = tok;
458
462
  break;
459
463
  }
464
+ // --components mode: scan managed_components/ + components/ declared in
465
+ // cuttlefish.config.ts. Falls back to cwd when no path is given.
466
+ if (componentsFlag) {
467
+ const componentsDir = inputPath || process.cwd();
468
+ return {
469
+ command: "gen-decls",
470
+ inputFile: undefined,
471
+ emitMode,
472
+ target,
473
+ outDir: outDir ? path.resolve(process.cwd(), outDir) : undefined,
474
+ emitMaps,
475
+ noTranspile: false,
476
+ compile: false,
477
+ upload: false,
478
+ monitor: false,
479
+ watch: false,
480
+ baud: 9600,
481
+ platformContext,
482
+ scanDir: undefined,
483
+ componentsDir: path.resolve(process.cwd(), componentsDir),
484
+ };
485
+ }
460
486
  if (!inputPath && !allFlag) {
461
487
  throw new Error("Missing input C++ file path. Use: gen-decls <file.cpp> or gen-decls --all <directory>");
462
488
  }
@@ -2,3 +2,16 @@ export declare function ensureDir(dirPath: string): void;
2
2
  export declare function readText(filePath: string): string;
3
3
  export declare function writeText(filePath: string, content: string): void;
4
4
  export declare function listFiles(dirPath: string, extension: string): string[];
5
+ /**
6
+ * Recursive variant of {@link listFiles}. Walks `dirPath` depth-first and
7
+ * returns every file (in every subdirectory) whose name ends with `extension`.
8
+ *
9
+ * Used by {@link loadLibraryDefinitions} so libdefs under nested cache dirs
10
+ * like `.cuttlefish/component-decls/<component>/` are discovered. Purely
11
+ * additive vs. the non-recursive `listFiles` — single-level layouts keep
12
+ * working, nested layouts now also work.
13
+ *
14
+ * Returns absolute paths. Unreadable directories are silently skipped
15
+ * (matches `listFiles`'s not-exist behavior for non-existent roots).
16
+ */
17
+ export declare function listFilesRecursive(dirPath: string, extension: string): string[];
package/dist/utils/fs.js CHANGED
@@ -10,6 +10,15 @@ export function readText(filePath) {
10
10
  }
11
11
  export function writeText(filePath, content) {
12
12
  ensureDir(path.dirname(filePath));
13
+ // Skip writing when content is identical — preserves mtime so downstream
14
+ // build tools (idf.py/ninja, arduino-cli, make) can skip recompilation.
15
+ try {
16
+ if (fs.readFileSync(filePath, "utf8") === content)
17
+ return;
18
+ }
19
+ catch {
20
+ // File doesn't exist yet — fall through to write.
21
+ }
13
22
  fs.writeFileSync(filePath, content, "utf8");
14
23
  }
15
24
  export function listFiles(dirPath, extension) {
@@ -21,3 +30,44 @@ export function listFiles(dirPath, extension) {
21
30
  .filter((name) => name.toLowerCase().endsWith(extension.toLowerCase()))
22
31
  .map((name) => path.join(dirPath, name));
23
32
  }
33
+ /**
34
+ * Recursive variant of {@link listFiles}. Walks `dirPath` depth-first and
35
+ * returns every file (in every subdirectory) whose name ends with `extension`.
36
+ *
37
+ * Used by {@link loadLibraryDefinitions} so libdefs under nested cache dirs
38
+ * like `.cuttlefish/component-decls/<component>/` are discovered. Purely
39
+ * additive vs. the non-recursive `listFiles` — single-level layouts keep
40
+ * working, nested layouts now also work.
41
+ *
42
+ * Returns absolute paths. Unreadable directories are silently skipped
43
+ * (matches `listFiles`'s not-exist behavior for non-existent roots).
44
+ */
45
+ export function listFilesRecursive(dirPath, extension) {
46
+ if (!fs.existsSync(dirPath)) {
47
+ return [];
48
+ }
49
+ const ext = extension.toLowerCase();
50
+ const out = [];
51
+ const stack = [dirPath];
52
+ while (stack.length > 0) {
53
+ const cur = stack.pop();
54
+ let entries;
55
+ try {
56
+ entries = fs.readdirSync(cur, { withFileTypes: true });
57
+ }
58
+ catch {
59
+ // Permission error / race / etc. Skip this subtree.
60
+ continue;
61
+ }
62
+ for (const entry of entries) {
63
+ const full = path.join(cur, entry.name);
64
+ if (entry.isDirectory()) {
65
+ stack.push(full);
66
+ }
67
+ else if (entry.isFile() && entry.name.toLowerCase().endsWith(ext)) {
68
+ out.push(full);
69
+ }
70
+ }
71
+ }
72
+ return out;
73
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typecad/cuttlefish",
3
- "version": "1.0.0-alpha.6",
3
+ "version": "1.0.0-alpha.7",
4
4
  "description": "TypeScript to C++ transpiler — native, Arduino, and bare-metal targets",
5
5
  "type": "module",
6
6
  "main": "./dist/transpile.js",
@@ -49,6 +49,10 @@
49
49
  "types": "./dist/emit/route-hal-op.d.ts",
50
50
  "default": "./dist/emit/route-hal-op.js"
51
51
  },
52
+ "./lib/component-decls": {
53
+ "types": "./dist/libdef/component-decls.d.ts",
54
+ "default": "./dist/libdef/component-decls.js"
55
+ },
52
56
  "./ir/transformers/ui-lowering": {
53
57
  "types": "./dist/ir/transformers/ui-lowering.d.ts",
54
58
  "default": "./dist/ir/transformers/ui-lowering.js"
@@ -81,10 +85,10 @@
81
85
  "chalk": "^4.1.2",
82
86
  "typescript": "^5.7.3",
83
87
  "zod": "^3.24.0",
84
- "@typecad/arduino-cli": "1.0.0-alpha.6"
88
+ "@typecad/arduino-cli": "1.0.0-alpha.7"
85
89
  },
86
90
  "peerDependencies": {
87
- "@typecad/ui": "1.0.0-alpha.6"
91
+ "@typecad/ui": "1.0.0-alpha.7"
88
92
  },
89
93
  "peerDependenciesMeta": {
90
94
  "@typecad/ui": {
@@ -92,7 +96,7 @@
92
96
  }
93
97
  },
94
98
  "optionalDependencies": {
95
- "@typecad/framework-native": "1.0.0-alpha.6"
99
+ "@typecad/framework-native": "1.0.0-alpha.7"
96
100
  },
97
101
  "devDependencies": {
98
102
  "@types/node": "^22.10.7"