Generate Angular wrapper libraries from Custom Elements Manifest output.
This package provides small utility functions to (1) run the Custom Elements Manifest analyzer (cem) and (2) generate Angular wrapper libraries from the resulting custom-elements.json manifest.
The primary exported utilities are:
runCemAnalyze(options?)— runsnpx cem analyze(or falls back topnpm exec cem analyze) and returns the path to the generatedcustom-elements.jsonmanifest.generateAngularWrappers(options)— reads a Custom Elements Manifest and scaffolds an Angular wrapper package (package.json, tsconfig.json, and per-component wrapper files) that exposes web components as Angular components.
This tooling is intended to help migrate or consume web components (Stencil/Lit) inside Angular apps by creating thin Angular bindings.
This repository contains the library source under cem-angular-generator and uses TypeScript. To build the library (from project root or inside the package folder):
# from the package folder
cd cem-angular-generator
pnpm install # or npm install / pnpm install in the workspace
pnpm run buildThe build script runs tsc -p tsconfig.json and outputs to dist per the package.json.
You can consume the library from Node or a build script. Example (TypeScript):
import { runCemAnalyze, generateAngularWrappers } from '@lit-migrators/cem-angular-generator';
// 1) run analyzer (optional if you already have custom-elements.json)
const manifestPath = runCemAnalyze({ cwd: process.cwd(), outDir: 'dist' });
// 2) generate wrappers
if (manifestPath) {
generateAngularWrappers({
manifestPath,
wrappersRoot: './angular-wrappers',
angularPackageName: '@my-scope/angular-wrappers',
componentLibraryImport: 'my-web-components',
componentLibraryVersion: '0.0.0',
});
}API contract (summary):
-
runCemAnalyze(options?: RunCemAnalyzeOptions) => string | undefined
- Inputs: cwd, outDir, configPath, analyzerExecutable, skip, spawnOptions
- Output: absolute path to
custom-elements.jsonorundefinedwhen skipped - Error modes: throws if analyzer fails or manifest not generated
-
generateAngularWrappers(options: GenerateAngularWrappersOptions) => GenerateAngularWrappersResult
- Inputs: manifestPath (required), optional wrappersRoot, componentLibraryImport, versions, linkNodeModulesFrom, etc.
- Output: object with component metadata, wrappersRoot and manifestPath
- Error modes: throws if manifestPath is missing or manifest invalid
Edge cases to consider
- If
cemis not installed globally, the code will attemptpnpm exec cem analyzeas a fallback; ensure you havecemavailable (installed or in workspace). - The generator writes files to disk. If wrappers already exist, it will create missing package.json/tsconfig.json and symlink node_modules when requested.
- Generated TypeScript types may reference non-built types from the component library — adjust imports or add type packages as needed.
-
Build or generate the
custom-elements.jsonfor your web components (via Stencil/Litcem):- Either run
runCemAnalyze()from a script - Or run
npx cem analyze --outdir dist --config custom-elements-manifest.config.mjsmanually
- Either run
-
Run
generateAngularWrappers({ manifestPath: 'dist/custom-elements.json', wrappersRoot: './angular-wrappers' }). -
Inspect the generated
angular-wrapperspackage. Review, test, and publish it as appropriate for your workspace.
This project is generated with AI.
See the cem-angular-generator package for the TypeScript sources under cem-angular-generator/src.
MIT