# Build your first pack

You will create a pack that writes one TypeScript type per schema. It takes about ten minutes and uses only the CLI.

## 1. Scaffold

```bash
mkdir types-pack && cd types-pack
dryv pack init . --yes \
  --key inject.types.simple \
  --title "Simple types" \
  --layout inject \
  --renderer handlebars --renderer-version ">=0.1" \
  --extension .hbs \
  --starter-subject schema
```

This writes two things:

```yaml
# dryv.pack.yaml
version: dryv.pack/v1alpha1
key: inject.types.simple
source: templates
info:
  title: Simple types
  version: 0.0.1
layout: inject
plugins:
  - name: handlebars
    version: ">=0.1"
    extensions:
      - .hbs
selections:
  starter:
    subject: schema
    scope: each
templates:
  starter:
    $ref: "#/selections/starter"
    output:
      name: $(subject.name.kebab)
```

and a template at `templates/{starter}/$(name).txt.hbs`. The folder name in braces (`{starter}`) links the file to the template entry `starter`; `$(name)` is replaced with that entry's `output.name`.

## 2. Write the template

Rename the file to end in `.ts.hbs` and give it a body. The `schema` root is available because the selection's subject is `schema`.

```handlebars
// templates/{starter}/$(name).ts.hbs export interface
{{schema.name.pascal}}
{
{{#each schema.fields}}
  {{name.camel}}{{#if optional}}?{{/if}}: unknown;
{{/each}}
}
```

Use `dryv context show "schema.fields[].name"` to see exactly what a path gives you. Names expose casing variants (`camel`, `pascal`, `snake`, `kebab`) so templates never re-case strings themselves.

## 3. Name the output

```yaml
templates:
  starter:
    $ref: "#/selections/starter"
    output:
      name: $(subject.name.kebab) # user-profile
      symbol: $(subject.name.pascal) # UserProfile
```

`symbol` lets other templates import this one without guessing names. See [Template filesystem](/pack-builders/design/template-filesystem) for every placement rule.

## 4. Inspect, validate, test

```bash
dryv pack inspect .     # what Dryv discovered: resources, ownership, renderer, size
dryv pack validate .    # manifest, filesystem and engine semantics
dryv pack doctor .      # is the renderer available?
dryv pack test .        # render against the engine's canonical sample IR in a temp workspace
```

`pack test` never touches your project. It renders into an isolated directory and reports every planned file, its template and the context paths it read.

## 5. Try it in a project

Point a project's `dryv.yaml` at the local folder:

```yaml
sources:
  packs:
    local: { path: ../types-pack/.. }
packs:
  types:
    source: { $ref: "#/sources/packs/local", path: types-pack }
    destination: { $ref: "#/destinations/types" }
destinations:
  types: { path: src/generated/types }
```

Then:

```bash
dryv plan
dryv generate --dry-run
```

## Common mistakes

| Symptom                         | Cause                                                             | Fix                                                                              |
| ------------------------------- | ----------------------------------------------------------------- | -------------------------------------------------------------------------------- |
| `unknown context path`          | A template reads a path the vocabulary does not define            | `dryv context show "<path>"` and fix the spelling or the collection (`fields[]`) |
| Nothing is generated            | Selection matched no subjects                                     | Check `subject`, `scope` and any `filter`                                        |
| Wrong file name                 | `output.name` uses a different casing variant                     | Use `$(subject.name.kebab)` or another variant                                   |
| File written once, then ignored | The filename has `.sf` before the renderer extension (a scaffold) | Remove `.sf` if Dryv should keep owning it                                       |

Next: [Pack anatomy](/pack-builders/anatomy).
