You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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...🕷
132
132
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
139
134
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).
144
136
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:
146
138
147
-
```javascript
139
+
```ts
148
140
// plopfile.ts
149
141
import {NodePlopAPI} from'plop';
150
142
@@ -153,12 +145,14 @@ export default function (plop: NodePlopAPI) {
153
145
};
154
146
```
155
147
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):
157
149
158
150
```bash
159
151
npm i -D tsx cross-env
160
152
```
161
153
154
+
Finally, use `NODE_OPTIONS` to activate the tsx loader. Now Plop can import your `plopfile.ts`:
155
+
162
156
**Node.js v20.6 and above**
163
157
164
158
```json
@@ -177,6 +171,19 @@ npm i -D tsx cross-env
177
171
}
178
172
```
179
173
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.
0 commit comments