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
+
### Using TypeScript plopfiles
134
+
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).
136
+
137
+
First, make a TypesScript plopfile:
138
+
139
+
```ts
140
+
// plopfile.ts
141
+
import {NodePlopAPI} from'plop';
142
+
143
+
exportdefaultfunction (plop:NodePlopAPI) {
144
+
// plop generator code
145
+
};
146
+
```
147
+
148
+
Next, install [tsx](https://github.com/privatenumber/tsx) and optionally [cross-env](https://www.npmjs.com/package/cross-env):
149
+
150
+
```bash
151
+
npm i -D tsx cross-env
152
+
```
153
+
154
+
Finally, use `NODE_OPTIONS` to activate the tsx loader. Now Plop can import your `plopfile.ts`:
Because when you create your boilerplate separate from your code, you naturally put more time and thought into it.
135
176
@@ -140,18 +181,13 @@ Because [context switching is expensive](https://www.petrikainulainen.net/softwa
140
181
# Plopfile API
141
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.
142
183
143
-
## TypeScript Declarations
184
+
## TypeScript Support
144
185
145
-
`plop` bundles TypeScript declarations. Whether or not you write your plopfile in TypeScript, many editors will offer code assistance via these declarations.
186
+
Plop bundles TypeScript declarations. See [using TypeScript plopfiles](#using-typescript-plopfiles) for more details.
146
187
147
-
```javascript
148
-
// plopfile.ts
149
-
import {NodePlopAPI} from'plop';
188
+
## JSDoc Support
150
189
151
-
exportdefaultfunction (plop:NodePlopAPI) {
152
-
// plop generator code
153
-
};
154
-
```
190
+
Whether or not you write your plopfile in TypeScript, many editors will offer code assistance via JSDoc declarations.
0 commit comments