@meadowlark-software/schematics 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +30 -2
  3. package/collection.json +10 -0
  4. package/ng-new/files/.prettierignore.template +4 -0
  5. package/ng-new/files/.prettierrc.json.template +1 -0
  6. package/ng-new/files/__dot__gitignore.template +5 -0
  7. package/ng-new/files/__dot__nvmrc.template +1 -0
  8. package/ng-new/files/angular.json.template +72 -0
  9. package/ng-new/files/eslint.config.js.template +2 -0
  10. package/ng-new/files/messages/en.json.template +17 -0
  11. package/ng-new/files/package.json.template +54 -0
  12. package/ng-new/files/project.inlang/settings.json.template +9 -0
  13. package/ng-new/files/proxy.conf.js.template +8 -0
  14. package/ng-new/files/public/.gitkeep.template +0 -0
  15. package/ng-new/files/scripts/serve.mjs.template +10 -0
  16. package/ng-new/files/src/app/__sliceFile__/__sliceFile__-client.service.ts.template +18 -0
  17. package/ng-new/files/src/app/__sliceFile__/__sliceFile__-page.spec.ts.template +73 -0
  18. package/ng-new/files/src/app/__sliceFile__/__sliceFile__-page.ts.template +100 -0
  19. package/ng-new/files/src/app/app.config.ts.template +24 -0
  20. package/ng-new/files/src/app/app.routes.ts.template +19 -0
  21. package/ng-new/files/src/app/app.spec.ts.template +15 -0
  22. package/ng-new/files/src/app/app.ts.template +24 -0
  23. package/ng-new/files/src/app/sign-in/sign-in-page.ts.template +18 -0
  24. package/ng-new/files/src/index.html.template +12 -0
  25. package/ng-new/files/src/main.ts.template +11 -0
  26. package/ng-new/files/src/styles.css.template +35 -0
  27. package/ng-new/files/tsconfig.app.json.template +9 -0
  28. package/ng-new/files/tsconfig.json.template +7 -0
  29. package/ng-new/files/tsconfig.spec.json.template +8 -0
  30. package/ng-new/index.js +34 -0
  31. package/ng-new/schema.json +37 -0
  32. package/package.json +19 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Meadowlark Software
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,31 @@
1
- # Temporary Holding Version
1
+ # @meadowlark-software/schematics
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Makes the Angular client of a repository made by `dotnet new meadowlark`, with the shared settings, its first slice's
4
+ page and the finish commands in place. Run it once, from the repository's root, with the names given to `dotnet new`:
5
+
6
+ ```bash
7
+ npx -p @angular/cli -p @meadowlark-software/schematics ng new angular-app --collection @meadowlark-software/schematics --product Wren --slice Orders --item Order
8
+ ```
9
+
10
+ It writes `angular-app/` and installs its packages (`--skip-install` leaves that for later). Then generate the API's
11
+ types from the repository's `openapi/` document, and check everything:
12
+
13
+ ```bash
14
+ cd angular-app
15
+ npm run api:types
16
+ npm run check
17
+ ```
18
+
19
+ The client has:
20
+
21
+ - `@meadowlark-software/angular` and `@meadowlark-software/angular-config`, with the tools they need pinned to the
22
+ versions this release was tested with: Angular, ESLint, Prettier, Vitest with jsdom, Testing Library, axe and
23
+ Paraglide.
24
+ - A shell that links to each page, applies the stored theme first and names each tab; a reload after a deploy; and the
25
+ session, with a sign-in guard and a sign-in page for the service to finish.
26
+ - The first slice's page, `src/app/orders/`: it lists the signed-in person's items through `orders-client.service.ts`,
27
+ typed from the API's document, and writes one through a signal form that shows the API's codes on the field. Its
28
+ tests answer the requests as the API does and check the page with axe.
29
+ - Every word it shows in `messages/en.json`, compiled by Paraglide into `src/paraglide/`.
30
+ - `npm start`, which serves it on the port Aspire gives it and sends `/api` on to the API, and `npm run check`, which
31
+ lints, checks formatting and the API's types, tests and builds.
@@ -0,0 +1,10 @@
1
+ {
2
+ "$schema": "../../node_modules/@angular-devkit/schematics/collection-schema.json",
3
+ "schematics": {
4
+ "ng-new": {
5
+ "description": "Makes a Meadowlark client: its first slice's page, sign-in, messages, the shared settings and the finish commands.",
6
+ "factory": "./ng-new/index#ngNew",
7
+ "schema": "./ng-new/schema.json"
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,4 @@
1
+ # Generated: src/paraglide from messages/, src/app/api from the API's OpenAPI document.
2
+ src/paraglide/
3
+ src/app/api/
4
+ package-lock.json
@@ -0,0 +1 @@
1
+ "@meadowlark-software/angular-config/prettier"
@@ -0,0 +1,5 @@
1
+ node_modules/
2
+ dist/
3
+ .angular/
4
+ coverage/
5
+ src/paraglide/
@@ -0,0 +1 @@
1
+ 24
@@ -0,0 +1,72 @@
1
+ {
2
+ "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3
+ "version": 1,
4
+ "cli": {
5
+ "packageManager": "npm",
6
+ "analytics": false
7
+ },
8
+ "newProjectRoot": "projects",
9
+ "projects": {
10
+ "<%= productLower %>-app": {
11
+ "projectType": "application",
12
+ "root": "",
13
+ "sourceRoot": "src",
14
+ "prefix": "app",
15
+ "architect": {
16
+ "build": {
17
+ "builder": "@angular/build:application",
18
+ "options": {
19
+ "outputPath": "dist/<%= productLower %>-app",
20
+ "index": "src/index.html",
21
+ "browser": "src/main.ts",
22
+ "tsConfig": "tsconfig.app.json",
23
+ "assets": [{ "glob": "**/*", "input": "public" }],
24
+ "styles": ["src/styles.css"]
25
+ },
26
+ "configurations": {
27
+ "production": {
28
+ "budgets": [
29
+ { "type": "initial", "maximumWarning": "450kB", "maximumError": "500kB" },
30
+ { "type": "anyComponentStyle", "maximumWarning": "4kB", "maximumError": "8kB" }
31
+ ],
32
+ "optimization": {
33
+ "scripts": true,
34
+ "styles": { "minify": true, "inlineCritical": false },
35
+ "fonts": true
36
+ },
37
+ "outputHashing": "all"
38
+ },
39
+ "development": {
40
+ "optimization": false,
41
+ "extractLicenses": false,
42
+ "sourceMap": true
43
+ }
44
+ },
45
+ "defaultConfiguration": "production"
46
+ },
47
+ "serve": {
48
+ "builder": "@angular/build:dev-server",
49
+ "options": { "proxyConfig": "proxy.conf.js" },
50
+ "configurations": {
51
+ "production": { "buildTarget": "<%= productLower %>-app:build:production" },
52
+ "development": { "buildTarget": "<%= productLower %>-app:build:development" }
53
+ },
54
+ "defaultConfiguration": "development"
55
+ },
56
+ "test": {
57
+ "builder": "@angular/build:unit-test",
58
+ "options": {
59
+ "tsConfig": "tsconfig.spec.json",
60
+ "runner": "vitest"
61
+ }
62
+ },
63
+ "lint": {
64
+ "builder": "@angular-eslint/builder:lint",
65
+ "options": {
66
+ "lintFilePatterns": ["src/**/*.ts", "src/**/*.html"]
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
72
+ }
@@ -0,0 +1,2 @@
1
+ // @ts-check
2
+ module.exports = require('@meadowlark-software/angular-config')({ tsconfigRootDir: __dirname });
@@ -0,0 +1,17 @@
1
+ {
2
+ "$schema": "https://inlang.com/schema/inlang-message-format",
3
+ "app_name": "<%= product %>",
4
+ "nav_label": "Main",
5
+ "sign_in_title": "Sign in",
6
+ "sign_in_missing": "Signing in is not set up yet.",
7
+ "<%= sliceKey %>_title": "<%= slice %>",
8
+ "<%= sliceKey %>_loading": "Loading…",
9
+ "<%= sliceKey %>_failed": "These could not be loaded. Try again in a moment.",
10
+ "<%= sliceKey %>_none": "There are none yet.",
11
+ "<%= sliceKey %>_written": "Written {ago}",
12
+ "<%= sliceKey %>_text_label": "Text",
13
+ "<%= sliceKey %>_text_required": "Write something first.",
14
+ "<%= sliceKey %>_text_too_long": "That is too long.",
15
+ "<%= sliceKey %>_write": "Write",
16
+ "<%= sliceKey %>_write_failed": "It could not be written. Try again in a moment."
17
+ }
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "<%= productLower %>-app",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "scripts": {
6
+ "ng": "ng",
7
+ "messages": "paraglide-js compile --project ./project.inlang --outdir ./src/paraglide --silent",
8
+ "start": "npm run messages && node scripts/serve.mjs",
9
+ "build": "npm run messages && ng build",
10
+ "test": "npm run messages && ng test",
11
+ "lint": "npm run messages && ng lint",
12
+ "format": "prettier --write .",
13
+ "format:check": "prettier --check .",
14
+ "api:types": "openapi-typescript ../openapi/<%= productLower %>-api.json -o src/app/api/<%= productLower %>-api.ts --root-types --root-types-no-schema-prefix --immutable",
15
+ "api:types:check": "openapi-typescript ../openapi/<%= productLower %>-api.json -o src/app/api/<%= productLower %>-api.ts --root-types --root-types-no-schema-prefix --immutable --check",
16
+ "check": "npm run messages && ng lint && npm run format:check && npm run api:types:check && ng test --watch=false && ng build"
17
+ },
18
+ "dependencies": {
19
+ "@angular/common": "22.3.2",
20
+ "@angular/compiler": "22.3.2",
21
+ "@angular/core": "22.3.2",
22
+ "@angular/forms": "22.3.2",
23
+ "@angular/platform-browser": "22.3.2",
24
+ "@angular/router": "22.3.2",
25
+ "@meadowlark-software/angular": "0.1.0",
26
+ "rxjs": "7.8.2",
27
+ "tslib": "2.9.1"
28
+ },
29
+ "devDependencies": {
30
+ "@angular/build": "22.3.0",
31
+ "@angular/cli": "22.3.0",
32
+ "@angular/compiler-cli": "22.3.2",
33
+ "@eslint/js": "10.0.1",
34
+ "@inlang/paraglide-js": "3.2.2",
35
+ "@meadowlark-software/angular-config": "0.1.0",
36
+ "@testing-library/angular": "19.6.0",
37
+ "@testing-library/dom": "10.4.2",
38
+ "angular-eslint": "22.8.0",
39
+ "axe-core": "4.14.1",
40
+ "eslint": "10.16.0",
41
+ "eslint-config-prettier": "10.1.9",
42
+ "jsdom": "31.0.1",
43
+ "openapi-typescript": "7.13.0",
44
+ "prettier": "3.10.1",
45
+ "typescript": "6.0.3",
46
+ "typescript-eslint": "8.74.0",
47
+ "vitest": "5.1.2"
48
+ },
49
+ "overrides": {
50
+ "openapi-typescript": {
51
+ "typescript": "$typescript"
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "$schema": "https://inlang.com/schema/project-settings",
3
+ "baseLocale": "en",
4
+ "locales": ["en"],
5
+ "modules": ["https://cdn.jsdelivr.net/npm/@inlang/plugin-message-format@4.5.0/dist/index.js"],
6
+ "plugin.inlang.messageFormat": {
7
+ "pathPattern": "./messages/{locale}.json"
8
+ }
9
+ }
@@ -0,0 +1,8 @@
1
+ // Under aspire run, the API's address comes from Aspire's service discovery; the client's pages and the API are then
2
+ // one origin, as they are when the API serves the client's build.
3
+ module.exports = {
4
+ '/api/**': {
5
+ target: process.env['services__<%= productLower %>-api__https__0'] ?? process.env['services__<%= productLower %>-api__http__0'],
6
+ secure: process.env['NODE_ENV'] !== 'development',
7
+ },
8
+ };
File without changes
@@ -0,0 +1,10 @@
1
+ // The dev server on the port Aspire gives it (PORT), or 4200 when started on its own. A script rather than
2
+ // `ng serve --port $PORT` so it works the same in every shell.
3
+ import { spawn } from 'node:child_process';
4
+
5
+ const port = process.env.PORT ?? '4200';
6
+ const child = spawn('npx', ['ng', 'serve', '--port', port], { stdio: 'inherit', shell: process.platform === 'win32' });
7
+
8
+ child.on('exit', (code) => process.exit(code ?? 0));
9
+ process.on('SIGINT', () => child.kill('SIGINT'));
10
+ process.on('SIGTERM', () => child.kill('SIGTERM'));
@@ -0,0 +1,18 @@
1
+ import { HttpClient } from '@angular/common/http';
2
+ import { Injectable, inject } from '@angular/core';
3
+ import type { Observable } from 'rxjs';
4
+ import type { <%= classify(item) %>, New<%= classify(item) %> } from '../api/<%= productLower %>-api';
5
+
6
+ /** The API's <%= sliceLower %> endpoints, for the signed-in person. */
7
+ @Injectable({ providedIn: 'root' })
8
+ export class <%= classify(slice) %>Client {
9
+ private readonly http = inject(HttpClient);
10
+
11
+ list(): Observable<readonly <%= classify(item) %>[]> {
12
+ return this.http.get<readonly <%= classify(item) %>[]>('/api/<%= sliceLower %>');
13
+ }
14
+
15
+ write(written: New<%= classify(item) %>): Observable<<%= classify(item) %>> {
16
+ return this.http.post<<%= classify(item) %>>('/api/<%= sliceLower %>', written);
17
+ }
18
+ }
@@ -0,0 +1,73 @@
1
+ import { provideHttpClient } from '@angular/common/http';
2
+ import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
3
+ import { TestBed } from '@angular/core/testing';
4
+ import { assertAccessible, flushInvalid, provideFakeClock } from '@meadowlark-software/angular/testing';
5
+ import { fireEvent, render, screen } from '@testing-library/angular';
6
+ import { afterEach, describe, expect, it } from 'vitest';
7
+ import { <%= classify(slice) %>Page } from './<%= sliceFile %>-page';
8
+
9
+ const NOW = Date.UTC(2026, 11, 4, 12);
10
+ const ADDRESS = '/api/<%= sliceLower %>';
11
+
12
+ async function renderPage() {
13
+ const rendered = await render(<%= classify(slice) %>Page, {
14
+ providers: [provideHttpClient(), provideHttpClientTesting(), provideFakeClock(NOW)],
15
+ });
16
+ return { ...rendered, http: TestBed.inject(HttpTestingController) };
17
+ }
18
+
19
+ describe('<%= classify(slice) %>Page', () => {
20
+ afterEach(() => {
21
+ TestBed.inject(HttpTestingController).verify();
22
+ });
23
+
24
+ it('lists what the API answers, with when each was written', async () => {
25
+ const { container, http } = await renderPage();
26
+
27
+ http.expectOne(ADDRESS).flush([
28
+ { id: 1, text: 'The first', writtenAt: new Date(NOW - 5 * 60_000).toISOString() },
29
+ ]);
30
+
31
+ expect(await screen.findByText('The first')).toBeTruthy();
32
+ expect(screen.getByText('Written 5 minutes ago')).toBeTruthy();
33
+ await assertAccessible(container);
34
+ });
35
+
36
+ it('says when there are none', async () => {
37
+ const { http } = await renderPage();
38
+
39
+ http.expectOne(ADDRESS).flush([]);
40
+
41
+ expect(await screen.findByText('There are none yet.')).toBeTruthy();
42
+ });
43
+
44
+ it('shows the code the API gave the text on the field', async () => {
45
+ const { http } = await renderPage();
46
+ http.expectOne(ADDRESS).flush([]);
47
+
48
+ fireEvent.input(screen.getByLabelText('Text'), { target: { value: 'Too much' } });
49
+ fireEvent.click(screen.getByRole('button', { name: 'Write' }));
50
+ const written = http.expectOne({ method: 'POST', url: ADDRESS });
51
+ expect(written.request.body).toEqual({ text: 'Too much' });
52
+ flushInvalid(written, { text: ['tooLong'] });
53
+
54
+ expect(await screen.findByText('That is too long.')).toBeTruthy();
55
+ });
56
+
57
+ it('lists the new one once it is written', async () => {
58
+ const { http } = await renderPage();
59
+ http.expectOne(ADDRESS).flush([]);
60
+
61
+ fireEvent.input(screen.getByLabelText('Text'), { target: { value: 'Another' } });
62
+ fireEvent.click(screen.getByRole('button', { name: 'Write' }));
63
+ http.expectOne({ method: 'POST', url: ADDRESS }).flush({
64
+ id: 2,
65
+ text: 'Another',
66
+ writtenAt: new Date(NOW).toISOString(),
67
+ });
68
+
69
+ await screen.findByText('Loading…');
70
+ http.expectOne(ADDRESS).flush([{ id: 2, text: 'Another', writtenAt: new Date(NOW).toISOString() }]);
71
+ expect(await screen.findByText('Another')).toBeTruthy();
72
+ });
73
+ });
@@ -0,0 +1,100 @@
1
+ import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';
2
+ import { FormField, form, maxLength, required, submit } from '@angular/forms/signals';
3
+ import { AgoPipe, injectNow, loadable, serverErrorsOf } from '@meadowlark-software/angular';
4
+ import { firstValueFrom } from 'rxjs';
5
+ import { m } from '../../paraglide/messages.js';
6
+ import { <%= classify(slice) %>Client } from './<%= sliceFile %>-client.service';
7
+
8
+ /** The most characters the API takes, as its service says. */
9
+ const MAX_LENGTH = 2000;
10
+
11
+ /** The signed-in person's <%= sliceLower %>, newest first, and a form that writes another. */
12
+ @Component({
13
+ selector: 'app-<%= sliceFile %>-page',
14
+ imports: [AgoPipe, FormField],
15
+ changeDetection: ChangeDetectionStrategy.OnPush,
16
+ template: `
17
+ <h1>{{ m.<%= sliceKey %>_title() }}</h1>
18
+
19
+ <form novalidate (submit)="write($event)">
20
+ <label for="text">{{ m.<%= sliceKey %>_text_label() }}</label>
21
+ <textarea id="text" aria-describedby="text-errors" [formField]="writing.text"></textarea>
22
+ <div id="text-errors">
23
+ @for (error of writing.text().errors(); track error.kind) {
24
+ <p>{{ errorText(error.kind) }}</p>
25
+ }
26
+ </div>
27
+ @if (writing().errors().length > 0) {
28
+ <p role="alert">{{ m.<%= sliceKey %>_write_failed() }}</p>
29
+ }
30
+ <button type="submit" [disabled]="writing().submitting()">{{ m.<%= sliceKey %>_write() }}</button>
31
+ </form>
32
+
33
+ @switch (items.state().state) {
34
+ @case ('loading') {
35
+ <p>{{ m.<%= sliceKey %>_loading() }}</p>
36
+ }
37
+ @case ('failed') {
38
+ <p role="alert">{{ m.<%= sliceKey %>_failed() }}</p>
39
+ }
40
+ @case ('ready') {
41
+ @let listed = items.value() ?? [];
42
+ @if (listed.length === 0) {
43
+ <p>{{ m.<%= sliceKey %>_none() }}</p>
44
+ } @else {
45
+ <ul>
46
+ @for (listedItem of listed; track listedItem.id) {
47
+ <li>
48
+ <p>{{ listedItem.text }}</p>
49
+ <p>{{ m.<%= sliceKey %>_written({ ago: (listedItem.writtenAt | ago: now()) }) }}</p>
50
+ </li>
51
+ }
52
+ </ul>
53
+ }
54
+ }
55
+ }
56
+ `,
57
+ })
58
+ export class <%= classify(slice) %>Page {
59
+ private readonly client = inject(<%= classify(slice) %>Client);
60
+
61
+ protected readonly m = m;
62
+ protected readonly now = injectNow();
63
+ protected readonly items = loadable(() => this.client.list());
64
+ protected readonly writing = form(signal({ text: '' }), (draft) => {
65
+ required(draft.text);
66
+ maxLength(draft.text, MAX_LENGTH);
67
+ });
68
+
69
+ constructor() {
70
+ this.items.reload();
71
+ }
72
+
73
+ protected async write(event: Event): Promise<void> {
74
+ event.preventDefault();
75
+ await submit(this.writing, async (draft) => {
76
+ try {
77
+ await firstValueFrom(this.client.write(draft().value()));
78
+ } catch (error: unknown) {
79
+ return serverErrorsOf(draft, error);
80
+ }
81
+
82
+ draft().reset({ text: '' });
83
+ this.items.reload();
84
+ return undefined;
85
+ });
86
+ }
87
+
88
+ /** Words an error on the text: the form's own checks, or a code the API gave the field. */
89
+ protected errorText(kind: string): string {
90
+ switch (kind) {
91
+ case 'required':
92
+ return m.<%= sliceKey %>_text_required();
93
+ case 'maxLength':
94
+ case 'tooLong':
95
+ return m.<%= sliceKey %>_text_too_long();
96
+ default:
97
+ return m.<%= sliceKey %>_write_failed();
98
+ }
99
+ }
100
+ }
@@ -0,0 +1,24 @@
1
+ import { provideHttpClient, withInterceptors } from '@angular/common/http';
2
+ import type { ApplicationConfig } from '@angular/core';
3
+ import { LOCALE_ID, provideBrowserGlobalErrorListeners } from '@angular/core';
4
+ import { provideRouter, withComponentInputBinding, withNavigationErrorHandler } from '@angular/router';
5
+ import {
6
+ providePageTitles,
7
+ provideSession,
8
+ reloadOnStaleChunk,
9
+ sessionInterceptor,
10
+ } from '@meadowlark-software/angular';
11
+ import { m } from '../paraglide/messages.js';
12
+ import { getLocale } from '../paraglide/runtime.js';
13
+ import { routes } from './app.routes';
14
+
15
+ export const appConfig: ApplicationConfig = {
16
+ providers: [
17
+ provideBrowserGlobalErrorListeners(),
18
+ provideRouter(routes, withComponentInputBinding(), withNavigationErrorHandler(reloadOnStaleChunk)),
19
+ provideHttpClient(withInterceptors([sessionInterceptor])),
20
+ provideSession({ url: '/api/session', signInPath: '/sign-in' }),
21
+ providePageTitles(m.app_name()),
22
+ { provide: LOCALE_ID, useFactory: getLocale },
23
+ ],
24
+ };
@@ -0,0 +1,19 @@
1
+ import type { Routes } from '@angular/router';
2
+ import { signedInGuard } from '@meadowlark-software/angular';
3
+ import { m } from '../paraglide/messages.js';
4
+
5
+ export const routes: Routes = [
6
+ { path: '', pathMatch: 'full', redirectTo: '<%= sliceFile %>' },
7
+ {
8
+ path: '<%= sliceFile %>',
9
+ title: m.<%= sliceKey %>_title(),
10
+ canActivate: [signedInGuard],
11
+ loadComponent: async () => (await import('./<%= sliceFile %>/<%= sliceFile %>-page')).<%= classify(slice) %>Page,
12
+ },
13
+ {
14
+ path: 'sign-in',
15
+ title: m.sign_in_title(),
16
+ loadComponent: async () => (await import('./sign-in/sign-in-page')).SignInPage,
17
+ },
18
+ { path: '**', redirectTo: '' },
19
+ ];
@@ -0,0 +1,15 @@
1
+ import { provideRouter } from '@angular/router';
2
+ import { assertAccessible } from '@meadowlark-software/angular/testing';
3
+ import { render, screen } from '@testing-library/angular';
4
+ import { describe, expect, it } from 'vitest';
5
+ import { App } from './app';
6
+
7
+ describe('App', () => {
8
+ it('links to each page from its navigation', async () => {
9
+ const { container } = await render(App, { providers: [provideRouter([])] });
10
+
11
+ const navigation = screen.getByRole('navigation', { name: 'Main' });
12
+ expect(navigation.querySelector('a')?.getAttribute('href')).toBe('/<%= sliceFile %>');
13
+ await assertAccessible(container);
14
+ });
15
+ });
@@ -0,0 +1,24 @@
1
+ import { ChangeDetectionStrategy, Component } from '@angular/core';
2
+ import { RouterLink, RouterLinkActive, RouterOutlet } from '@angular/router';
3
+ import { m } from '../paraglide/messages.js';
4
+
5
+ /** The shell: the product's name, the pages it links to, and the page open now. */
6
+ @Component({
7
+ selector: 'app-root',
8
+ imports: [RouterLink, RouterLinkActive, RouterOutlet],
9
+ changeDetection: ChangeDetectionStrategy.OnPush,
10
+ template: `
11
+ <header>
12
+ <a routerLink="/">{{ m.app_name() }}</a>
13
+ <nav [attr.aria-label]="m.nav_label()">
14
+ <a routerLink="/<%= sliceFile %>" routerLinkActive ariaCurrentWhenActive="page">{{ m.<%= sliceKey %>_title() }}</a>
15
+ </nav>
16
+ </header>
17
+ <main>
18
+ <router-outlet />
19
+ </main>
20
+ `,
21
+ })
22
+ export class App {
23
+ protected readonly m = m;
24
+ }
@@ -0,0 +1,18 @@
1
+ import { ChangeDetectionStrategy, Component } from '@angular/core';
2
+ import { m } from '../../paraglide/messages.js';
3
+
4
+ /**
5
+ * Where the sign-in guard sends a person who is not signed in. Signing in is the service's to add: once the API has
6
+ * checked who someone is, call Session.signedIn(name) and go on to placeAfterSignIn(next).
7
+ */
8
+ @Component({
9
+ selector: 'app-sign-in-page',
10
+ changeDetection: ChangeDetectionStrategy.OnPush,
11
+ template: `
12
+ <h1>{{ m.sign_in_title() }}</h1>
13
+ <p>{{ m.sign_in_missing() }}</p>
14
+ `,
15
+ })
16
+ export class SignInPage {
17
+ protected readonly m = m;
18
+ }
@@ -0,0 +1,12 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title><%= product %></title>
6
+ <base href="/" />
7
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
8
+ </head>
9
+ <body>
10
+ <app-root></app-root>
11
+ </body>
12
+ </html>
@@ -0,0 +1,11 @@
1
+ import { bootstrapApplication } from '@angular/platform-browser';
2
+ import { applyStoredTheme } from '@meadowlark-software/angular';
3
+ import { App } from './app/app';
4
+ import { appConfig } from './app/app.config';
5
+
6
+ // Before the first paint, so the page is never drawn in the wrong theme.
7
+ applyStoredTheme();
8
+
9
+ bootstrapApplication(App, appConfig).catch((error: unknown) => {
10
+ console.error(error);
11
+ });
@@ -0,0 +1,35 @@
1
+ :root {
2
+ color-scheme: light dark;
3
+ font-family: system-ui, sans-serif;
4
+ line-height: 1.5;
5
+ }
6
+
7
+ :root.theme-light {
8
+ color-scheme: light;
9
+ }
10
+
11
+ :root.theme-dark {
12
+ color-scheme: dark;
13
+ }
14
+
15
+ body {
16
+ margin: 0 auto;
17
+ max-width: 48rem;
18
+ padding: 1rem;
19
+ }
20
+
21
+ header {
22
+ display: flex;
23
+ gap: 1rem;
24
+ align-items: baseline;
25
+ }
26
+
27
+ nav a[aria-current='page'] {
28
+ font-weight: bold;
29
+ }
30
+
31
+ textarea {
32
+ display: block;
33
+ width: 100%;
34
+ min-height: 4rem;
35
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/out-tsc/app",
5
+ "types": []
6
+ },
7
+ "files": ["src/main.ts"],
8
+ "include": ["src/**/*.d.ts"]
9
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "@meadowlark-software/angular-config/tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/out-tsc"
5
+ },
6
+ "include": ["src/**/*.ts"]
7
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/out-tsc/spec",
5
+ "types": ["vitest/globals"]
6
+ },
7
+ "include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
8
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ngNew = ngNew;
4
+ const core_1 = require("@angular-devkit/core");
5
+ const schematics_1 = require("@angular-devkit/schematics");
6
+ const tasks_1 = require("@angular-devkit/schematics/tasks");
7
+ /**
8
+ * Makes a client in `name`, beside the repository's `openapi/` folder: the shell, a sign-in page, a page for the first
9
+ * slice that lists its items and writes one, and the settings and scripts that build and check it.
10
+ */
11
+ function ngNew(options) {
12
+ return (_tree, context) => {
13
+ if (!options.skipInstall) {
14
+ context.addTask(new tasks_1.NodePackageInstallTask({ workingDirectory: options.name }));
15
+ }
16
+ return (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./files'), [
17
+ (0, schematics_1.applyTemplates)({
18
+ ...core_1.strings,
19
+ product: options.product,
20
+ slice: options.slice,
21
+ item: options.item,
22
+ // The names dotnet new gives the API, its document and the slice's path, which lower case each name.
23
+ productLower: options.product.toLowerCase(),
24
+ sliceLower: options.slice.toLowerCase(),
25
+ // A file, route and selector name, and a message key, for the slice.
26
+ sliceFile: core_1.strings.dasherize(options.slice),
27
+ sliceKey: core_1.strings.underscore(options.slice),
28
+ // npm drops a package's .gitignore, so dot files are named __dot__ in it.
29
+ dot: '.',
30
+ }),
31
+ (0, schematics_1.move)(options.name),
32
+ ]));
33
+ };
34
+ }
@@ -0,0 +1,37 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "MeadowlarkNgNew",
4
+ "title": "A Meadowlark client",
5
+ "type": "object",
6
+ "properties": {
7
+ "name": {
8
+ "type": "string",
9
+ "description": "The client's folder: angular-app in a repository made by dotnet new meadowlark.",
10
+ "$default": { "$source": "argv", "index": 0 }
11
+ },
12
+ "product": {
13
+ "type": "string",
14
+ "description": "The product, as named to dotnet new meadowlark, such as Wren.",
15
+ "pattern": "^[A-Z][A-Za-z0-9]*$",
16
+ "x-prompt": "What is the product called, as named to dotnet new meadowlark?"
17
+ },
18
+ "slice": {
19
+ "type": "string",
20
+ "description": "The first slice, as named to dotnet new meadowlark, such as Orders.",
21
+ "pattern": "^[A-Z][A-Za-z0-9]*$",
22
+ "default": "Notes"
23
+ },
24
+ "item": {
25
+ "type": "string",
26
+ "description": "One of the first slice's items, as named to dotnet new meadowlark, such as Order.",
27
+ "pattern": "^[A-Z][A-Za-z0-9]*$",
28
+ "default": "Note"
29
+ },
30
+ "skipInstall": {
31
+ "type": "boolean",
32
+ "description": "Leave npm install for later.",
33
+ "default": false
34
+ }
35
+ },
36
+ "required": ["name", "product"]
37
+ }
package/package.json CHANGED
@@ -1,6 +1,21 @@
1
1
  {
2
2
  "name": "@meadowlark-software/schematics",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Makes a Meadowlark Angular client, in a repository made by dotnet new meadowlark, with ng new.",
5
+ "license": "MIT",
6
+ "author": "Meadowlark Software",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/Meadowlark-Software/foundation.git",
10
+ "directory": "angular/projects/schematics"
11
+ },
12
+ "keywords": [
13
+ "angular",
14
+ "schematics"
15
+ ],
16
+ "schematics": "./collection.json",
17
+ "dependencies": {
18
+ "@angular-devkit/core": "^22.3.0",
19
+ "@angular-devkit/schematics": "^22.3.0"
20
+ }
21
+ }