# How to migrate a Yeoman generator without losing its composition

> Port a Yeoman generator's composed sub-generators to components that one command still runs in order, and hold the port to the original's output with a test.

Source: https://voxgig.com/howto/migrate-a-yeoman-generator-to-a-newer-tool

- Audience: library-maintainer
- Level: advanced
- Languages: typescript
- Verified: 2026-11-22
- Published: 2026-11-22

## Short answer

Port each Yeoman sub-generator to a jostraca cmp() component that reads the prompt answers as its model, and call the components inside one Project, so one command still runs them all. Move into the model any value that one sub-generator read from a file an earlier one wrote. Keep the prompts in your own code, since jostraca has none, and test the port with mem: true against a yeoman-test run of the original.

---
## You will need

Node 22.22.2 or later, the Yeoman generator you are moving, and its `yeoman-test` suite. Verified
2026-11-22 against jostraca 0.42.0, yeoman-generator 10.3.1, yeoman-environment 8.9.0,
yeoman-test 11.8.2, orval 8.48.0 and OpenAPI Generator 7.27.0. The sample generator, `service`,
has an `app` generator that prompts and then composes `package`, `src` and `ci`.

## Approaches compared

| Approach | When it fits | What it costs you | When to pick something else |
| --- | --- | --- | --- |
| [Copier](https://copier.readthedocs.io/en/stable/configuring/#applying-multiple-templates-to-the-same-subproject) | The template has to update the projects it already made | Python and Git, plus one answers file and one update command per template | Your steps share answers or output within one run |
| [jostraca](https://github.com/jostraca/jostraca) | Sub-generators become components in one tree, tested in memory | No prompts and no install step, so both move into code you write | Your users expect a prompt-driven tool and nobody will write code |
| [OpenAPI Generator `files` node](https://openapi-generator.tech/docs/customization/) | The sub-generators only add a few files beside a generated client | Logic-less Mustache templates, a Java runtime, and answers passed as `additionalProperties` | The scaffold holds logic, or files unrelated to the client |
| [orval `generate()`](https://orval.dev/docs/reference/integration/) | A TypeScript client is one step of the scaffold, run by the same command | It writes API code only, so every other file in the scaffold needs another tool | Your clients are not TypeScript |
| [Plop](https://plopjs.com/documentation/) | A flat set of prompts and actions inside a repository that already exists | One generator per command; chaining means a custom action calling `getGenerator(name).runActions` | Your sub-generators depend on each other's answers or output |
| [Yeoman](https://yeoman.io/authoring/composability.html) | The generator works, and composition is the part you would lose | A run loop, mem-fs, and EJS templates that somebody has to keep current | Nobody on the team will maintain the generator's dependencies |

Voxgig maintains jostraca, the only one of these six it makes, and the table does not rank it.

Plop is the smallest port, and each sub-generator becomes a command of its own unless a custom
action calls the next one through `getGenerator`. Copier
[replays a later tag](https://copier.readthedocs.io/en/stable/updating/) of the template over a
project it made, from the answers it recorded there, at the price of a separate answers file and
update per template. jostraca keeps composition as plain function calls and leaves the questions
to you.

## Map each Yeoman concept before you port

Write the map first. Every row is a decision, and the second and fourth are where ports go wrong.

| Yeoman | jostraca port |
| --- | --- |
| `prompting()` and `this.prompt` | Your own code: flags, then `node:readline` questions, then defaults (`port/answers.mjs`) |
| `composeWith(path, options)` | A component call inside one `Project`; the options become the model |
| `this.fs.copyTpl` with EJS | `Content` with `$$path$$` substitution; EJS loops and conditions become JavaScript |
| Reading another sub-generator's output from mem-fs | Not possible while the tree is defined, so the value moves into the model |
| The install that [yeoman-environment queues](https://unpkg.com/yeoman-environment@8.9.0/dist/environment/environment-base.js) when `package.json` changes | Nothing; the port's user runs `npm install` |
| `yeoman-test` with `withAnswers` | `Jostraca({ mem: true })`, `res.vol().toJSON()`, and a file-by-file comparison you write (`runs.mjs`) |

The fourth row matters because jostraca writes nothing until the tree is complete. Yeoman runs
composed generators priority by priority, in the order `composeWith` was called, so a later
`writing()` can read an earlier one's file.[^1] A component cannot.

## Port a sub-generator to a component

The `ci` sub-generator read `scripts` back out of `package.json`. In the port, the model holds the
scripts, and both the package component and the workflow component read them from there.

```js title="port/components.mjs"
// Was the ci sub-generator. It reads the scripts from the model, not from a
// package.json that another component may or may not have written yet.
export const Workflow = cmp(function Workflow(props) {
  const steps = Object.keys(props.ctx$.model.scripts).filter((s) => s === 'test' || s === 'lint')
  Folder({ name: '.github' }, () => {
    Folder({ name: 'workflows' }, () => {
      File({ name: 'ci.yml' }, () => {
        Content(`name: $$service$$ ci
on: [push]
jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci
`)
        for (const s of steps) Content(`      - run: npm run ${s}\n`)
      })
    })
  })
})
```

The EJS loop became a `for`. `$$service$$` is replaced with the model value as text, with no
escaping, so the answers are checked before the tree is built.

```js title="port/model.mjs"
export function toModel(answers) {
  const a = { ...DEFAULTS, ...answers }
  if (typeof a.name !== 'string' || !NAME.test(a.name)) {
    throw new Error(`service name ${JSON.stringify(a.name)} is not a lowercase package name`)
  }
  if (!Number.isInteger(a.port) || a.port < 1 || a.port > 65535) {
    throw new Error(`port ${JSON.stringify(a.port)} is not an integer from 1 to 65535`)
  }
```

## Compose the components in one command

`composeWith` becomes three calls in one `Project`. The order no longer matters, because no
component reads a file that a sibling wrote.

```js title="port/generate.mjs"
  return jostraca.generate({ folder }, () => {
    Project({}, () => {
      PackageJson()
      Server()
      if (model.ci) Workflow()
    })
  })
}
```

`port/bin.mjs` is the command that replaces `yo service`. It asks only when a person is at the
terminal, and `--dry-run` sets jostraca's `control.dryrun`, which lists the files and writes none.

```bash
node port/bin.mjs --name orders --port 8080 --out orders --dry-run
```

```text output
would write package.json
would write src/server.js
would write .github/workflows/ci.yml
```

## Check it worked

Run the original and the port on the same answers and compare every file. `runs.mjs` runs Yeoman
through `yeoman-test`[^2] and the port in memory, and leaves out jostraca's own `.jostraca/` folder.

```bash
node compare.mjs
```

```text output
answers {"name":"orders","port":8080,"ci":true}
  .github/workflows/ci.yml   identical, 160 bytes
  package.json               identical, 124 bytes
  src/server.js              identical, 220 bytes
answers {"name":"billing","port":9090,"ci":false}
  package.json               identical, 125 bytes
  src/server.js              identical, 221 bytes
every file identical
```

The tests hold it there. They compare three answer sets and show that a changed port number is
caught. They refuse names such as `o'reilly` and `../x`, and check that a memory run and a dry
run leave the disk untouched. Two more pin the pitfalls below.

```bash
node --test parity.test.mjs records.test.mjs
```

```text output
# tests 13
# suites 0
# pass 13
# fail 0
# cancelled 0
# skipped 0
# todo 0
```

## When it goes wrong

The workflow loses its test step. The sub-generators were ported one for one into separate
commands, and `ci` ran before `package`, so the file it reads was not there.

```bash
node pitfall.mjs
```

```text output
yo service (composed)          npm ci, npm run test
yo service:package, then :ci   npm ci, npm run test
yo service:ci first            npm ci
port, Workflow called first    npm ci, npm run test
```

Both ported orders give the full workflow, because the port reads the scripts from the model. Find
every `this.fs.read` and `readJSON` in your sub-generators before you port, and move each value it
reads into the model.

A service name with a quote in it breaks `server.js` differently in each tool. The EJS tag `<%=` escapes HTML, so
the original wrote `o&#39;reilly`, and `$$service$$` writes the quote itself, which ends the
JavaScript string early. Validate answers in `toModel`, as the sample does, so a bad name fails
before a file exists.

A port test passes on an empty run. Assert that the Yeoman run wrote files before comparing, as
`parity.test.mjs` does, or two empty trees compare equal.

## Run the client step with orval or OpenAPI Generator

orval writes API code and nothing else, so it has no mechanism for the rest of a scaffold. A team
that generates its client with orval keeps the client step in the scaffold's command through
orval's [programmatic API](https://orval.dev/docs/reference/integration/). `with-orval.mjs` runs
the port and then `generate()`, and `generate.sh` ran it once and committed what it wrote.

```js title="with-orval.mjs"
const res = await generateService({ name: 'orders', port: 8080, ci: true }, { folder: out })
for (const f of res.files.written) console.log(`jostraca wrote ${f.slice(out.length + 1)}`)

// generate() logs a failed generation and resolves unless throwOnError is set.
await generate({
  input: { target: resolve('api.json') },
  output: { target: join(out, 'src/client/bookshelf.ts'), client: 'fetch' },
}, process.cwd(), { throwOnError: true })
if (!existsSync(join(out, 'src/client/bookshelf.ts'))) throw new Error('orval wrote no client')
console.log('orval wrote src/client/bookshelf.ts')
```

A team on OpenAPI Generator can move a sub-generator that only adds files into the generator's own
configuration. Its [`files` node](https://openapi-generator.tech/docs/customization/) renders a
template as a supporting file, and `additionalProperties` carries the answers.

```yaml title="openapi-generator/config.yaml"
generatorName: typescript-fetch
inputSpec: api.json
templateDir: openapi-generator/templates
additionalProperties:
  service: orders
files:
  ci.yml.mustache:
    templateType: SupportingFiles
    folder: .github/workflows
    destinationFilename: ci.yml
```

`show-records.mjs` reads both runs back from the committed files.

```bash
node show-records.mjs
```

```text output
node with-orval.mjs, one command, wrote:
  package.json
  src/server.js
  .github/workflows/ci.yml
  src/client/bookshelf.ts
orval client functions: createBook, deleteBook, getBook, listBooks, updateBook
OpenAPI Generator wrote 12 files, its FILES list names 10, among them .github/workflows/ci.yml
its ci.yml is byte-identical to the port's: true
```

The Mustache template writes the test step as fixed text, since a logic-less template cannot
filter the scripts. OpenAPI Generator's
[`batch` command](https://openapi-generator.tech/docs/usage/#batch) runs several configurations in
one command, and its `!include` property lets them share one file of settings.

## When not to do this

Do not port a generator that works and has someone keeping its dependencies current. Yeoman's
composition is the feature this page spends most of its length rebuilding.

Do not choose jostraca if your users expect to answer questions and get a project. It has no
prompt layer and no install step, so the port carries `port/answers.mjs` and whatever runs
`npm install` afterwards.

Do not port to Plop or Copier and then document the order of the commands. If sub-generators
share answers or files, keep them in one run.

If the scaffold exists mainly to wrap a client, OpenAPI Generator's `files` node may be the whole
generator you need. It suits a team whose extra files are few, static and tied to the client,
which is less to maintain than a component tree. Keep orval for the client alone: its
`generate()` call fits inside whatever command writes the rest. Copier suits a fleet of projects
that must take template updates.

## Related how-tos

- [Generate a code section with code instead of a template](/howto/generate-a-code-section-with-a-component)

- [Drive code generation from a script instead of the CLI](/howto/drive-code-generation-from-a-script)

- [Scaffold a Python API client project with Cookiecutter](/howto/scaffold-a-python-project-with-cookiecutter)

- [Set an overwrite policy for a regenerated SDK](/howto/set-an-overwrite-policy-for-regeneration)

- [Compose one generated file from several components](/howto/compose-generated-files-with-slots-and-fragments)

## Last verified

Verified 2026-11-22 against Node 22.23.5, jostraca 0.42.0, shape 12.2.5, yeoman-generator 10.3.1,
yeoman-environment 8.9.0, yeoman-test 11.8.2, orval 8.48.0 and OpenAPI Generator 7.27.0. Every
output block is what the command preceding it printed. orval and OpenAPI Generator ran once in
`generate.sh`, and the page's commands read what they committed. Plop and Copier were not run;
their rows come from their documentation, read on the same day.

[^1]: Yeoman's [page on composing generators](https://yeoman.io/authoring/composability.html) introduces
the idea by comparison with Voltron, trademark sign included. It names two ways to start a
composition, by a generator or by the end user, and then adds that the second is a planned feature
and not available.

[^2]: The test suite this port replaces has its own drift. Yeoman's
[testing page](https://yeoman.io/authoring/testing.html) shows answers passed with `withPrompts`.
yeoman-test 11.8.2 still accepts the call and marks it deprecated in
[its type declarations](https://unpkg.com/yeoman-test@11.8.2/dist/run-context.d.ts). Its
[compiled source](https://unpkg.com/yeoman-test@11.8.2/dist/run-context.js) hands the answers on
to `withAnswers` in one line.