Skip to content

Commit

Permalink
Improve plop-dir README examples
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronccasanova committed Sep 18, 2022
1 parent df4b4af commit 46b5337
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 28 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-stingrays-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'plop-dir': patch
---

Improve README examples
30 changes: 15 additions & 15 deletions packages/plop-dir/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
/** @param {import('plop').NodePlopAPI} plop */
export default async function run(plop) {
plop.setGenerator(
'my-generator',
'my-template',
await plopDir({
plop,
// Path to my-generator templates
templateDir: path.join(__dirname, './templates/my-generator'),
// Path to output my-generator files
// Path to my-template templates
templateDir: path.join(__dirname, './templates/my-template'),
// Path to output my-template files
outputDir: path.join(__dirname, './src'),
// Override or extend the inferred prompts
prompts: [
{
name: 'generatorName',
message: "What's the name of the generator?",
name: 'templateName',
message: "What's the name of your template?",
},
],
}),
Expand All @@ -65,28 +65,28 @@ Example template directory:
plopfile.mjs
src/
templates/
|__ my-generator/
|-- {{kebabCase extractedPrompt}}.js
|__ my-template/
|-- {{kebabCase templateName}}.js
|__ tests/
|__ {{kebabCase anotherPrompt}}.test.js
|__ {{kebabCase templateName}}.test.js
```
Example template file `{{kebabCase extractedPrompt}}.js`:
Example template file `my-template/tests/{{kebabCase templateName}}.js`:
> See the [plop docs](https://plopjs.com/documentation/#case-modifiers) for all
> available case modifiers
```js
export default function {{camelCase extractedPrompt}}() {
return '{{sentenceCase anotherPrompt}}'
export default function {{camelCase testName}}() {
return '{{pascalCase templateName}}'
}
```
Run the `plop` CLI:
```sh
$ npm run plop my-generator
Enter extractedPrompt: <answer>
Enter anotherPrompt: <answer>
$ npm run plop my-template
Whats the name of your template? <answer>
Enter testName <answer>
✔ plop-dir successfully wrote files to <outputDir>
```
12 changes: 6 additions & 6 deletions packages/plop-dir/plopfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ const __dirname = path.dirname(url.fileURLToPath(import.meta.url))
// eslint-disable-next-line import/no-default-export
export default async function run(plop) {
plop.setGenerator(
'my-generator',
'my-template',
await plopDir({
plop,
// Path to my-generator templates
templateDir: path.join(__dirname, './templates/my-generator'),
// Path to output my-generator files
// Path to my-template templates
templateDir: path.join(__dirname, './templates/my-template'),
// Path to output my-template files
outputDir: path.join(__dirname, './tmp'),
// Override or extend the inferred prompts
prompts: [
{
name: 'generatorName',
message: "What's the name of the generator?",
name: 'templateName',
message: "What's the name of your template?",
},
],
}),
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default function {{camelCase testName}}() {
return '{{pascalCase testContentName}}';
return '{{pascalCase templateName}}';
}

0 comments on commit 46b5337

Please sign in to comment.