Schematics
@blotch/angular-lynx ships Angular CLI schematics that set a project up for Lynx and generate Lynx components.
npm create angular-lynx runs ng add for you. Every schematic takes --project, which defaults to the project you're in.
ng-add
What it changes:
src/main.ts: replaced. It callsbootstrapApplicationfrom@blotch/angular-lynx.src/app/app.config.ts: replaced, withprovideZonelessChangeDetection(),provideRenderer()andprovideRouter(routes)(from@blotch/angular-lynx).src/app/app.ts: replaced with a root component whose inline template uses Lynx elements and a<router-outlet>.app.html,app.css(or.scss) andapp.spec.tsare deleted.src/rspeedy-env.d.ts: added. It types asset and CSS module imports.tsconfig.app.jsonexcludessrc/**/*.test.ts, andtsconfig.spec.jsonincludes it.angular.json:builduses@blotch/angular-lynx-build:application. It keepsng new's configurations and the options the builder accepts, and addsappNameand a placeholderappId(com.example.<name>) for the native apps.ng new'sinitialbudget (500 kB warning, 1 MB error) becomes 2 MB and 5 MB. A Lynx bundle holds Angular twice, once per thread.serveuses@blotch/angular-lynx-build:dev-server, keepingbuildTarget,portandhost.testuses@blotch/angular-lynx-build:unit-test, keeping the options of an@angular/build:unit-testtarget.cli.schematicCollectionslists@blotch/angular-lynxfirst, song generate componentmakes Lynx components.
package.json:startrunsng serveandbuildrunsng build. Adds@blotch/angular-lynx-buildand@lynx-js/typesas dev dependencies.- Tailwind CSS, unless
--tailwind=false: the same changes asadd-tailwind.
It doesn't write a lynx.config.ts. The builders read everything from angular.json (see @blotch/angular-lynx-build).
component
ng add puts @blotch/angular-lynx first in cli.schematicCollections, so this command runs it. Without that setting, run ng generate @blotch/angular-lynx:component <name>. Other ng generate schematics, such as service and pipe, still come from Angular.
What it changes:
- Runs Angular's component schematic with your options and
angular.json's@schematics/angular:componentdefaults, so it creates the files you know. - The template gets Lynx elements: the
<p>dashboard works!</p>placeholder becomes<view><text>dashboard works!</text></view>, in the.htmlfile or inline. - The component imports
LYNX_ELEMENTS, so its template type-checks in your editor and underng test. A component declared in an NgModule (--standalone false) is left as Angular made it. - The test: if
@blotch/angular-lynx-testing-libraryis inpackage.json,dashboard.spec.tsis replaced bydashboard.test.ts, which renders the component withrender(). Without the library, Angular's spec stays.
It takes all of Angular's component options. Defaults come from angular.json, then Angular.
add-tailwind
Use it if you skipped Tailwind during ng add. See Tailwind CSS.
What it changes:
tailwind.config.ts: created, or replaced, with@lynx-js/tailwind-presetandcontent: ['./src/**/*.ts'].src/styles.css(orstyles.scssif it exists): its contents are replaced with@tailwind base;and@tailwind utilities;.package.json: addstailwindcss(3.x) and@lynx-js/tailwind-presetas dev dependencies.
add-testing
Adds the testing library, so tests can render components on Lynx. See Testing.
What it changes:
package.json: adds@blotch/angular-lynx-testing-libraryas a dev dependency, plusvitestandjsdomif they're missing.ng newalready adds both. Sets thetestscript tong test.angular.json: pointstestat@blotch/angular-lynx-build:unit-test, if it isn't already.ng adddoes this for new projects.
There's no Vitest config or setup file to add: ng test loads the library's setup itself. Components you generate from then on get a test that renders them on Lynx.
add-i18n
Sets up @angular/localize with the device's language. See Internationalization.
What it changes:
angular.json: adds ani18nblock withsourceLocale: 'en-US'if there's none, and adds@angular/localize/initto the build'spolyfills.tsconfig.app.json: adds@angular/localizetocompilerOptions.types, so$localizeis typed.src/app/app.config.ts: addsprovideLocale()as the first provider, unless the file already uses it.package.json: adds@angular/localizeas a dev dependency, at the same version range as your@angular/core.
eject
Copies the native projects (the source folders of the iOS and Android apps) that ng build --platform generates into your repo. Eject only when you need a native change that the build options don't cover. See Run on iOS and Android.
What it changes:
ios/andandroid/: created in the project folder. It stops with an error if a folder already exists and isn't empty.ng build --platformthen builds those folders as they are.
It's one-way. The app options in angular.json no longer apply to an ejected project, and keeping it up to date with Lynx, Apple's and Google's tools becomes your job. It needs @blotch/angular-lynx-build installed.
ng update
Updates @blotch/angular-lynx, @blotch/angular-lynx-build, @blotch/angular-lynx-testing-library and the packages they use together, so their versions stay in step.
