# Template Testing

This repo ships EJS-backed project templates. You cannot fully validate template changes by only
type-checking files in `src/templates/**`, because those files are not directly compiled in-place.

Use the flow below to test a template the same way the CLI generates it.

## When to use this

Run this flow when you change:
- files under `src/templates/**`
- feature-pruning behavior in `src/utils/features.ts`
- template rendering behavior in `src/utils/filemanager.ts`
- generated dependency versions or lockfiles

## Recommended verification flow

### 1. Build the CLI first

This refreshes `dist/`, which is what the verification script imports.

```bash
npm run build
```

### 2. Render a real app from the built CLI utilities

This uses the same template-copying and feature-pruning code path as the CLI.

Default `base` template render:

```bash
cd /tmp
rm -rf /private/tmp/verify-base

node --input-type=module <<'EOF'
import { createProject, createDirectoryContents, renderTemplateContents } from '/Users/alan/Documents/Dev_Work/Mangos Projects/mangos-cli/dist/utils/filemanager.js';
import { extrasPath } from '/Users/alan/Documents/Dev_Work/Mangos Projects/mangos-cli/dist/utils/config.js';
import { handleSelectedFeatures } from '/Users/alan/Documents/Dev_Work/Mangos Projects/mangos-cli/dist/utils/features.js';

const projectName = 'verify-base';
const selectedFeatures = [];
const renderContext = {
  projectName,
  features: selectedFeatures,
  hasPwa: false,
  hasNotifications: false,
};

const { targetPath } = createProject(projectName);
renderTemplateContents(projectName, 'base', renderContext);
createDirectoryContents(projectName, extrasPath, renderContext);
handleSelectedFeatures(targetPath, selectedFeatures);

console.log(targetPath);
EOF
```

Important:
- `createDirectoryContents(...)` alone is not enough.
- Use `renderTemplateContents(...)` when rendering app templates so branded templates inherit `base`
  before applying their overrides.
- You must also call `handleSelectedFeatures(...)`, otherwise the rendered app still contains files
  that the real CLI would have deleted.

### 3. Install and build the rendered app

```bash
cd /private/tmp/verify-base
pnpm install
pnpm build
pnpm ng version
```

This catches:
- broken generated TypeScript
- Angular compiler/template errors
- bad dependency ranges
- missing conditional dependencies

## Recommended variants

At minimum, verify these two renders for the `base` template:

### Default feature set

```bash
selectedFeatures = [];
hasPwa = false;
hasNotifications = false;
```

### PWA-enabled render

This is important because the template conditionally injects `@angular/service-worker`.

```bash
selectedFeatures = ['PWA'];
hasPwa = true;
hasNotifications = false;
```

Then run:

```bash
cd /private/tmp/verify-base-pwa
pnpm install
pnpm build
```

## Notes for agents

- If you change template files after a previous verification run, rebuild the CLI again with
  `npm run build` before rendering another app.
- Use a fresh output directory each time, or delete the old one first.
- Testing the interactive prompt layer is optional for most template changes.
  The meaningful verification is rendering through the built file-manager + feature-pruning path.
- If a build fails because optional features reference missing packages, check whether you rendered
  the right feature set before treating it as a template regression.

## What passed during the Angular 21 migration

During the Angular 21 base-template migration, the following rendered apps were verified
successfully:
- default `base` render
- `base` render with `PWA` enabled

The generated Angular app installed and built successfully with:
- `@angular/core` `21.2.5`
- `@angular/cli` `21.2.3`
- `typescript` `5.9.3`

Non-blocking warnings remained:
- initial bundle budget exceeded
- `sweetalert2` is CommonJS
