Skip to content

Commit dad313a

Browse files
committed
wip
1 parent dc6045b commit dad313a

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

README.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,21 +130,13 @@ $ plop component -- --type react
130130
### Running a Generator Forcefully
131131
By default Plop actions keep your files safe by failing when things look fishy. The most obvious example of this is not allowing an [`add`](#add) action to overwrite a file that already exists. Plop actions individually support the `force` property but you can also use the `--force` flag when running Plop from the terminal. Using the `--force` flag will tell every action to run forcefully. With great power...🕷
132132

133-
## Why Generators?
134-
Because when you create your boilerplate separate from your code, you naturally put more time and thought into it.
135-
136-
Because saving your team (or yourself) 5-15 minutes when creating every route, component, controller, helper, test, view, etc... [really adds up](https://xkcd.com/1205/).
137-
138-
Because [context switching is expensive](https://www.petrikainulainen.net/software-development/processes/the-cost-of-context-switching/) and saving time is not the only [benefit to automating workflows](https://kentcdodds.com/blog/automation)
133+
### Using TypeScript plopfiles
139134

140-
# Plopfile API
141-
The plopfile api is the collection of methods that are exposed by the `plop` object. Most of the work is done by [`setGenerator`](#setgenerator) but this section documents the other methods that you may also find useful in your plopfile.
142-
143-
## TypeScript Support
135+
Plop bundles TypeScript declarations and supports TypeScript plopfiles via [tsx loaders](https://github.com/privatenumber/tsx?tab=readme-ov-file#nodejs-loader), a feature of [NodeJS command line imports](https://nodejs.org/api/cli.html#--importmodule).
144136

145-
Plop bundles TypeScript declarations and supports TypeScript plopfiles via [NodeJS command line imports](https://nodejs.org/api/cli.html#--importmodule).
137+
First, make a TypesScript plopfile:
146138

147-
```javascript
139+
```ts
148140
// plopfile.ts
149141
import {NodePlopAPI} from 'plop';
150142

@@ -153,12 +145,14 @@ export default function (plop: NodePlopAPI) {
153145
};
154146
```
155147

156-
Plop can use a native `polopfile.ts` without compiling it ahead of time by using [tsx loaders](https://github.com/privatenumber/tsx?tab=readme-ov-file#nodejs-loader):
148+
Next, install [tsx](https://github.com/privatenumber/tsx) and optionally [cross-env](https://www.npmjs.com/package/cross-env):
157149

158150
```bash
159151
npm i -D tsx cross-env
160152
```
161153

154+
Finally, use `NODE_OPTIONS` to activate the tsx loader. Now Plop can import your `plopfile.ts`:
155+
162156
**Node.js v20.6 and above**
163157

164158
```json
@@ -177,6 +171,19 @@ npm i -D tsx cross-env
177171
}
178172
```
179173

174+
## Why Generators?
175+
Because when you create your boilerplate separate from your code, you naturally put more time and thought into it.
176+
177+
Because saving your team (or yourself) 5-15 minutes when creating every route, component, controller, helper, test, view, etc... [really adds up](https://xkcd.com/1205/).
178+
179+
Because [context switching is expensive](https://www.petrikainulainen.net/software-development/processes/the-cost-of-context-switching/) and saving time is not the only [benefit to automating workflows](https://kentcdodds.com/blog/automation)
180+
181+
# Plopfile API
182+
The plopfile api is the collection of methods that are exposed by the `plop` object. Most of the work is done by [`setGenerator`](#setgenerator) but this section documents the other methods that you may also find useful in your plopfile.
183+
184+
## TypeScript Support
185+
186+
Plop bundles TypeScript declarations. See [using TypeScript plopfiles](#using-typescript-plopfiles) for more details.
180187

181188
## JSDoc Support
182189

0 commit comments

Comments
 (0)