@typecad/cuttlefish 1.0.0-alpha.13 → 1.0.0-alpha.15
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/README.md +82 -79
- package/assets/editor-extensions/typecad-debug/README.md +141 -0
- package/assets/editor-extensions/typecad-debug/out/extension.js +347 -0
- package/assets/editor-extensions/typecad-debug/out/extension.js.map +1 -0
- package/assets/editor-extensions/typecad-debug/package.json +76 -0
- package/assets/editor-extensions/typecad-ui/LICENSE +27 -0
- package/assets/editor-extensions/typecad-ui/README.md +52 -0
- package/assets/editor-extensions/typecad-ui/file-icon-dark.png +0 -0
- package/assets/editor-extensions/typecad-ui/file-icon-light.png +0 -0
- package/assets/editor-extensions/typecad-ui/icon.png +0 -0
- package/assets/editor-extensions/typecad-ui/language-configuration.json +43 -0
- package/assets/editor-extensions/typecad-ui/package.json +54 -0
- package/assets/editor-extensions/typecad-ui/snippets/typecad-ui.json +80 -0
- package/assets/editor-extensions/typecad-ui/syntaxes/markdown-ui.json +45 -0
- package/assets/editor-extensions/typecad-ui/syntaxes/typecad-ui.tmLanguage.json +1269 -0
- package/dist/api/config.d.ts +30 -27
- package/dist/api/schema/types.d.ts +20 -3
- package/dist/api/shared/async-runtime-static.d.ts +1 -1
- package/dist/api/shared/async-runtime-static.js +5 -5
- package/dist/api/shared/async-types.d.ts +3 -2
- package/dist/api/shared/board-catalog.d.ts +2 -0
- package/dist/api/shared/board-catalog.js +6 -0
- package/dist/api/shared/board-resolver.d.ts +4 -7
- package/dist/api/shared/board-resolver.js +2 -1
- package/dist/api/shared/coop-scheduler.d.ts +1 -1
- package/dist/api/shared/coop-scheduler.js +1 -1
- package/dist/api/shared/cpp-type-ir.d.ts +1 -1
- package/dist/api/shared/cpp-type-ir.js +1 -1
- package/dist/api/shared/display-profile.d.ts +1 -1
- package/dist/api/shared/display-profile.js +3 -5
- package/dist/api/shared/framework-manifest-registry.d.ts +1 -1
- package/dist/api/shared/framework-manifest-registry.js +0 -1
- package/dist/api/shared/framework-manifest.d.ts +65 -507
- package/dist/api/shared/framework-manifest.js +6 -11
- package/dist/api/shared/hal-op-ir.d.ts +294 -685
- package/dist/api/shared/hal-op-ir.js +31 -65
- package/dist/api/shared/index.d.ts +0 -4
- package/dist/api/shared/index.js +1 -7
- package/dist/api/shared/ir-core.d.ts +6 -0
- package/dist/api/shared/ir-declarations.d.ts +4 -0
- package/dist/api/shared/ir.d.ts +1 -3
- package/dist/api/shared/platform-strategy.d.ts +14 -37
- package/dist/api/shared/polyfill-helper-registry.js +0 -5
- package/dist/api/shared/polyfill-types.js +0 -27
- package/dist/api/shared/promise-runtime.js +3 -3
- package/dist/api/shared/spdx-licenses.d.ts +12 -10
- package/dist/api/shared/spdx-licenses.js +1 -1
- package/dist/api/shared/toolchain-types.d.ts +1 -1
- package/dist/api/shared/toolchain-types.js +3 -3
- package/dist/api/shared/types.d.ts +0 -3
- package/dist/api/shared/validate-framework-manifest.js +13 -33
- package/dist/board-catalog/dts-reader.d.ts +220 -0
- package/dist/board-catalog/dts-reader.js +1052 -0
- package/dist/board-catalog/index.d.ts +11 -0
- package/dist/board-catalog/index.js +12 -0
- package/dist/board-catalog/pinconfig.d.ts +48 -0
- package/dist/board-catalog/pinconfig.js +263 -0
- package/dist/board-catalog/sdk.d.ts +82 -0
- package/dist/board-catalog/sdk.js +180 -0
- package/dist/board-catalog/store.d.ts +196 -0
- package/dist/board-catalog/store.js +363 -0
- package/dist/board-catalog/types.d.ts +233 -0
- package/dist/board-catalog/types.js +7 -0
- package/dist/board-catalog/walker.d.ts +112 -0
- package/dist/board-catalog/walker.js +1101 -0
- package/dist/cli-utils.d.ts +2 -2
- package/dist/cli-utils.js +5 -5
- package/dist/cli.js +227 -244
- package/dist/config-loader.d.ts +14 -19
- package/dist/config-loader.js +242 -78
- package/dist/config-schema.d.ts +19 -227
- package/dist/config-schema.js +9 -8
- package/dist/contract/board-generator.d.ts +4 -4
- package/dist/contract/board-generator.js +16 -5
- package/dist/contract/contract-parser.d.ts +36 -127
- package/dist/contract/contract-parser.js +76 -0
- package/dist/contract/index.d.ts +1 -1
- package/dist/contract/index.js +70 -21
- package/dist/create/active-board-catalog.d.ts +9 -0
- package/dist/create/active-board-catalog.js +94 -0
- package/dist/create/board-catalog.generated.d.ts +96 -0
- package/dist/create/board-catalog.generated.js +128737 -0
- package/dist/create/board-search.d.ts +23 -0
- package/dist/create/board-search.js +88 -0
- package/dist/create/editor-integration.d.ts +32 -0
- package/dist/create/editor-integration.js +257 -0
- package/dist/create/eslint-rules-template.d.ts +2 -2
- package/dist/create/framework-catalog.d.ts +48 -8
- package/dist/create/framework-catalog.js +58 -44
- package/dist/create/index.d.ts +8 -13
- package/dist/create/index.js +5 -9
- package/dist/create/mcu-target.d.ts +39 -0
- package/dist/create/mcu-target.js +80 -0
- package/dist/create/pack-targets.d.ts +19 -0
- package/dist/create/pack-targets.js +56 -0
- package/dist/create/{init-scaffold.d.ts → scaffold.d.ts} +8 -11
- package/dist/create/{init-scaffold.js → scaffold.js} +28 -87
- package/dist/create/templates.d.ts +51 -0
- package/dist/create/{init-templates.js → templates.js} +135 -116
- package/dist/create/wizard.d.ts +19 -0
- package/dist/create/wizard.js +314 -0
- package/dist/debug/preprocessor.d.ts +5 -0
- package/dist/debug/preprocessor.js +31 -7
- package/dist/diagnostics/diagnostics-report.d.ts +1 -1
- package/dist/diagnostics/diagnostics-report.js +3 -11
- package/dist/diagnostics/json-schema.d.ts +1 -1
- package/dist/diagnostics/md-writer.js +2 -2
- package/dist/diagnostics/mermaid-builder.d.ts +1 -1
- package/dist/diagnostics/mermaid-builder.js +1 -1
- package/dist/emit/cpp-emitter.js +4 -1
- package/dist/emit/emitters/class-emitter.js +32 -4
- package/dist/emit/emitters/emitter-context.d.ts +11 -0
- package/dist/emit/emitters/entrypoint-synthesizer.js +1 -1
- package/dist/emit/emitters/function-emitter-impl.js +33 -17
- package/dist/emit/emitters/output-finalizer.d.ts +7 -0
- package/dist/emit/emitters/output-finalizer.js +31 -23
- package/dist/emit/emitters/setup.js +147 -63
- package/dist/emit/emitters/top-level-prep.js +1 -1
- package/dist/emit/emitters/type-decl-emitter.js +13 -8
- package/dist/emit/emitters/ui-emitter.js +1 -1
- package/dist/emit/expression-renderer.d.ts +3 -3
- package/dist/emit/expression-renderer.js +17 -7
- package/dist/emit/route-hal-op.js +17 -48
- package/dist/emit/snprintf-helpers.d.ts +1 -3
- package/dist/emit/snprintf-helpers.js +1 -39
- package/dist/emit/statement-renderer.d.ts +0 -4
- package/dist/emit/statement-renderer.js +54 -45
- package/dist/emit/utils/async-state-machine.d.ts +16 -9
- package/dist/emit/utils/async-state-machine.js +56 -54
- package/dist/emit/utils/comment-helpers.d.ts +0 -8
- package/dist/emit/utils/comment-helpers.js +1 -1
- package/dist/emit/utils/cpp-helpers.d.ts +2 -2
- package/dist/emit/utils/cpp-helpers.js +2 -2
- package/dist/emit/utils/hal-op-cpp-type.js +4 -6
- package/dist/emit/utils/index.d.ts +3 -3
- package/dist/emit/utils/index.js +3 -3
- package/dist/emit/utils/type-inference.d.ts +1 -29
- package/dist/emit/utils/type-inference.js +0 -75
- package/dist/framework-package.d.ts +3 -0
- package/dist/framework-package.js +23 -6
- package/dist/framework-registry.d.ts +5 -5
- package/dist/frameworks/native/graphics/terminal-preview.d.ts +5 -0
- package/dist/frameworks/native/graphics/terminal-preview.js +33 -0
- package/dist/frameworks/native/index.d.ts +3 -0
- package/dist/frameworks/native/index.js +15 -0
- package/dist/frameworks/native/native-compile.d.ts +17 -0
- package/dist/frameworks/native/native-compile.js +170 -0
- package/dist/frameworks/native/native-config.d.ts +41 -0
- package/dist/frameworks/native/native-config.js +7 -0
- package/dist/frameworks/native/strategy.d.ts +97 -0
- package/dist/frameworks/native/strategy.js +664 -0
- package/dist/ir/board-resolver.d.ts +18 -23
- package/dist/ir/board-resolver.js +43 -401
- package/dist/ir/build-ir-state.d.ts +3 -0
- package/dist/ir/build-ir-state.js +42 -0
- package/dist/ir/build-ir.d.ts +1 -1
- package/dist/ir/build-ir.js +64 -45
- package/dist/ir/declaration-builders.js +1 -0
- package/dist/ir/expression-to-ir.js +17 -10
- package/dist/ir/hal/hal-emitter.d.ts +0 -2
- package/dist/ir/hal/hal-emitter.js +92 -41
- package/dist/ir/hal/hal-parser.d.ts +5 -5
- package/dist/ir/hal/hal-parser.js +128 -36
- package/dist/ir/hal/hal-plugins.d.ts +0 -1
- package/dist/ir/hal/hal-plugins.js +425 -716
- package/dist/ir/heap-analysis.js +2 -41
- package/dist/ir/identifier-collector.js +32 -20
- package/dist/ir/network-validation.js +7 -11
- package/dist/ir/ownership-analysis.js +75 -13
- package/dist/ir/peripheral-usage.d.ts +8 -2
- package/dist/ir/peripheral-usage.js +78 -149
- package/dist/ir/peripheral-validation.js +23 -3
- package/dist/ir/pin-capability-validation.d.ts +12 -0
- package/dist/ir/pin-capability-validation.js +61 -97
- package/dist/ir/pin-mode-validation.js +5 -5
- package/dist/ir/program-analysis.d.ts +8 -15
- package/dist/ir/program-analysis.js +140 -323
- package/dist/ir/pulldown-validation.js +11 -4
- package/dist/ir/resource-analysis.js +15 -3
- package/dist/ir/statement-to-ir.js +0 -6
- package/dist/ir/timing-validation.js +1 -1
- package/dist/ir/transformers/array-methods.js +11 -5
- package/dist/ir/transformers/call-statement.js +20 -87
- package/dist/ir/transformers/callback-context-registry.d.ts +1 -1
- package/dist/ir/transformers/callback-context-registry.js +8 -16
- package/dist/ir/transformers/control-flow.js +0 -13
- package/dist/ir/transformers/expressions.js +10 -9
- package/dist/ir/transformers/hal-call-resolver.d.ts +2 -2
- package/dist/ir/transformers/hal-call-resolver.js +24 -10
- package/dist/ir/transformers/hal-emit-helpers.d.ts +2 -2
- package/dist/ir/transformers/hal-emit-helpers.js +2 -2
- package/dist/ir/transformers/namespace-methods.js +1 -1
- package/dist/ir/transformers/ui-callback-lowering.d.ts +0 -2
- package/dist/ir/transformers/ui-callback-lowering.js +0 -24
- package/dist/ir/transformers/variables.js +338 -42
- package/dist/ir/try-catch-validation.js +4 -3
- package/dist/ir/type-resolution.js +15 -4
- package/dist/ir/validation-orchestrator.js +0 -9
- package/dist/libdef/cpp-to-decl.d.ts +0 -9
- package/dist/libdef/cpp-to-decl.js +0 -72
- package/dist/libdef/registry.d.ts +0 -1
- package/dist/libdef/registry.js +1 -24
- package/dist/library/catalog.d.ts +35 -0
- package/dist/library/catalog.js +67 -0
- package/dist/library/cli.d.ts +2 -0
- package/dist/library/cli.js +168 -0
- package/dist/library/init.d.ts +25 -0
- package/dist/library/init.js +397 -0
- package/dist/library/install.d.ts +9 -0
- package/dist/library/install.js +80 -0
- package/dist/library/registry-search.d.ts +34 -0
- package/dist/library/registry-search.js +50 -0
- package/dist/library/validate.d.ts +17 -0
- package/dist/library/validate.js +175 -0
- package/dist/library-packages.d.ts +95 -0
- package/dist/library-packages.js +275 -0
- package/dist/mapping/peripheral-names.js +9 -4
- package/dist/mapping/source-map.d.ts +3 -4
- package/dist/mapping/source-map.js +12 -18
- package/dist/orchestrator/graph-builder.d.ts +3 -3
- package/dist/orchestrator/graph-builder.js +29 -12
- package/dist/orchestrator/type-checker.d.ts +3 -3
- package/dist/orchestrator/type-checker.js +3 -3
- package/dist/platform/async-runtime.js +1 -1
- package/dist/platform/coop-scheduler-runtime.js +2 -2
- package/dist/platform/generic-debug-codegen.d.ts +36 -0
- package/dist/platform/generic-debug-codegen.js +185 -0
- package/dist/platform/generic-strategy.d.ts +3 -4
- package/dist/platform/generic-strategy.js +5 -80
- package/dist/platform/index.js +1 -1
- package/dist/platform/registry.d.ts +2 -2
- package/dist/platform/registry.js +2 -2
- package/dist/preview/client.js +17 -3
- package/dist/safety/asil-decorators.d.ts +32 -0
- package/dist/safety/asil-decorators.js +32 -0
- package/dist/safety/authoring.d.ts +85 -0
- package/dist/safety/authoring.js +61 -0
- package/dist/safety/engine.d.ts +3 -0
- package/dist/safety/engine.js +83 -0
- package/dist/safety/hal/ops.d.ts +48 -0
- package/dist/safety/hal/ops.js +46 -0
- package/dist/safety/iso26262/analyze.d.ts +13 -0
- package/dist/safety/iso26262/analyze.js +29 -0
- package/dist/safety/iso26262/asil.d.ts +10 -0
- package/dist/safety/iso26262/asil.js +22 -0
- package/dist/safety/iso26262/collect.d.ts +14 -0
- package/dist/safety/iso26262/collect.js +137 -0
- package/dist/safety/iso26262/goto-checker.d.ts +10 -0
- package/dist/safety/iso26262/goto-checker.js +72 -0
- package/dist/safety/iso26262/heap-checker.d.ts +7 -0
- package/dist/safety/iso26262/heap-checker.js +57 -0
- package/dist/safety/iso26262/init-checker.d.ts +13 -0
- package/dist/safety/iso26262/init-checker.js +127 -0
- package/dist/safety/iso26262/loop-checker.d.ts +7 -0
- package/dist/safety/iso26262/loop-checker.js +86 -0
- package/dist/safety/iso26262/recursion-checker.d.ts +9 -0
- package/dist/safety/iso26262/recursion-checker.js +134 -0
- package/dist/safety/iso26262/sidecar-writer.d.ts +25 -0
- package/dist/safety/iso26262/sidecar-writer.js +13 -0
- package/dist/safety/passes/pinMode-intercept.d.ts +3 -0
- package/dist/safety/passes/pinMode-intercept.js +60 -0
- package/dist/safety/runtime/mode-table.d.ts +5 -0
- package/dist/safety/runtime/mode-table.js +55 -0
- package/dist/safety/runtime/polyfills.d.ts +6 -0
- package/dist/safety/runtime/polyfills.js +12 -0
- package/dist/safety/runtime/result-struct.d.ts +11 -0
- package/dist/safety/runtime/result-struct.js +98 -0
- package/dist/safety/runtime/safe-int.d.ts +33 -0
- package/dist/safety/runtime/safe-int.js +170 -0
- package/dist/safety/runtime/safe-traits.d.ts +4 -0
- package/dist/safety/runtime/safe-traits.js +95 -0
- package/dist/safety/runtime/safe-variable.d.ts +39 -0
- package/dist/safety/runtime/safe-variable.js +226 -0
- package/dist/safety/runtime/vote.d.ts +8 -0
- package/dist/safety/runtime/vote.js +92 -0
- package/dist/safety/runtime/write-verify.d.ts +8 -0
- package/dist/safety/runtime/write-verify.js +71 -0
- package/dist/safety/safe-int-types.d.ts +45 -0
- package/dist/safety/safe-int-types.js +25 -0
- package/dist/safety/safe-variable-types.d.ts +29 -0
- package/dist/safety/safe-variable-types.js +19 -0
- package/dist/safety/safety-bridge.d.ts +5 -6
- package/dist/safety/safety-bridge.js +15 -28
- package/dist/safety/sidecar-bridge.d.ts +1 -3
- package/dist/safety/sidecar-bridge.js +3 -20
- package/dist/safety/specifiers.d.ts +6 -0
- package/dist/safety/specifiers.js +14 -0
- package/dist/safety-hook.d.ts +8 -7
- package/dist/safety-hook.js +12 -13
- package/dist/testing.d.ts +5 -6
- package/dist/testing.js +5 -5
- package/dist/transpile/resolution.d.ts +1 -1
- package/dist/transpile/resolution.js +18 -9
- package/dist/transpile/test-pins.d.ts +18 -0
- package/dist/transpile/test-pins.js +142 -0
- package/dist/transpile.d.ts +1 -2
- package/dist/transpile.js +90 -29
- package/dist/types.d.ts +45 -26
- package/dist/ui-hook.d.ts +1 -1
- package/dist/utils/cli.d.ts +2 -2
- package/dist/utils/cli.js +160 -157
- package/dist/utils/fs.d.ts +3 -4
- package/dist/utils/fs.js +4 -5
- package/dist/utils/strings.d.ts +0 -1
- package/dist/utils/strings.js +0 -8
- package/dist/utils/ui.d.ts +5 -2
- package/dist/utils/ui.js +13 -3
- package/package.json +158 -149
- package/dist/add-preset.d.ts +0 -4
- package/dist/add-preset.js +0 -74
- package/dist/api/shared/async-symbol-detector.d.ts +0 -11
- package/dist/api/shared/async-symbol-detector.js +0 -140
- package/dist/api/shared/native-display-op-resolver.d.ts +0 -10
- package/dist/api/shared/native-display-op-resolver.js +0 -64
- package/dist/create/board-checklist.d.ts +0 -2
- package/dist/create/board-checklist.js +0 -52
- package/dist/create/board-codegen.d.ts +0 -9
- package/dist/create/board-codegen.js +0 -238
- package/dist/create/board-generators.d.ts +0 -12
- package/dist/create/board-generators.js +0 -651
- package/dist/create/board-spec.d.ts +0 -637
- package/dist/create/board-spec.js +0 -214
- package/dist/create/init-templates.d.ts +0 -28
- package/dist/create/init-wizard.d.ts +0 -8
- package/dist/create/init-wizard.js +0 -182
- package/dist/install/framework-catalog.d.ts +0 -53
- package/dist/install/framework-catalog.js +0 -107
- package/dist/install/handle-install.d.ts +0 -35
- package/dist/install/handle-install.js +0 -177
- package/dist/install/index.d.ts +0 -4
- package/dist/install/index.js +0 -3
- package/dist/ir/pin-state-tracking.d.ts +0 -58
- package/dist/ir/pin-state-tracking.js +0 -182
- package/dist/ir/pwm-timer-sharing.d.ts +0 -4
- package/dist/ir/pwm-timer-sharing.js +0 -94
- package/dist/ir/timer0-pwm-timing-conflict.d.ts +0 -4
- package/dist/ir/timer0-pwm-timing-conflict.js +0 -72
- package/dist/libdef/component-decls.d.ts +0 -2
- package/dist/libdef/component-decls.js +0 -6
- package/dist/libdef/component-discovery.d.ts +0 -43
- package/dist/libdef/component-discovery.js +0 -83
- package/dist/theme-tokens.d.ts +0 -22
- package/dist/theme-tokens.js +0 -172
|
@@ -8,7 +8,6 @@ import fs from "node:fs";
|
|
|
8
8
|
import path from "node:path";
|
|
9
9
|
import { parseHeader } from "./header-parser.js";
|
|
10
10
|
import { buildClassIndex, BaseClassResolver } from "./base-class-resolver.js";
|
|
11
|
-
import { writeText } from "../utils/fs.js";
|
|
12
11
|
/**
|
|
13
12
|
* Maps C++ types to TypeScript types
|
|
14
13
|
*/
|
|
@@ -583,74 +582,3 @@ function generateDeclWithResolver(filePath, resolver) {
|
|
|
583
582
|
}
|
|
584
583
|
return outPath;
|
|
585
584
|
}
|
|
586
|
-
// ─── ESP-IDF component dispatch ───────────────────────────────────────────
|
|
587
|
-
//
|
|
588
|
-
// Picks the C or C++ emitter per header based on whether it declares classes.
|
|
589
|
-
// ESP-IDF components are mostly C (free functions + typedefs); Arduino-style
|
|
590
|
-
// libraries are C++ classes. Spec:
|
|
591
|
-
// docs/superpowers/specs/2026-07-19-framework-esp32-components-design.md
|
|
592
|
-
import { generateCDecl } from "./c-to-decl.js";
|
|
593
|
-
import { discoverComponentHeaders } from "./component-discovery.js";
|
|
594
|
-
/** Heuristic: does this header declare any C++ classes? */
|
|
595
|
-
function hasClasses(headerPath) {
|
|
596
|
-
try {
|
|
597
|
-
const content = fs.readFileSync(headerPath, "utf8");
|
|
598
|
-
return parseHeader(content).length > 0;
|
|
599
|
-
}
|
|
600
|
-
catch {
|
|
601
|
-
return false;
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
/**
|
|
605
|
-
* Generate .d.ts declarations for every declared component's headers,
|
|
606
|
-
* picking the C or C++ emitter per header based on whether it declares classes.
|
|
607
|
-
*
|
|
608
|
-
* Returns the list of created/updated .d.ts paths (headers that produced no
|
|
609
|
-
* declarations are skipped).
|
|
610
|
-
*/
|
|
611
|
-
export function generateComponentDeclsForProject(projectDir, roots) {
|
|
612
|
-
const headers = discoverComponentHeaders(projectDir, roots);
|
|
613
|
-
const created = [];
|
|
614
|
-
for (const discovered of headers) {
|
|
615
|
-
// Output path: <outputDir>/<basename>.d.ts. For managed/local this is
|
|
616
|
-
// alongside the header; for builtins it's the project-local cache dir.
|
|
617
|
-
const baseName = path.basename(discovered.path).replace(/\.h$/i, '');
|
|
618
|
-
const outputPath = path.join(discovered.outputDir, baseName + '.d.ts');
|
|
619
|
-
const out = hasClasses(discovered.path)
|
|
620
|
-
? generateDecl(discovered.path, outputPath)
|
|
621
|
-
: generateCDecl(discovered.path, outputPath);
|
|
622
|
-
if (out) {
|
|
623
|
-
created.push(out);
|
|
624
|
-
// Write a sibling .libdef.json so the import → #include resolver picks
|
|
625
|
-
// up the real (case-preserving) header name. Without this, the resolver
|
|
626
|
-
// falls back to toPascalCase(moduleKey) + ".h" — fine for Arduino libs
|
|
627
|
-
// (Adafruit_GFX → Adafruit_GFX.h, resolved separately) but wrong for
|
|
628
|
-
// ESP-IDF component headers (esp_wifi → <EspWifi.h>, not <esp_wifi.h>).
|
|
629
|
-
// The libdef declares the actual header basename ("esp_wifi.h"), which
|
|
630
|
-
// is the ground truth — the generator just read the file.
|
|
631
|
-
writeComponentLibdef(discovered.path, outputPath);
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
return created;
|
|
635
|
-
}
|
|
636
|
-
/**
|
|
637
|
-
* Write `<d.ts-basename>.libdef.json` next to a generated component `.d.ts`,
|
|
638
|
-
* pointing the import → #include resolver at the actual source header.
|
|
639
|
-
*
|
|
640
|
-
* The libdef `module` field is the lowercased basename (matches what
|
|
641
|
-
* `toModuleKey()` produces from an import specifier), and `include` is the
|
|
642
|
-
* case-preserving `<basename>.h` — quote-wrapped because component headers
|
|
643
|
-
* are project-local (resolved via the include path), not system angle-bracket
|
|
644
|
-
* includes. Matches the local-header convention in `resolveLocalModuleHeader`.
|
|
645
|
-
*/
|
|
646
|
-
function writeComponentLibdef(sourceHeaderPath, dtsOutputPath) {
|
|
647
|
-
const headerBaseName = path.basename(sourceHeaderPath); // e.g. "esp_wifi.h"
|
|
648
|
-
const dtsBaseName = path.basename(dtsOutputPath, '.d.ts'); // e.g. "esp_wifi"
|
|
649
|
-
const libdefPath = path.join(path.dirname(dtsOutputPath), `${dtsBaseName}.libdef.json`);
|
|
650
|
-
const libdef = {
|
|
651
|
-
module: dtsBaseName.toLowerCase(),
|
|
652
|
-
include: `"${headerBaseName}"`,
|
|
653
|
-
source: sourceHeaderPath,
|
|
654
|
-
};
|
|
655
|
-
writeText(libdefPath, JSON.stringify(libdef, null, 2) + '\n');
|
|
656
|
-
}
|
|
@@ -6,5 +6,4 @@ interface ResolvedImport {
|
|
|
6
6
|
}
|
|
7
7
|
export declare function loadLibraryDefinitions(definitionsDir: string): Map<string, LibraryDefinition>;
|
|
8
8
|
export declare function resolveImport(importNode: ImportIR, definitions: Map<string, LibraryDefinition>, target: TargetProfile, platformContext?: PlatformContext, importerFilePath?: string): ResolvedImport;
|
|
9
|
-
export declare function generateLibdefStubs(inputFile: string, imports: ImportIR[], outDir: string): string[];
|
|
10
9
|
export {};
|
package/dist/libdef/registry.js
CHANGED
|
@@ -22,8 +22,7 @@ function getLibraryResolver() {
|
|
|
22
22
|
export function loadLibraryDefinitions(definitionsDir) {
|
|
23
23
|
const registry = new Map();
|
|
24
24
|
// Recursive scan: libdefs may live at the entry dir (single-level convention)
|
|
25
|
-
// or nested
|
|
26
|
-
// (per-component overrides generated alongside .d.ts stubs).
|
|
25
|
+
// or nested in project subdirectories (per-module overrides).
|
|
27
26
|
const files = listFilesRecursive(definitionsDir, ".libdef.json");
|
|
28
27
|
for (const filePath of files) {
|
|
29
28
|
let def;
|
|
@@ -121,25 +120,3 @@ export function resolveImport(importNode, definitions, target, platformContext,
|
|
|
121
120
|
},
|
|
122
121
|
};
|
|
123
122
|
}
|
|
124
|
-
export function generateLibdefStubs(inputFile, imports, outDir) {
|
|
125
|
-
const created = [];
|
|
126
|
-
if (!fs.existsSync(outDir)) {
|
|
127
|
-
fs.mkdirSync(outDir, { recursive: true });
|
|
128
|
-
}
|
|
129
|
-
for (const item of imports) {
|
|
130
|
-
const moduleKey = toModuleKey(item.moduleSpecifier);
|
|
131
|
-
const libdefPath = path.join(outDir, `${moduleKey}.libdef.json`);
|
|
132
|
-
if (!fs.existsSync(libdefPath)) {
|
|
133
|
-
const include = `<${toPascalCase(moduleKey)}.h>`;
|
|
134
|
-
const libdefContent = {
|
|
135
|
-
module: moduleKey,
|
|
136
|
-
include,
|
|
137
|
-
symbols: Object.fromEntries(item.namedImports.map((symbol) => [symbol, symbol])),
|
|
138
|
-
source: inputFile,
|
|
139
|
-
};
|
|
140
|
-
fs.writeFileSync(libdefPath, JSON.stringify(libdefContent, null, 2) + "\n", "utf8");
|
|
141
|
-
created.push(libdefPath);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return created;
|
|
145
|
-
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** The one keyword every cuttlefish library package must carry. */
|
|
2
|
+
export declare const LIBRARY_MARKER_KEYWORD = "cuttlefish-library";
|
|
3
|
+
/** Prefix for category keywords (`cuttlefish-<id>`). */
|
|
4
|
+
export declare const CATEGORY_KEYWORD_PREFIX = "cuttlefish-";
|
|
5
|
+
export interface LibraryCategory {
|
|
6
|
+
/** Stable id used in --category flags, keywords, and docs. */
|
|
7
|
+
id: string;
|
|
8
|
+
/** Human label for prompts and tables. */
|
|
9
|
+
label: string;
|
|
10
|
+
/** One-line scope description. */
|
|
11
|
+
description: string;
|
|
12
|
+
/** Example parts the category covers (prompt/README guidance). */
|
|
13
|
+
examples: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The category taxonomy. Shared by search (query building + result shaping),
|
|
17
|
+
* init (scaffold choices + keywords), validate (keyword consistency), and the
|
|
18
|
+
* website's Library Packages page (rendered from the same list).
|
|
19
|
+
*/
|
|
20
|
+
export declare const LIBRARY_CATEGORIES: readonly LibraryCategory[];
|
|
21
|
+
/** Look up a category by id (case-insensitive). */
|
|
22
|
+
export declare function libraryCategory(id: string): LibraryCategory | undefined;
|
|
23
|
+
/** The npm keyword for a category (`cuttlefish-<id>`). */
|
|
24
|
+
export declare function categoryKeyword(id: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Derive the category of an npm search result from its keywords. A package may
|
|
27
|
+
* carry several category keywords; the first match in taxonomy order wins so
|
|
28
|
+
* results are stable.
|
|
29
|
+
*/
|
|
30
|
+
export declare function categoryFromKeywords(keywords: readonly string[] | undefined): string | null;
|
|
31
|
+
/**
|
|
32
|
+
* The keywords a library package should carry: the marker plus its category
|
|
33
|
+
* keyword. Used by `library init` and checked by `library validate`.
|
|
34
|
+
*/
|
|
35
|
+
export declare function requiredLibraryKeywords(categoryId: string): string[];
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Cuttlefish library catalog — the category taxonomy and npm keyword
|
|
3
|
+
// conventions behind `cuttlefish library search/init/validate`.
|
|
4
|
+
//
|
|
5
|
+
// The catalog has no registry service: npm keywords ARE the catalog. Every
|
|
6
|
+
// library package carries the marker keyword LIBRARY_MARKER_KEYWORD plus one
|
|
7
|
+
// category keyword (e.g. 'cuttlefish-led'). npm's search endpoint ANDs
|
|
8
|
+
// `keywords:` terms, so queries compose:
|
|
9
|
+
//
|
|
10
|
+
// keywords:cuttlefish-library → every library
|
|
11
|
+
// keywords:cuttlefish-library keywords:cuttlefish-led → the led category
|
|
12
|
+
// keywords:cuttlefish-library ws2812 → free-text within libraries
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
/** The one keyword every cuttlefish library package must carry. */
|
|
15
|
+
export const LIBRARY_MARKER_KEYWORD = "cuttlefish-library";
|
|
16
|
+
/** Prefix for category keywords (`cuttlefish-<id>`). */
|
|
17
|
+
export const CATEGORY_KEYWORD_PREFIX = "cuttlefish-";
|
|
18
|
+
/**
|
|
19
|
+
* The category taxonomy. Shared by search (query building + result shaping),
|
|
20
|
+
* init (scaffold choices + keywords), validate (keyword consistency), and the
|
|
21
|
+
* website's Library Packages page (rendered from the same list).
|
|
22
|
+
*/
|
|
23
|
+
export const LIBRARY_CATEGORIES = [
|
|
24
|
+
{ id: "led", label: "LEDs", description: "LEDs, addressable strips, LED drivers", examples: "WS2812-class pixels, LED drivers, bar graphs" },
|
|
25
|
+
{ id: "display", label: "Displays", description: "Panels and panel drivers", examples: "TFT, OLED, e-ink" },
|
|
26
|
+
{ id: "sensor", label: "Sensors", description: "Measurement parts", examples: "environmental, motion, IMU, light, distance" },
|
|
27
|
+
{ id: "actuator", label: "Actuators", description: "Things that move or switch", examples: "motors, servos, steppers, relays" },
|
|
28
|
+
{ id: "comms", label: "Communications", description: "Radios and networking beyond built-in WiFi/BLE", examples: "LoRa, GSM, satellite, CAN add-ons" },
|
|
29
|
+
{ id: "storage", label: "Storage", description: "Persistent storage parts", examples: "SD cards, flash chips, FRAM" },
|
|
30
|
+
{ id: "audio", label: "Audio", description: "Sound input and output", examples: "microphones, amplifiers, codecs" },
|
|
31
|
+
{ id: "power", label: "Power", description: "Power management and monitoring", examples: "PMICs, battery gauges, chargers" },
|
|
32
|
+
{ id: "input", label: "Input", description: "Add-on human input", examples: "keypads, rotary encoders, add-on touch" },
|
|
33
|
+
{ id: "io", label: "I/O Expanders", description: "Extra I/O and simple drivers", examples: "port expanders, matrix drivers, 7-segment" },
|
|
34
|
+
{ id: "timing", label: "Timing", description: "Clocks and time sources", examples: "RTCs, precision clocks, GPS time" },
|
|
35
|
+
{ id: "utility", label: "Utility", description: "Pure-code helpers with no hardware of their own", examples: "formats, algorithms, protocol codecs" },
|
|
36
|
+
];
|
|
37
|
+
/** Look up a category by id (case-insensitive). */
|
|
38
|
+
export function libraryCategory(id) {
|
|
39
|
+
const lower = id.toLowerCase();
|
|
40
|
+
return LIBRARY_CATEGORIES.find((c) => c.id === lower);
|
|
41
|
+
}
|
|
42
|
+
/** The npm keyword for a category (`cuttlefish-<id>`). */
|
|
43
|
+
export function categoryKeyword(id) {
|
|
44
|
+
return `${CATEGORY_KEYWORD_PREFIX}${id.toLowerCase()}`;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Derive the category of an npm search result from its keywords. A package may
|
|
48
|
+
* carry several category keywords; the first match in taxonomy order wins so
|
|
49
|
+
* results are stable.
|
|
50
|
+
*/
|
|
51
|
+
export function categoryFromKeywords(keywords) {
|
|
52
|
+
if (!keywords || keywords.length === 0)
|
|
53
|
+
return null;
|
|
54
|
+
const set = new Set(keywords.map((k) => k.toLowerCase()));
|
|
55
|
+
for (const category of LIBRARY_CATEGORIES) {
|
|
56
|
+
if (set.has(categoryKeyword(category.id)))
|
|
57
|
+
return category.id;
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The keywords a library package should carry: the marker plus its category
|
|
63
|
+
* keyword. Used by `library init` and checked by `library validate`.
|
|
64
|
+
*/
|
|
65
|
+
export function requiredLibraryKeywords(categoryId) {
|
|
66
|
+
return [LIBRARY_MARKER_KEYWORD, categoryKeyword(categoryId)];
|
|
67
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// `cuttlefish library <subcommand>` — CLI glue for the library manager.
|
|
3
|
+
// Subcommands: search, install, init, validate. The catalog modules own the
|
|
4
|
+
// logic; this module owns argument interpretation and presentation.
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
import chalk from "chalk";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { LIBRARY_CATEGORIES, libraryCategory } from "./catalog.js";
|
|
9
|
+
import { searchLibraryPackages } from "./registry-search.js";
|
|
10
|
+
import { findProjectPackageJson, installedDependencyVersion, npmInstall } from "./install.js";
|
|
11
|
+
import { runLibraryInit } from "./init.js";
|
|
12
|
+
import { validateLibraryPackage, printValidationReport } from "./validate.js";
|
|
13
|
+
function requireCategory(category, command) {
|
|
14
|
+
if (category === undefined)
|
|
15
|
+
return undefined;
|
|
16
|
+
if (!libraryCategory(category)) {
|
|
17
|
+
throw new Error(`Unknown category '${category}' for 'library ${command}'. Known categories: ` +
|
|
18
|
+
LIBRARY_CATEGORIES.map((c) => c.id).join(", ") +
|
|
19
|
+
".");
|
|
20
|
+
}
|
|
21
|
+
return category.toLowerCase();
|
|
22
|
+
}
|
|
23
|
+
function stripVersionPrefix(v) {
|
|
24
|
+
return v.replace(/^[^0-9]*/, "");
|
|
25
|
+
}
|
|
26
|
+
async function runSearch(options) {
|
|
27
|
+
const category = requireCategory(options.category, "search");
|
|
28
|
+
const text = options.positionals.join(" ");
|
|
29
|
+
let results;
|
|
30
|
+
try {
|
|
31
|
+
results = await searchLibraryPackages(text || undefined, category);
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
throw new Error(`Failed to search npm: ${e instanceof Error ? e.message : String(e)}`);
|
|
35
|
+
}
|
|
36
|
+
if (options.json) {
|
|
37
|
+
const pkgPath = findProjectPackageJson();
|
|
38
|
+
console.log(JSON.stringify(results.map((r) => ({
|
|
39
|
+
name: r.name,
|
|
40
|
+
version: r.version,
|
|
41
|
+
description: r.description,
|
|
42
|
+
category: r.category,
|
|
43
|
+
npmUrl: r.npmUrl,
|
|
44
|
+
installed: pkgPath ? installedDependencyVersion(pkgPath, r.name) !== undefined : false,
|
|
45
|
+
})), null, 2));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const header = category
|
|
49
|
+
? `cuttlefish libraries — category: ${libraryCategory(category).label}`
|
|
50
|
+
: "cuttlefish libraries";
|
|
51
|
+
console.log(chalk.green("+") + " " + chalk.white.bold(header) + chalk.gray(` (npm keyword: cuttlefish-library${category ? ` + cuttlefish-${category}` : ""})`));
|
|
52
|
+
console.log();
|
|
53
|
+
if (results.length === 0) {
|
|
54
|
+
console.log(chalk.yellow("No matching library packages on npm yet."));
|
|
55
|
+
console.log(` Scaffold the first one: ${chalk.cyan("cuttlefish library init")}`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const pkgPath = findProjectPackageJson();
|
|
59
|
+
for (const r of results) {
|
|
60
|
+
const cat = r.category ? libraryCategory(r.category) : undefined;
|
|
61
|
+
const installedSpec = pkgPath ? installedDependencyVersion(pkgPath, r.name) : undefined;
|
|
62
|
+
const state = installedSpec
|
|
63
|
+
? stripVersionPrefix(installedSpec) === r.version
|
|
64
|
+
? chalk.gray(" (installed)")
|
|
65
|
+
: chalk.yellow(` (installed v${stripVersionPrefix(installedSpec)}, latest v${r.version})`)
|
|
66
|
+
: "";
|
|
67
|
+
console.log(` ${chalk.white.bold(r.name)} ${chalk.dim(`v${r.version}`)}${state}`);
|
|
68
|
+
if (cat) {
|
|
69
|
+
console.log(` ${chalk.cyan(`[${cat.label}]`)} ${r.description ?? ""}`);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
console.log(` ${r.description ?? ""}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
console.log();
|
|
76
|
+
console.log(chalk.gray(` Install with: cuttlefish library install <name>`));
|
|
77
|
+
}
|
|
78
|
+
function runInstall(options) {
|
|
79
|
+
const names = options.positionals;
|
|
80
|
+
if (names.length === 0) {
|
|
81
|
+
throw new Error("Usage: cuttlefish library install <package...>");
|
|
82
|
+
}
|
|
83
|
+
const pkgPath = findProjectPackageJson();
|
|
84
|
+
if (!pkgPath) {
|
|
85
|
+
throw new Error("No package.json found in this directory or any parent — run inside a cuttlefish project.");
|
|
86
|
+
}
|
|
87
|
+
const pkgDir = path.dirname(pkgPath);
|
|
88
|
+
if (options.json) {
|
|
89
|
+
const before = Object.fromEntries(names.map((n) => [n, installedDependencyVersion(pkgPath, n) ?? null]));
|
|
90
|
+
try {
|
|
91
|
+
npmInstall(names, pkgDir);
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
const err = e;
|
|
95
|
+
const detail = err.stderr?.toString().trim() || (e instanceof Error ? e.message : String(e));
|
|
96
|
+
throw new Error(`Failed to install packages: ${detail}`);
|
|
97
|
+
}
|
|
98
|
+
console.log(JSON.stringify({ installed: names, projectRoot: pkgDir, previous: before }, null, 2));
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
console.log(chalk.green("+") + ` Installing ${names.join(", ")}...`);
|
|
102
|
+
try {
|
|
103
|
+
npmInstall(names, pkgDir);
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
const err = e;
|
|
107
|
+
const detail = err.stderr?.toString().trim() || (e instanceof Error ? e.message : String(e));
|
|
108
|
+
throw new Error(`Failed to install packages: ${detail}`);
|
|
109
|
+
}
|
|
110
|
+
for (const name of names) {
|
|
111
|
+
console.log(chalk.green("+") + ` ${name}`);
|
|
112
|
+
console.log(chalk.gray(` https://www.npmjs.com/package/${name}`));
|
|
113
|
+
}
|
|
114
|
+
console.log(chalk.green("✔") + " Done");
|
|
115
|
+
}
|
|
116
|
+
async function runInit(options) {
|
|
117
|
+
if (options.category !== undefined) {
|
|
118
|
+
requireCategory(options.category, "init");
|
|
119
|
+
}
|
|
120
|
+
await runLibraryInit({
|
|
121
|
+
name: options.positionals[0],
|
|
122
|
+
framework: options.framework,
|
|
123
|
+
category: options.category,
|
|
124
|
+
targets: options.targets,
|
|
125
|
+
dir: options.dir,
|
|
126
|
+
yes: options.yes,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function runValidate(options) {
|
|
130
|
+
const dir = options.positionals[0] ?? process.cwd();
|
|
131
|
+
const report = validateLibraryPackage(dir);
|
|
132
|
+
if (options.json) {
|
|
133
|
+
console.log(JSON.stringify({
|
|
134
|
+
valid: report.valid,
|
|
135
|
+
dir: report.dir,
|
|
136
|
+
errors: report.errors,
|
|
137
|
+
warnings: report.warnings,
|
|
138
|
+
autosarFindings: report.autosarFindings,
|
|
139
|
+
}, null, 2));
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
console.log(chalk.white.bold(`cuttlefish library validate`) + chalk.gray(` ${report.dir}`));
|
|
143
|
+
console.log();
|
|
144
|
+
const code = printValidationReport(report);
|
|
145
|
+
if (code !== 0) {
|
|
146
|
+
process.exitCode = code;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (!report.valid && options.json) {
|
|
150
|
+
process.exitCode = 1;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
export async function runLibraryCommand(options) {
|
|
154
|
+
switch (options.subcommand) {
|
|
155
|
+
case "search":
|
|
156
|
+
await runSearch(options);
|
|
157
|
+
return;
|
|
158
|
+
case "install":
|
|
159
|
+
runInstall(options);
|
|
160
|
+
return;
|
|
161
|
+
case "init":
|
|
162
|
+
await runInit(options);
|
|
163
|
+
return;
|
|
164
|
+
case "validate":
|
|
165
|
+
runValidate(options);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface LibraryInitOptions {
|
|
2
|
+
/** Full package name (e.g. '@acme/esp32-led-ring' or 'my-lib'). */
|
|
3
|
+
name?: string;
|
|
4
|
+
/** Framework id from FRAMEWORK_CATALOG ('zephyr', 'native', ...). */
|
|
5
|
+
framework?: string;
|
|
6
|
+
/** Category id from LIBRARY_CATEGORIES. */
|
|
7
|
+
category?: string;
|
|
8
|
+
/** Comma-separated board-target prefixes (e.g. 'esp32s3_devkitc'). */
|
|
9
|
+
targets?: string;
|
|
10
|
+
/** Directory to scaffold into (default: ./<package basename>). */
|
|
11
|
+
dir?: string;
|
|
12
|
+
/** Skip prompts; take defaults for anything not provided by flags. */
|
|
13
|
+
yes?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface LibraryInitResult {
|
|
16
|
+
packageDir: string;
|
|
17
|
+
packageName: string;
|
|
18
|
+
/** The library id (slug of the package basename). */
|
|
19
|
+
id: string;
|
|
20
|
+
}
|
|
21
|
+
/** Slug of a package basename: lowercase, runs of non-alphanumerics → '-'. */
|
|
22
|
+
export declare function libraryIdFromPackageName(packageName: string): string;
|
|
23
|
+
/** '__tc_my_lib' for id 'my-lib' — a valid C++ identifier prefix. */
|
|
24
|
+
export declare function tokenBaseFromId(id: string): string;
|
|
25
|
+
export declare function runLibraryInit(options: LibraryInitOptions): Promise<LibraryInitResult>;
|