@typecad/cuttlefish 0.1.0-alpha.1
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/LICENSE +21 -0
- package/README.md +79 -0
- package/dist/api/board-types.d.ts +1 -0
- package/dist/api/board-types.js +4 -0
- package/dist/api/capabilities.d.ts +12 -0
- package/dist/api/capabilities.js +1 -0
- package/dist/api/config.d.ts +120 -0
- package/dist/api/config.js +7 -0
- package/dist/api/index.d.ts +5 -0
- package/dist/api/index.js +2 -0
- package/dist/api/schema/builder.d.ts +14 -0
- package/dist/api/schema/builder.js +15 -0
- package/dist/api/schema/index.d.ts +2 -0
- package/dist/api/schema/index.js +1 -0
- package/dist/api/schema/types.d.ts +257 -0
- package/dist/api/schema/types.js +4 -0
- package/dist/api/shared/async-runtime-static.d.ts +8 -0
- package/dist/api/shared/async-runtime-static.js +201 -0
- package/dist/api/shared/async-types.d.ts +42 -0
- package/dist/api/shared/async-types.js +8 -0
- package/dist/api/shared/board-resolver.d.ts +12 -0
- package/dist/api/shared/board-resolver.js +7 -0
- package/dist/api/shared/cpp-type-ir.d.ts +229 -0
- package/dist/api/shared/cpp-type-ir.js +672 -0
- package/dist/api/shared/display-adapter.d.ts +12 -0
- package/dist/api/shared/display-adapter.js +145 -0
- package/dist/api/shared/display-adapters/eink-mono.d.ts +2 -0
- package/dist/api/shared/display-adapters/eink-mono.js +53 -0
- package/dist/api/shared/display-adapters/sdl.d.ts +2 -0
- package/dist/api/shared/display-adapters/sdl.js +452 -0
- package/dist/api/shared/display-adapters/ssd1309.d.ts +2 -0
- package/dist/api/shared/display-adapters/ssd1309.js +136 -0
- package/dist/api/shared/display-adapters/st7796.d.ts +2 -0
- package/dist/api/shared/display-adapters/st7796.js +132 -0
- package/dist/api/shared/display-capabilities.d.ts +45 -0
- package/dist/api/shared/display-capabilities.js +54 -0
- package/dist/api/shared/display-op-ir.d.ts +62 -0
- package/dist/api/shared/display-op-ir.js +19 -0
- package/dist/api/shared/display-profile.d.ts +265 -0
- package/dist/api/shared/display-profile.js +338 -0
- package/dist/api/shared/graphics-strategy.d.ts +29 -0
- package/dist/api/shared/graphics-strategy.js +11 -0
- package/dist/api/shared/hal-op-ir.d.ts +393 -0
- package/dist/api/shared/hal-op-ir.js +18 -0
- package/dist/api/shared/index.d.ts +26 -0
- package/dist/api/shared/index.js +21 -0
- package/dist/api/shared/ir-core.d.ts +363 -0
- package/dist/api/shared/ir-core.js +8 -0
- package/dist/api/shared/ir-declarations.d.ts +201 -0
- package/dist/api/shared/ir-declarations.js +26 -0
- package/dist/api/shared/ir.d.ts +85 -0
- package/dist/api/shared/ir.js +13 -0
- package/dist/api/shared/platform-strategy.d.ts +402 -0
- package/dist/api/shared/platform-strategy.js +14 -0
- package/dist/api/shared/polyfill-helper-registry.d.ts +11 -0
- package/dist/api/shared/polyfill-helper-registry.js +86 -0
- package/dist/api/shared/polyfill-types.d.ts +33 -0
- package/dist/api/shared/polyfill-types.js +76 -0
- package/dist/api/shared/promise-runtime.d.ts +10 -0
- package/dist/api/shared/promise-runtime.js +244 -0
- package/dist/api/shared/snprintf-types.d.ts +29 -0
- package/dist/api/shared/snprintf-types.js +8 -0
- package/dist/api/shared/string-method-registry.d.ts +53 -0
- package/dist/api/shared/string-method-registry.js +168 -0
- package/dist/api/shared/toolchain-types.d.ts +63 -0
- package/dist/api/shared/toolchain-types.js +71 -0
- package/dist/api/shared/types.d.ts +50 -0
- package/dist/api/shared/types.js +6 -0
- package/dist/ast/parse.d.ts +2 -0
- package/dist/ast/parse.js +4 -0
- package/dist/cache.d.ts +26 -0
- package/dist/cache.js +95 -0
- package/dist/cli-utils.d.ts +37 -0
- package/dist/cli-utils.js +250 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +635 -0
- package/dist/config-loader.d.ts +78 -0
- package/dist/config-loader.js +508 -0
- package/dist/config-schema.d.ts +233 -0
- package/dist/config-schema.js +83 -0
- package/dist/create/board-checklist.d.ts +2 -0
- package/dist/create/board-checklist.js +52 -0
- package/dist/create/board-codegen.d.ts +9 -0
- package/dist/create/board-codegen.js +238 -0
- package/dist/create/board-generators.d.ts +12 -0
- package/dist/create/board-generators.js +652 -0
- package/dist/create/board-spec.d.ts +640 -0
- package/dist/create/board-spec.js +215 -0
- package/dist/create/eslint-rules-template.d.ts +2 -0
- package/dist/create/eslint-rules-template.js +672 -0
- package/dist/create/index.d.ts +11 -0
- package/dist/create/index.js +8 -0
- package/dist/create/init-scaffold.d.ts +27 -0
- package/dist/create/init-scaffold.js +150 -0
- package/dist/create/init-templates.d.ts +24 -0
- package/dist/create/init-templates.js +379 -0
- package/dist/create/init-wizard.d.ts +8 -0
- package/dist/create/init-wizard.js +168 -0
- package/dist/debug/breakpoint-loader.d.ts +24 -0
- package/dist/debug/breakpoint-loader.js +137 -0
- package/dist/debug/index.d.ts +3 -0
- package/dist/debug/index.js +7 -0
- package/dist/debug/preprocessor.d.ts +9 -0
- package/dist/debug/preprocessor.js +214 -0
- package/dist/debug/types.d.ts +32 -0
- package/dist/debug/types.js +6 -0
- package/dist/diagnostics/diagnostics-report.d.ts +51 -0
- package/dist/diagnostics/diagnostics-report.js +333 -0
- package/dist/diagnostics/json-schema.d.ts +138 -0
- package/dist/diagnostics/json-schema.js +27 -0
- package/dist/diagnostics/md-writer.d.ts +10 -0
- package/dist/diagnostics/md-writer.js +336 -0
- package/dist/diagnostics/mermaid-builder.d.ts +65 -0
- package/dist/diagnostics/mermaid-builder.js +681 -0
- package/dist/emit/cpp-emitter.d.ts +6 -0
- package/dist/emit/cpp-emitter.js +48 -0
- package/dist/emit/emitters/class-emitter.d.ts +2 -0
- package/dist/emit/emitters/class-emitter.js +523 -0
- package/dist/emit/emitters/emitter-context.d.ts +174 -0
- package/dist/emit/emitters/emitter-context.js +1 -0
- package/dist/emit/emitters/entrypoint-synthesizer.d.ts +2 -0
- package/dist/emit/emitters/entrypoint-synthesizer.js +175 -0
- package/dist/emit/emitters/function-emitter-impl.d.ts +19 -0
- package/dist/emit/emitters/function-emitter-impl.js +428 -0
- package/dist/emit/emitters/line-appender.d.ts +15 -0
- package/dist/emit/emitters/line-appender.js +344 -0
- package/dist/emit/emitters/namespace-emitter.d.ts +2 -0
- package/dist/emit/emitters/namespace-emitter.js +324 -0
- package/dist/emit/emitters/output-finalizer.d.ts +4 -0
- package/dist/emit/emitters/output-finalizer.js +267 -0
- package/dist/emit/emitters/setup.d.ts +3 -0
- package/dist/emit/emitters/setup.js +851 -0
- package/dist/emit/emitters/top-level-prep.d.ts +2 -0
- package/dist/emit/emitters/top-level-prep.js +706 -0
- package/dist/emit/emitters/type-decl-emitter.d.ts +2 -0
- package/dist/emit/emitters/type-decl-emitter.js +251 -0
- package/dist/emit/emitters/ui-emitter.d.ts +21 -0
- package/dist/emit/emitters/ui-emitter.js +564 -0
- package/dist/emit/enum-emitter.d.ts +1 -0
- package/dist/emit/enum-emitter.js +1 -0
- package/dist/emit/expression-renderer.d.ts +283 -0
- package/dist/emit/expression-renderer.js +1477 -0
- package/dist/emit/native-helpers-emitter.d.ts +11 -0
- package/dist/emit/native-helpers-emitter.js +34 -0
- package/dist/emit/route-hal-op.d.ts +5 -0
- package/dist/emit/route-hal-op.js +13 -0
- package/dist/emit/snprintf-helpers.d.ts +17 -0
- package/dist/emit/snprintf-helpers.js +462 -0
- package/dist/emit/statement-renderer.d.ts +189 -0
- package/dist/emit/statement-renderer.js +948 -0
- package/dist/emit/utils/async-state-machine.d.ts +42 -0
- package/dist/emit/utils/async-state-machine.js +343 -0
- package/dist/emit/utils/comment-helpers.d.ts +20 -0
- package/dist/emit/utils/comment-helpers.js +31 -0
- package/dist/emit/utils/cpp-helpers.d.ts +47 -0
- package/dist/emit/utils/cpp-helpers.js +85 -0
- package/dist/emit/utils/include-resolver.d.ts +58 -0
- package/dist/emit/utils/include-resolver.js +155 -0
- package/dist/emit/utils/index.d.ts +8 -0
- package/dist/emit/utils/index.js +12 -0
- package/dist/emit/utils/type-inference.d.ts +159 -0
- package/dist/emit/utils/type-inference.js +559 -0
- package/dist/eslint-check.d.ts +10 -0
- package/dist/eslint-check.js +102 -0
- package/dist/framework-package.d.ts +10 -0
- package/dist/framework-package.js +58 -0
- package/dist/framework-registry.d.ts +39 -0
- package/dist/framework-registry.js +30 -0
- package/dist/incremental-cache.d.ts +116 -0
- package/dist/incremental-cache.js +335 -0
- package/dist/ir/adc-range-validation.d.ts +11 -0
- package/dist/ir/adc-range-validation.js +250 -0
- package/dist/ir/ast-node-utils.d.ts +8 -0
- package/dist/ir/ast-node-utils.js +32 -0
- package/dist/ir/board-pin-utils.d.ts +13 -0
- package/dist/ir/board-pin-utils.js +65 -0
- package/dist/ir/board-resolver.d.ts +36 -0
- package/dist/ir/board-resolver.js +437 -0
- package/dist/ir/build-ir-state.d.ts +167 -0
- package/dist/ir/build-ir-state.js +306 -0
- package/dist/ir/build-ir.d.ts +2 -0
- package/dist/ir/build-ir.js +808 -0
- package/dist/ir/call-graph.d.ts +35 -0
- package/dist/ir/call-graph.js +194 -0
- package/dist/ir/compile-time-only.d.ts +2 -0
- package/dist/ir/compile-time-only.js +16 -0
- package/dist/ir/declaration-builders.d.ts +9 -0
- package/dist/ir/declaration-builders.js +608 -0
- package/dist/ir/entry-points.d.ts +30 -0
- package/dist/ir/entry-points.js +191 -0
- package/dist/ir/expression-to-ir.d.ts +5 -0
- package/dist/ir/expression-to-ir.js +2249 -0
- package/dist/ir/extract-property-chain.d.ts +10 -0
- package/dist/ir/extract-property-chain.js +30 -0
- package/dist/ir/feature-prescan.d.ts +3 -0
- package/dist/ir/feature-prescan.js +43 -0
- package/dist/ir/feature-registry.d.ts +30 -0
- package/dist/ir/feature-registry.js +816 -0
- package/dist/ir/filter.d.ts +7 -0
- package/dist/ir/filter.js +85 -0
- package/dist/ir/function-builder.d.ts +19 -0
- package/dist/ir/function-builder.js +670 -0
- package/dist/ir/hal/hal-emitter.d.ts +62 -0
- package/dist/ir/hal/hal-emitter.js +735 -0
- package/dist/ir/hal/hal-parser.d.ts +61 -0
- package/dist/ir/hal/hal-parser.js +473 -0
- package/dist/ir/hal/hal-plugins.d.ts +34 -0
- package/dist/ir/hal/hal-plugins.js +706 -0
- package/dist/ir/hal-resolver.d.ts +5 -0
- package/dist/ir/hal-resolver.js +5 -0
- package/dist/ir/heap-analysis.d.ts +8 -0
- package/dist/ir/heap-analysis.js +350 -0
- package/dist/ir/heap-array-validation.d.ts +24 -0
- package/dist/ir/heap-array-validation.js +29 -0
- package/dist/ir/identifier-collector.d.ts +18 -0
- package/dist/ir/identifier-collector.js +439 -0
- package/dist/ir/interrupt-analysis.d.ts +39 -0
- package/dist/ir/interrupt-analysis.js +467 -0
- package/dist/ir/memory-budget-validation.d.ts +10 -0
- package/dist/ir/memory-budget-validation.js +86 -0
- package/dist/ir/namespace-builder.d.ts +7 -0
- package/dist/ir/namespace-builder.js +152 -0
- package/dist/ir/ownership-analysis.d.ts +9 -0
- package/dist/ir/ownership-analysis.js +1207 -0
- package/dist/ir/peripheral-ownership.d.ts +3 -0
- package/dist/ir/peripheral-ownership.js +152 -0
- package/dist/ir/peripheral-symbols.d.ts +7 -0
- package/dist/ir/peripheral-symbols.js +57 -0
- package/dist/ir/peripheral-usage.d.ts +54 -0
- package/dist/ir/peripheral-usage.js +691 -0
- package/dist/ir/peripheral-validation.d.ts +8 -0
- package/dist/ir/peripheral-validation.js +77 -0
- package/dist/ir/pin-alias-conflict.d.ts +4 -0
- package/dist/ir/pin-alias-conflict.js +34 -0
- package/dist/ir/pin-capability-validation.d.ts +6 -0
- package/dist/ir/pin-capability-validation.js +413 -0
- package/dist/ir/pin-mode-validation.d.ts +10 -0
- package/dist/ir/pin-mode-validation.js +301 -0
- package/dist/ir/pin-safety.d.ts +11 -0
- package/dist/ir/pin-safety.js +58 -0
- package/dist/ir/program-analysis.d.ts +44 -0
- package/dist/ir/program-analysis.js +589 -0
- package/dist/ir/pulldown-validation.d.ts +7 -0
- package/dist/ir/pulldown-validation.js +49 -0
- package/dist/ir/pwm-timer-sharing.d.ts +4 -0
- package/dist/ir/pwm-timer-sharing.js +93 -0
- package/dist/ir/reachability.d.ts +68 -0
- package/dist/ir/reachability.js +224 -0
- package/dist/ir/register-decorators.d.ts +6 -0
- package/dist/ir/register-decorators.js +49 -0
- package/dist/ir/render-expr.d.ts +4 -0
- package/dist/ir/render-expr.js +127 -0
- package/dist/ir/resource-analysis.d.ts +19 -0
- package/dist/ir/resource-analysis.js +153 -0
- package/dist/ir/statement-to-ir.d.ts +23 -0
- package/dist/ir/statement-to-ir.js +349 -0
- package/dist/ir/symbol-table.d.ts +68 -0
- package/dist/ir/symbol-table.js +179 -0
- package/dist/ir/symbol-types.d.ts +56 -0
- package/dist/ir/symbol-types.js +107 -0
- package/dist/ir/timer0-pwm-timing-conflict.d.ts +4 -0
- package/dist/ir/timer0-pwm-timing-conflict.js +71 -0
- package/dist/ir/timing-validation.d.ts +7 -0
- package/dist/ir/timing-validation.js +95 -0
- package/dist/ir/transformers/array-methods.d.ts +8 -0
- package/dist/ir/transformers/array-methods.js +493 -0
- package/dist/ir/transformers/call-statement.d.ts +5 -0
- package/dist/ir/transformers/call-statement.js +758 -0
- package/dist/ir/transformers/callback-context-registry.d.ts +20 -0
- package/dist/ir/transformers/callback-context-registry.js +55 -0
- package/dist/ir/transformers/canvas-lowering.d.ts +42 -0
- package/dist/ir/transformers/canvas-lowering.js +249 -0
- package/dist/ir/transformers/control-flow.d.ts +8 -0
- package/dist/ir/transformers/control-flow.js +508 -0
- package/dist/ir/transformers/expressions.d.ts +7 -0
- package/dist/ir/transformers/expressions.js +406 -0
- package/dist/ir/transformers/hal-call-resolver.d.ts +29 -0
- package/dist/ir/transformers/hal-call-resolver.js +274 -0
- package/dist/ir/transformers/hal-emit-helpers.d.ts +14 -0
- package/dist/ir/transformers/hal-emit-helpers.js +63 -0
- package/dist/ir/transformers/namespace-methods.d.ts +20 -0
- package/dist/ir/transformers/namespace-methods.js +110 -0
- package/dist/ir/transformers/register-assignment.d.ts +5 -0
- package/dist/ir/transformers/register-assignment.js +56 -0
- package/dist/ir/transformers/ui-call-resolver.d.ts +149 -0
- package/dist/ir/transformers/ui-call-resolver.js +1136 -0
- package/dist/ir/transformers/ui-callback-lowering.d.ts +62 -0
- package/dist/ir/transformers/ui-callback-lowering.js +623 -0
- package/dist/ir/transformers/ui-mount.d.ts +20 -0
- package/dist/ir/transformers/ui-mount.js +35 -0
- package/dist/ir/transformers/ui-reactive.d.ts +68 -0
- package/dist/ir/transformers/ui-reactive.js +129 -0
- package/dist/ir/transformers/variables.d.ts +14 -0
- package/dist/ir/transformers/variables.js +1045 -0
- package/dist/ir/try-catch-validation.d.ts +26 -0
- package/dist/ir/try-catch-validation.js +128 -0
- package/dist/ir/type-resolution.d.ts +31 -0
- package/dist/ir/type-resolution.js +977 -0
- package/dist/ir/ui-element-auto-wire.d.ts +50 -0
- package/dist/ir/ui-element-auto-wire.js +218 -0
- package/dist/ir/unit-suspicion-validation.d.ts +12 -0
- package/dist/ir/unit-suspicion-validation.js +296 -0
- package/dist/ir/utils/walk-ir.d.ts +6 -0
- package/dist/ir/utils/walk-ir.js +162 -0
- package/dist/ir/validation-orchestrator.d.ts +4 -0
- package/dist/ir/validation-orchestrator.js +45 -0
- package/dist/libdef/base-class-resolver.d.ts +23 -0
- package/dist/libdef/base-class-resolver.js +50 -0
- package/dist/libdef/cpp-to-decl.d.ts +34 -0
- package/dist/libdef/cpp-to-decl.js +584 -0
- package/dist/libdef/header-parser.d.ts +53 -0
- package/dist/libdef/header-parser.js +269 -0
- package/dist/libdef/registry.d.ts +10 -0
- package/dist/libdef/registry.js +142 -0
- package/dist/mapping/peripheral-names.d.ts +23 -0
- package/dist/mapping/peripheral-names.js +63 -0
- package/dist/mapping/source-map.d.ts +46 -0
- package/dist/mapping/source-map.js +207 -0
- package/dist/orchestrator/dts-generator.d.ts +17 -0
- package/dist/orchestrator/dts-generator.js +83 -0
- package/dist/orchestrator/graph-builder.d.ts +18 -0
- package/dist/orchestrator/graph-builder.js +218 -0
- package/dist/orchestrator/semantic-facts-verifier.d.ts +38 -0
- package/dist/orchestrator/semantic-facts-verifier.js +121 -0
- package/dist/orchestrator/semantic-facts.d.ts +141 -0
- package/dist/orchestrator/semantic-facts.js +652 -0
- package/dist/orchestrator/type-checker.d.ts +39 -0
- package/dist/orchestrator/type-checker.js +760 -0
- package/dist/platform/async-runtime.d.ts +8 -0
- package/dist/platform/async-runtime.js +26 -0
- package/dist/platform/generic-strategy.d.ts +101 -0
- package/dist/platform/generic-strategy.js +289 -0
- package/dist/platform/index.d.ts +4 -0
- package/dist/platform/index.js +9 -0
- package/dist/platform/registry.d.ts +21 -0
- package/dist/platform/registry.js +42 -0
- package/dist/platform/toolchain.d.ts +4 -0
- package/dist/platform/toolchain.js +43 -0
- package/dist/preview/client.d.ts +1 -0
- package/dist/preview/client.js +137 -0
- package/dist/preview/server.d.ts +5 -0
- package/dist/preview/server.js +199 -0
- package/dist/profiler/index.d.ts +28 -0
- package/dist/profiler/index.js +28 -0
- package/dist/profiler/profiler.d.ts +95 -0
- package/dist/profiler/profiler.js +338 -0
- package/dist/profiler/types.d.ts +87 -0
- package/dist/profiler/types.js +12 -0
- package/dist/stores/display-profile-store.d.ts +16 -0
- package/dist/stores/display-profile-store.js +48 -0
- package/dist/stores/theme-store.d.ts +13 -0
- package/dist/stores/theme-store.js +30 -0
- package/dist/testing.d.ts +45 -0
- package/dist/testing.js +47 -0
- package/dist/transpile/resolution.d.ts +29 -0
- package/dist/transpile/resolution.js +282 -0
- package/dist/transpile.d.ts +3 -0
- package/dist/transpile.js +722 -0
- package/dist/types.d.ts +217 -0
- package/dist/types.js +1 -0
- package/dist/ui/ui-bridge.d.ts +4 -0
- package/dist/ui/ui-bridge.js +34 -0
- package/dist/ui-hook.d.ts +84 -0
- package/dist/ui-hook.js +45 -0
- package/dist/utils/cli.d.ts +3 -0
- package/dist/utils/cli.js +463 -0
- package/dist/utils/fs.d.ts +4 -0
- package/dist/utils/fs.js +23 -0
- package/dist/utils/logger.d.ts +2 -0
- package/dist/utils/logger.js +8 -0
- package/dist/utils/strings.d.ts +35 -0
- package/dist/utils/strings.js +142 -0
- package/dist/utils/ui.d.ts +66 -0
- package/dist/utils/ui.js +149 -0
- package/dist/watch.d.ts +35 -0
- package/dist/watch.js +111 -0
- package/package.json +127 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
function stripExtension(fileName) {
|
|
3
|
+
return fileName.replace(/\.[^.]+$/, "");
|
|
4
|
+
}
|
|
5
|
+
export function toModuleKey(moduleSpecifier) {
|
|
6
|
+
const normalized = moduleSpecifier.replace(/\\/g, "/");
|
|
7
|
+
const base = path.posix.basename(normalized);
|
|
8
|
+
return stripExtension(base).toLowerCase();
|
|
9
|
+
}
|
|
10
|
+
export function toPascalCase(input) {
|
|
11
|
+
return input
|
|
12
|
+
.split(/[^a-zA-Z0-9]+/)
|
|
13
|
+
.filter(Boolean)
|
|
14
|
+
.map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))
|
|
15
|
+
.join("");
|
|
16
|
+
}
|
|
17
|
+
export function withLineColumn(content, position) {
|
|
18
|
+
const prefix = content.slice(0, position);
|
|
19
|
+
const lines = prefix.split(/\r?\n/);
|
|
20
|
+
return {
|
|
21
|
+
line: lines.length,
|
|
22
|
+
column: (lines.at(-1)?.length ?? 0) + 1,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* C++ reserved keywords that cannot be used as identifiers.
|
|
27
|
+
* When a TypeScript parameter/variable name matches one of these,
|
|
28
|
+
* we append an underscore to avoid compile errors.
|
|
29
|
+
*/
|
|
30
|
+
const CPP_RESERVED_KEYWORDS = new Set([
|
|
31
|
+
// C keywords also reserved in C++
|
|
32
|
+
"auto", "break", "case", "char", "const", "continue", "default", "do",
|
|
33
|
+
"double", "else", "enum", "extern", "float", "for", "goto", "if",
|
|
34
|
+
"int", "long", "register", "return", "short", "signed", "sizeof",
|
|
35
|
+
"static", "struct", "switch", "typedef", "union", "unsigned", "void",
|
|
36
|
+
"volatile", "while",
|
|
37
|
+
// C++-specific keywords
|
|
38
|
+
"alignas", "alignof", "and", "and_eq", "asm", "atomic_cancel",
|
|
39
|
+
"atomic_commit", "atomic_noexcept", "bitand", "bitor", "bool",
|
|
40
|
+
"catch", "char16_t", "char32_t", "char8_t", "class", "compl",
|
|
41
|
+
"concept", "const_cast", "consteval", "constexpr", "constinit",
|
|
42
|
+
"co_await", "co_return", "co_yield", "decltype", "delete",
|
|
43
|
+
"dynamic_cast", "explicit", "export", "false", "friend", "inline",
|
|
44
|
+
"mutable", "namespace", "new", "noexcept", "not", "not_eq",
|
|
45
|
+
"nullptr", "operator", "or", "or_eq", "private", "protected",
|
|
46
|
+
"public", "reflexpr", "reinterpret_cast", "requires", "static_assert",
|
|
47
|
+
"static_cast", "template", "this", "thread_local", "throw",
|
|
48
|
+
"true", "try", "typedef", "typeid", "typename", "using",
|
|
49
|
+
"virtual", "wchar_t", "xor", "xor_eq",
|
|
50
|
+
]);
|
|
51
|
+
const C_STDLIB_RESERVED_NAMES = new Set([
|
|
52
|
+
"abort", "abs", "acos", "asin", "atan", "atan2",
|
|
53
|
+
"atexit", "atof", "atoi", "atol",
|
|
54
|
+
"calloc", "ceil", "clearerr", "clock", "cos", "cosh", "ctime",
|
|
55
|
+
"div", "exit", "exp",
|
|
56
|
+
"fabs", "fclose", "feof", "ferror", "fflush", "fgetc", "fgetpos", "fgets",
|
|
57
|
+
"floor", "fmod", "fopen", "fprintf", "fputc", "fputs", "fread", "free",
|
|
58
|
+
"freopen", "frexp", "fscanf", "fseek", "fsetpos", "ftell", "fwrite",
|
|
59
|
+
"getc", "getchar", "getenv", "gets", "gmtime",
|
|
60
|
+
"isalnum", "isalpha", "iscntrl", "isdigit", "isgraph", "islower",
|
|
61
|
+
"isprint", "ispunct", "isspace", "isupper", "isxdigit",
|
|
62
|
+
"labs", "ldexp", "ldiv", "localtime", "log", "log10", "longjmp",
|
|
63
|
+
"malloc", "memchr", "memcmp", "memcpy", "memmove", "memset", "mktime", "modf",
|
|
64
|
+
"perror", "pow", "printf", "putc", "putchar", "puts",
|
|
65
|
+
"qsort",
|
|
66
|
+
"raise", "rand", "realloc", "remove", "rename", "rewind",
|
|
67
|
+
"scanf", "setbuf", "setjmp", "setvbuf", "signal", "sin", "sinh", "sprintf",
|
|
68
|
+
"sqrt", "srand", "sscanf", "strcat", "strchr", "strcmp", "strcoll",
|
|
69
|
+
"strcpy", "strcspn", "strerror", "strftime", "strlen", "strncat", "strncmp",
|
|
70
|
+
"strncpy", "strpbrk", "strrchr", "strspn", "strstr", "strtod", "strtok",
|
|
71
|
+
"strtol", "strtoul", "strxfrm", "system",
|
|
72
|
+
"tan", "tanh", "time", "tmpfile", "tmpnam", "tolower", "toupper",
|
|
73
|
+
"ungetc",
|
|
74
|
+
"va_arg", "va_end", "va_start",
|
|
75
|
+
"vfprintf", "vprintf", "vsprintf",
|
|
76
|
+
]);
|
|
77
|
+
/**
|
|
78
|
+
* Escapes a name that conflicts with a C++ reserved keyword by appending `_`.
|
|
79
|
+
* Additionally checks against the optional `platformNames` set, which should
|
|
80
|
+
* come from `PlatformStrategy.reservedNames()` for the active framework.
|
|
81
|
+
*
|
|
82
|
+
* For example, `register` → `register_`.
|
|
83
|
+
* With Arduino strategy: `min` → `min_`, `map` → `map_`.
|
|
84
|
+
*/
|
|
85
|
+
export function escapeCppKeyword(name, platformNames) {
|
|
86
|
+
if (CPP_RESERVED_KEYWORDS.has(name)) {
|
|
87
|
+
return `${name}_`;
|
|
88
|
+
}
|
|
89
|
+
if (C_STDLIB_RESERVED_NAMES.has(name)) {
|
|
90
|
+
return `${name}_`;
|
|
91
|
+
}
|
|
92
|
+
if (platformNames?.has(name)) {
|
|
93
|
+
return `${name}_`;
|
|
94
|
+
}
|
|
95
|
+
return name;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Escape the trailing member name of a (possibly compound) C++ lvalue/access
|
|
99
|
+
* string against the reserved-name sets. Handles both bare identifiers
|
|
100
|
+
* (`min` → `min_`) and member-access chains (`this->min`, `obj.min`,
|
|
101
|
+
* `ptr->field`) by renaming only the final segment, so a reserved member name
|
|
102
|
+
* is escaped consistently with how the field is DECLARED (renameStructField /
|
|
103
|
+
* escapeCppKeyword applied to the bare field name). Demo #33: applying plain
|
|
104
|
+
* escapeCppKeyword to the compound string `this.min` left `min` untouched,
|
|
105
|
+
* diverging from the access path and producing a declaration/access mismatch.
|
|
106
|
+
*/
|
|
107
|
+
export function escapeTrailingMember(text, platformNames) {
|
|
108
|
+
// A member-access chain ends in `->name`, `.name`, or `::name`. Rename only
|
|
109
|
+
// the trailing identifier so the receiver chain is preserved verbatim.
|
|
110
|
+
const match = text.match(/^(.*?(?:->|\.|::))([A-Za-z_][A-Za-z0-9_]*)$/);
|
|
111
|
+
if (match) {
|
|
112
|
+
const [, prefix, member] = match;
|
|
113
|
+
return `${prefix}${escapeCppKeyword(member, platformNames)}`;
|
|
114
|
+
}
|
|
115
|
+
// No member-access separator — treat the whole text as a bare identifier.
|
|
116
|
+
return escapeCppKeyword(text, platformNames);
|
|
117
|
+
}
|
|
118
|
+
export function escapeCppStringLiteral(value) {
|
|
119
|
+
return value
|
|
120
|
+
.replace(/\\/g, "\\\\")
|
|
121
|
+
.replace(/"/g, '\\"')
|
|
122
|
+
.replace(/\n/g, "\\n")
|
|
123
|
+
.replace(/\r/g, "\\r")
|
|
124
|
+
.replace(/\t/g, "\\t");
|
|
125
|
+
}
|
|
126
|
+
/** Escape a literal text fragment destined for a snprintf *format* string.
|
|
127
|
+
* Same as escapeCppStringLiteral, but also doubles `%` so a trailing or
|
|
128
|
+
* embedded percent (e.g. `meter: ${v}%`) doesn't get misread as a conversion
|
|
129
|
+
* specifier on hardware. Use this for any fragment that becomes part of the
|
|
130
|
+
* format argument to snprintf(...) — NOT for snprintf *arguments* or for
|
|
131
|
+
* standalone C++ string literals, where a bare `%` is harmless. */
|
|
132
|
+
export function escapeSnprintfFormatFragment(value) {
|
|
133
|
+
return escapeCppStringLiteral(value).replace(/%/g, "%%");
|
|
134
|
+
}
|
|
135
|
+
export function normalizeKebabName(name) {
|
|
136
|
+
return name
|
|
137
|
+
.toLowerCase()
|
|
138
|
+
.replace(/[\s_]+/g, '-')
|
|
139
|
+
.replace(/[^a-z0-9-]/g, '')
|
|
140
|
+
.replace(/-+/g, '-')
|
|
141
|
+
.replace(/^-|-$/g, '');
|
|
142
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Print the Cuttlefish branded header
|
|
3
|
+
*/
|
|
4
|
+
export declare function printHeader(): void;
|
|
5
|
+
/**
|
|
6
|
+
* Print build configuration info
|
|
7
|
+
*/
|
|
8
|
+
export declare function printBuildInfo(options: {
|
|
9
|
+
framework?: string;
|
|
10
|
+
mcu?: string;
|
|
11
|
+
board?: string;
|
|
12
|
+
buildTarget?: string;
|
|
13
|
+
}): void;
|
|
14
|
+
/**
|
|
15
|
+
* Print discovered tasks and timers
|
|
16
|
+
*/
|
|
17
|
+
export declare function printTasks(tasks: string[], usesTimers: boolean): void;
|
|
18
|
+
/**
|
|
19
|
+
* Print a step notification (transpiling, compiling, etc.)
|
|
20
|
+
*/
|
|
21
|
+
export declare function printStep(message: string): void;
|
|
22
|
+
/**
|
|
23
|
+
* Print transpiling step
|
|
24
|
+
*/
|
|
25
|
+
export declare function printTranspiling(): void;
|
|
26
|
+
/**
|
|
27
|
+
* Print compiling step
|
|
28
|
+
*/
|
|
29
|
+
export declare function printCompiling(target: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Print uploading step
|
|
32
|
+
*/
|
|
33
|
+
export declare function printUploading(port: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Print monitoring step
|
|
36
|
+
*/
|
|
37
|
+
export declare function printMonitoring(port: string, baud: number): void;
|
|
38
|
+
/**
|
|
39
|
+
* Print success message
|
|
40
|
+
*/
|
|
41
|
+
export declare function printSuccess(message?: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* Print error message
|
|
44
|
+
*/
|
|
45
|
+
export declare function printError(message: string): void;
|
|
46
|
+
/**
|
|
47
|
+
* Print warning message
|
|
48
|
+
*/
|
|
49
|
+
export declare function printWarning(message: string): void;
|
|
50
|
+
/**
|
|
51
|
+
* Print info message
|
|
52
|
+
*/
|
|
53
|
+
export declare function printInfo(message: string): void;
|
|
54
|
+
/**
|
|
55
|
+
* Print a file creation notification (for scaffold commands)
|
|
56
|
+
*/
|
|
57
|
+
export declare function printFileCreated(filePath: string): void;
|
|
58
|
+
/**
|
|
59
|
+
* Print memory usage info
|
|
60
|
+
*/
|
|
61
|
+
export declare function printMemoryUsage(usage: {
|
|
62
|
+
flashUsed?: number;
|
|
63
|
+
flashTotal?: number;
|
|
64
|
+
ramUsed?: number;
|
|
65
|
+
ramTotal?: number;
|
|
66
|
+
}): void;
|
package/dist/utils/ui.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
const VERSION = "0.1.0";
|
|
3
|
+
// Icons
|
|
4
|
+
const ICON_CUTTLEFISH = "⤳";
|
|
5
|
+
const ICON_COMPILE = "⇉";
|
|
6
|
+
const ICON_UPLOAD = "↱";
|
|
7
|
+
const ICON_SUCCESS = "✓";
|
|
8
|
+
const ICON_ERROR = "✗";
|
|
9
|
+
const ICON_INFO = "•";
|
|
10
|
+
const ICON_MEMORY = " ";
|
|
11
|
+
/**
|
|
12
|
+
* Print the Cuttlefish branded header
|
|
13
|
+
*/
|
|
14
|
+
export function printHeader() {
|
|
15
|
+
console.log();
|
|
16
|
+
console.log(chalk.cyan(`${ICON_CUTTLEFISH} Cuttlefish`) + chalk.gray(` v${VERSION}`));
|
|
17
|
+
console.log();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Print build configuration info
|
|
21
|
+
*/
|
|
22
|
+
export function printBuildInfo(options) {
|
|
23
|
+
if (options.framework) {
|
|
24
|
+
console.log(chalk.gray(` ${ICON_INFO} Framework: `) + chalk.white(options.framework));
|
|
25
|
+
}
|
|
26
|
+
if (options.mcu) {
|
|
27
|
+
console.log(chalk.gray(` ${ICON_INFO} MCU: `) + chalk.white(options.mcu));
|
|
28
|
+
}
|
|
29
|
+
if (options.board) {
|
|
30
|
+
console.log(chalk.gray(` ${ICON_INFO} Board: `) + chalk.white(options.board));
|
|
31
|
+
}
|
|
32
|
+
if (options.buildTarget) {
|
|
33
|
+
console.log(chalk.gray(` • Build Target: `) + chalk.white(options.buildTarget));
|
|
34
|
+
}
|
|
35
|
+
if (options.framework || options.mcu || options.board || options.buildTarget) {
|
|
36
|
+
console.log();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Print discovered tasks and timers
|
|
41
|
+
*/
|
|
42
|
+
export function printTasks(tasks, usesTimers) {
|
|
43
|
+
if (tasks.length === 0 && !usesTimers)
|
|
44
|
+
return;
|
|
45
|
+
console.log(chalk.gray(` ${ICON_INFO} Discovered Tasks:`));
|
|
46
|
+
for (const task of tasks) {
|
|
47
|
+
console.log(chalk.gray(` Task: `) + chalk.white(task));
|
|
48
|
+
}
|
|
49
|
+
if (usesTimers) {
|
|
50
|
+
console.log(chalk.gray(` Timer: `) + chalk.white(`Active (setInterval/setTimeout)`));
|
|
51
|
+
}
|
|
52
|
+
console.log();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Print a step notification (transpiling, compiling, etc.)
|
|
56
|
+
*/
|
|
57
|
+
export function printStep(message) {
|
|
58
|
+
console.log(chalk.cyan(`${ICON_COMPILE} ${message}`));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Print transpiling step
|
|
62
|
+
*/
|
|
63
|
+
export function printTranspiling() {
|
|
64
|
+
console.log(chalk.cyan(`${ICON_CUTTLEFISH} Transpiling...`));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Print compiling step
|
|
68
|
+
*/
|
|
69
|
+
export function printCompiling(target) {
|
|
70
|
+
console.log(chalk.cyan(`${ICON_COMPILE} Compiling for `) + chalk.white(target));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Print uploading step
|
|
74
|
+
*/
|
|
75
|
+
export function printUploading(port) {
|
|
76
|
+
console.log(chalk.cyan(`${ICON_UPLOAD} Uploading to `) + chalk.white(port));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Print monitoring step
|
|
80
|
+
*/
|
|
81
|
+
export function printMonitoring(port, baud) {
|
|
82
|
+
console.log(chalk.cyan(`${ICON_UPLOAD} Monitor `) + chalk.white(`${port} @ ${baud} baud`));
|
|
83
|
+
console.log(chalk.gray(` Press Ctrl+C to exit`));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Print success message
|
|
87
|
+
*/
|
|
88
|
+
export function printSuccess(message = "Done") {
|
|
89
|
+
console.log(chalk.green(`${ICON_SUCCESS} ${message}`));
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Print error message
|
|
93
|
+
*/
|
|
94
|
+
export function printError(message) {
|
|
95
|
+
console.log(chalk.red(`${ICON_ERROR} ${message}`));
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Print warning message
|
|
99
|
+
*/
|
|
100
|
+
export function printWarning(message) {
|
|
101
|
+
console.log(chalk.yellow(`! ${message}`));
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Print info message
|
|
105
|
+
*/
|
|
106
|
+
export function printInfo(message) {
|
|
107
|
+
console.log(chalk.gray(` ${ICON_INFO} ${message}`));
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Print a file creation notification (for scaffold commands)
|
|
111
|
+
*/
|
|
112
|
+
export function printFileCreated(filePath) {
|
|
113
|
+
console.log(chalk.gray(` ${ICON_SUCCESS} ${filePath}`));
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Print memory usage info
|
|
117
|
+
*/
|
|
118
|
+
export function printMemoryUsage(usage) {
|
|
119
|
+
const formatBytes = (bytes) => {
|
|
120
|
+
if (bytes < 1024)
|
|
121
|
+
return `${bytes} B`;
|
|
122
|
+
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
123
|
+
};
|
|
124
|
+
const renderBar = (used, total) => {
|
|
125
|
+
const percent = Math.round((used / total) * 100);
|
|
126
|
+
const color = percent > 90 ? chalk.red : percent > 75 ? chalk.yellow : chalk.green;
|
|
127
|
+
return color(`${percent}%`);
|
|
128
|
+
};
|
|
129
|
+
console.log(chalk.gray(` ${ICON_MEMORY} Memory Usage:`));
|
|
130
|
+
if (usage.flashUsed !== undefined && usage.flashTotal !== undefined) {
|
|
131
|
+
console.log(chalk.gray(` Flash: `) +
|
|
132
|
+
chalk.white(formatBytes(usage.flashUsed)) +
|
|
133
|
+
chalk.gray(` / ${formatBytes(usage.flashTotal)} (`) +
|
|
134
|
+
renderBar(usage.flashUsed, usage.flashTotal) +
|
|
135
|
+
chalk.gray(`)`));
|
|
136
|
+
}
|
|
137
|
+
if (usage.ramUsed !== undefined && usage.ramTotal !== undefined) {
|
|
138
|
+
console.log(chalk.gray(` RAM: `) +
|
|
139
|
+
chalk.white(formatBytes(usage.ramUsed)) +
|
|
140
|
+
chalk.gray(` / ${formatBytes(usage.ramTotal)} (`) +
|
|
141
|
+
renderBar(usage.ramUsed, usage.ramTotal) +
|
|
142
|
+
chalk.gray(`)`));
|
|
143
|
+
const free = usage.ramTotal - usage.ramUsed;
|
|
144
|
+
console.log(chalk.gray(` Heap: `) +
|
|
145
|
+
chalk.white(formatBytes(free)) +
|
|
146
|
+
chalk.gray(` available`));
|
|
147
|
+
}
|
|
148
|
+
console.log();
|
|
149
|
+
}
|
package/dist/watch.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for the watch mode runner.
|
|
3
|
+
*/
|
|
4
|
+
interface WatchOptions {
|
|
5
|
+
/** Directories to watch recursively. */
|
|
6
|
+
watchDirs: string[];
|
|
7
|
+
/** Path to cuttlefish.config.ts (if any) — watched for changes. */
|
|
8
|
+
configPath?: string;
|
|
9
|
+
/** Directory containing the entry file — used for relevance filtering. */
|
|
10
|
+
entryDir: string;
|
|
11
|
+
/** Callback invoked on each relevant file change. */
|
|
12
|
+
onRebuild: (changedFile: string) => Promise<void>;
|
|
13
|
+
/** Callback invoked once after watchers are set up. */
|
|
14
|
+
onReady?: () => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Discover directories that should be watched for a given entry file and
|
|
18
|
+
* optional config path. Returns unique, resolved directory paths.
|
|
19
|
+
*/
|
|
20
|
+
export declare function discoverWatchDirs(entryFile: string, configPath?: string): string[];
|
|
21
|
+
/**
|
|
22
|
+
* Determine whether a file change event is relevant and should trigger a
|
|
23
|
+
* rebuild.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isRelevantChange(changedPath: string, _entryDir: string, configPath?: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Start the file watcher loop. Sets up `fs.watch` listeners on each of the
|
|
28
|
+
* supplied `watchDirs`, debounces rapid events, and invokes `onRebuild` for
|
|
29
|
+
* relevant changes.
|
|
30
|
+
*
|
|
31
|
+
* This function **never resolves** under normal operation — it keeps the
|
|
32
|
+
* process alive until the user presses Ctrl+C.
|
|
33
|
+
*/
|
|
34
|
+
export declare function runWatch(options: WatchOptions): Promise<void>;
|
|
35
|
+
export {};
|
package/dist/watch.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// File watcher for automatic retranspilation on source changes
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
/** Debounce interval in milliseconds to collapse rapid file events. */
|
|
7
|
+
const DEBOUNCE_MS = 150;
|
|
8
|
+
/**
|
|
9
|
+
* Discover directories that should be watched for a given entry file and
|
|
10
|
+
* optional config path. Returns unique, resolved directory paths.
|
|
11
|
+
*/
|
|
12
|
+
export function discoverWatchDirs(entryFile, configPath) {
|
|
13
|
+
const dirs = new Set();
|
|
14
|
+
// Always watch the entry file's directory tree
|
|
15
|
+
dirs.add(path.dirname(path.resolve(entryFile)));
|
|
16
|
+
// Also watch the config file's directory if it lives elsewhere
|
|
17
|
+
if (configPath) {
|
|
18
|
+
dirs.add(path.dirname(path.resolve(configPath)));
|
|
19
|
+
}
|
|
20
|
+
return [...dirs];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Determine whether a file change event is relevant and should trigger a
|
|
24
|
+
* rebuild.
|
|
25
|
+
*/
|
|
26
|
+
export function isRelevantChange(changedPath, _entryDir, configPath) {
|
|
27
|
+
const resolved = path.resolve(changedPath);
|
|
28
|
+
const ext = path.extname(resolved).toLowerCase();
|
|
29
|
+
if (configPath && resolved === path.resolve(configPath)) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
if (ext !== ".ts") {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (resolved.endsWith(".d.ts")) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
if (resolved.includes(`${path.sep}node_modules${path.sep}`)) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Start the file watcher loop. Sets up `fs.watch` listeners on each of the
|
|
45
|
+
* supplied `watchDirs`, debounces rapid events, and invokes `onRebuild` for
|
|
46
|
+
* relevant changes.
|
|
47
|
+
*
|
|
48
|
+
* This function **never resolves** under normal operation — it keeps the
|
|
49
|
+
* process alive until the user presses Ctrl+C.
|
|
50
|
+
*/
|
|
51
|
+
export async function runWatch(options) {
|
|
52
|
+
const { watchDirs, configPath, entryDir, onRebuild, onReady } = options;
|
|
53
|
+
const watchers = [];
|
|
54
|
+
let debounceTimer = null;
|
|
55
|
+
let rebuilding = false;
|
|
56
|
+
// ---- Debounced rebuild scheduler ----------------------------------------
|
|
57
|
+
const scheduleRebuild = (changedFile) => {
|
|
58
|
+
if (!isRelevantChange(changedFile, entryDir, configPath)) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (debounceTimer) {
|
|
62
|
+
clearTimeout(debounceTimer);
|
|
63
|
+
}
|
|
64
|
+
debounceTimer = setTimeout(async () => {
|
|
65
|
+
debounceTimer = null;
|
|
66
|
+
if (rebuilding)
|
|
67
|
+
return;
|
|
68
|
+
rebuilding = true;
|
|
69
|
+
try {
|
|
70
|
+
await onRebuild(changedFile);
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
rebuilding = false;
|
|
74
|
+
}
|
|
75
|
+
}, DEBOUNCE_MS);
|
|
76
|
+
};
|
|
77
|
+
// ---- Start watchers -----------------------------------------------------
|
|
78
|
+
for (const dir of watchDirs) {
|
|
79
|
+
try {
|
|
80
|
+
const watcher = fs.watch(dir, { recursive: true }, (_eventType, filename) => {
|
|
81
|
+
if (!filename)
|
|
82
|
+
return;
|
|
83
|
+
scheduleRebuild(path.join(dir, filename));
|
|
84
|
+
});
|
|
85
|
+
watchers.push(watcher);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// Directory might not exist or recursive watch unsupported on this platform
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Signal readiness
|
|
92
|
+
onReady?.();
|
|
93
|
+
// ---- Graceful shutdown on Ctrl+C ----------------------------------------
|
|
94
|
+
const onSigInt = () => {
|
|
95
|
+
if (debounceTimer) {
|
|
96
|
+
clearTimeout(debounceTimer);
|
|
97
|
+
}
|
|
98
|
+
for (const w of watchers) {
|
|
99
|
+
w.close();
|
|
100
|
+
}
|
|
101
|
+
console.log();
|
|
102
|
+
console.log(" Watch stopped.");
|
|
103
|
+
process.exit(0);
|
|
104
|
+
};
|
|
105
|
+
process.on("SIGINT", onSigInt);
|
|
106
|
+
// Return a promise that never resolves so the caller can `await` this
|
|
107
|
+
// function and block the main thread indefinitely. The fs.watch listeners
|
|
108
|
+
// keep the Node.js event loop alive.
|
|
109
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
110
|
+
return new Promise(() => { });
|
|
111
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@typecad/cuttlefish",
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"description": "TypeScript to C++ transpiler — native, Arduino, and bare-metal targets",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/transpile.js",
|
|
7
|
+
"types": "./dist/transpile.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"cuttlefish": "dist/cli.js"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/transpile.d.ts",
|
|
14
|
+
"default": "./dist/transpile.js"
|
|
15
|
+
},
|
|
16
|
+
"./testing": {
|
|
17
|
+
"types": "./dist/testing.d.ts",
|
|
18
|
+
"default": "./dist/testing.js"
|
|
19
|
+
},
|
|
20
|
+
"./api": {
|
|
21
|
+
"types": "./dist/api/index.d.ts",
|
|
22
|
+
"default": "./dist/api/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./api/shared": {
|
|
25
|
+
"types": "./dist/api/shared/index.d.ts",
|
|
26
|
+
"default": "./dist/api/shared/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./ui-hook": {
|
|
29
|
+
"types": "./dist/ui-hook.d.ts",
|
|
30
|
+
"default": "./dist/ui-hook.js"
|
|
31
|
+
},
|
|
32
|
+
"./config-loader": {
|
|
33
|
+
"types": "./dist/config-loader.d.ts",
|
|
34
|
+
"default": "./dist/config-loader.js"
|
|
35
|
+
},
|
|
36
|
+
"./stores/display-profile-store": {
|
|
37
|
+
"types": "./dist/stores/display-profile-store.d.ts",
|
|
38
|
+
"default": "./dist/stores/display-profile-store.js"
|
|
39
|
+
},
|
|
40
|
+
"./stores/theme-store": {
|
|
41
|
+
"types": "./dist/stores/theme-store.d.ts",
|
|
42
|
+
"default": "./dist/stores/theme-store.js"
|
|
43
|
+
},
|
|
44
|
+
"./api/schema": {
|
|
45
|
+
"types": "./dist/api/schema/index.d.ts",
|
|
46
|
+
"default": "./dist/api/schema/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./emit/route-hal-op": {
|
|
49
|
+
"types": "./dist/emit/route-hal-op.d.ts",
|
|
50
|
+
"default": "./dist/emit/route-hal-op.js"
|
|
51
|
+
},
|
|
52
|
+
"./ir/transformers/ui-lowering": {
|
|
53
|
+
"types": "./dist/ir/transformers/ui-lowering.d.ts",
|
|
54
|
+
"default": "./dist/ir/transformers/ui-lowering.js"
|
|
55
|
+
},
|
|
56
|
+
"./ir/ui-element-auto-wire": {
|
|
57
|
+
"types": "./dist/ir/ui-element-auto-wire.d.ts",
|
|
58
|
+
"default": "./dist/ir/ui-element-auto-wire.js"
|
|
59
|
+
},
|
|
60
|
+
"./ir/transformers/ui-mount": {
|
|
61
|
+
"types": "./dist/ir/transformers/ui-mount.d.ts",
|
|
62
|
+
"default": "./dist/ir/transformers/ui-mount.js"
|
|
63
|
+
},
|
|
64
|
+
"./ir/transformers/ui-reactive": {
|
|
65
|
+
"types": "./dist/ir/transformers/ui-reactive.d.ts",
|
|
66
|
+
"default": "./dist/ir/transformers/ui-reactive.js"
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"files": [
|
|
70
|
+
"dist"
|
|
71
|
+
],
|
|
72
|
+
"publishConfig": {
|
|
73
|
+
"access": "public"
|
|
74
|
+
},
|
|
75
|
+
"scripts": {
|
|
76
|
+
"build": "tsc",
|
|
77
|
+
"prepublishOnly": "npm run build",
|
|
78
|
+
"start": "node dist/cli.js"
|
|
79
|
+
},
|
|
80
|
+
"dependencies": {
|
|
81
|
+
"chalk": "^4.1.2",
|
|
82
|
+
"typescript": "^5.7.3",
|
|
83
|
+
"zod": "^3.24.0"
|
|
84
|
+
},
|
|
85
|
+
"peerDependencies": {
|
|
86
|
+
"@typecad/ui": "0.1.0-alpha.1"
|
|
87
|
+
},
|
|
88
|
+
"peerDependenciesMeta": {
|
|
89
|
+
"@typecad/ui": {
|
|
90
|
+
"optional": true
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
"optionalDependencies": {
|
|
94
|
+
"@typecad/framework-native": "0.1.0-alpha.1"
|
|
95
|
+
},
|
|
96
|
+
"devDependencies": {
|
|
97
|
+
"@types/node": "^22.10.7"
|
|
98
|
+
},
|
|
99
|
+
"license": "MIT",
|
|
100
|
+
"repository": {
|
|
101
|
+
"type": "git",
|
|
102
|
+
"url": "git+https://github.com/justind000/typecode.git",
|
|
103
|
+
"directory": "packages/cuttlefish"
|
|
104
|
+
},
|
|
105
|
+
"homepage": "https://github.com/justind000/typecode/tree/main/packages/cuttlefish",
|
|
106
|
+
"bugs": {
|
|
107
|
+
"url": "https://github.com/justind000/typecode/issues"
|
|
108
|
+
},
|
|
109
|
+
"keywords": [
|
|
110
|
+
"arduino",
|
|
111
|
+
"cli",
|
|
112
|
+
"codegen",
|
|
113
|
+
"cpp",
|
|
114
|
+
"cuttlefish",
|
|
115
|
+
"embedded",
|
|
116
|
+
"firmware",
|
|
117
|
+
"microcontroller",
|
|
118
|
+
"transpiler",
|
|
119
|
+
"typecad",
|
|
120
|
+
"typescript"
|
|
121
|
+
],
|
|
122
|
+
"engines": {
|
|
123
|
+
"node": ">=18"
|
|
124
|
+
},
|
|
125
|
+
"author": "typecad0",
|
|
126
|
+
"sideEffects": false
|
|
127
|
+
}
|