Skip to content

Commit 0bba0f2

Browse files
authored
Merge pull request #333 from plopjs/shorthand-load-all-plop-assets
Shorthand to load all plop assets
2 parents 8a296e3 + d6176cc commit 0bba0f2

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

.changeset/old-balloons-look.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"node-plop": minor
3+
"plop": minor
4+
---
5+
6+
Added shorthand to load all Plop assets at once #333

packages/node-plop/src/node-plop.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,25 +125,25 @@ async function nodePlop(plopfilePath = "", plopCfg = {}) {
125125
const genNameList = proxy.getGeneratorList().map((g) => g.name);
126126
loadAsset(
127127
genNameList,
128-
include.generators,
128+
includeCfg === true || include.generators,
129129
setGenerator,
130130
(proxyName) => ({ proxyName, proxy })
131131
);
132132
loadAsset(
133133
proxy.getPartialList(),
134-
include.partials,
134+
includeCfg === true || include.partials,
135135
setPartial,
136136
proxy.getPartial
137137
);
138138
loadAsset(
139139
proxy.getHelperList(),
140-
include.helpers,
140+
includeCfg === true || include.helpers,
141141
setHelper,
142142
proxy.getHelper
143143
);
144144
loadAsset(
145145
proxy.getActionTypeList(),
146-
include.actionTypes,
146+
includeCfg === true || include.actionTypes,
147147
setActionType,
148148
proxy.getActionType
149149
);

packages/node-plop/tests/load-assets-from-plopfile/load-assets-from-plopfile.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,21 @@ describe("load-assets-from-plopfile", function () {
9393
expect(plop.getActionTypeList().includes("test-actionType1")).toBe(true);
9494
});
9595

96+
test("plop.load passes a config option that can be used to include all the plopfile output", async function () {
97+
const plop = await nodePlop();
98+
await plop.load(plopfilePath, { prefix: "test-" }, true);
99+
100+
const gNameList = plop.getGeneratorList().map((g) => g.name);
101+
expect(gNameList.length).toBe(3);
102+
expect(plop.getHelperList().length).toBe(3);
103+
expect(plop.getPartialList().length).toBe(3);
104+
expect(plop.getActionTypeList().length).toBe(1);
105+
expect(gNameList.includes("test-generator1")).toBe(true);
106+
expect(plop.getHelperList().includes("test-helper2")).toBe(true);
107+
expect(plop.getPartialList().includes("test-partial3")).toBe(true);
108+
expect(plop.getActionTypeList().includes("test-actionType1")).toBe(true);
109+
});
110+
96111
test("plop.load should import functioning assets", async function () {
97112
const plop = await nodePlop();
98113
await plop.load(

packages/plop/plop-load.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ plop.load
1818
`config` is an object that can be passed to the plopfile or `plop-pack` when they are run. This allows the consumer of the plopfile or `plop-pack` to configure certain aspects of its functionality. To know what properties should be in this object, see the documentation provided by the author.
1919

2020
#### include
21-
- **type:** `Object`
21+
- **type:** `Object` or `Boolean`
2222
- **default:** `{ generators:true, helpers:false, partials:false, actionTypes:false }`
2323
- **optional**
2424

25-
`include` is an object that can contain 4 properties (`generators`, `helpers`, `partials`, and `actionTypes`). Each of these properties should have an [`IncludeDefinition`](#IncludeDefinition) as its value. Most of the time this object is not needed because the plopfile or `plop-pack` is able to specify a default [`IncludeDefinition`](#IncludeDefinition) to be used.
25+
If `include` is `true` all assets from the target will be included (none if `false`). Otherwise, `include` should be an object that can contain 4 properties (`generators`, `helpers`, `partials`, and `actionTypes`). Each of these properties should have an [`IncludeDefinition`](#Interface-IncludeDefinition) as its value. Most of the time this object is not needed because the plopfile or `plop-pack` is able to specify a default [`IncludeDefinition`](#Interface-IncludeDefinition) to be used.
2626

2727
#### Interface `IncludeDefinition`
2828
- **Boolean:** `true` will include all assets, `false` will include non of them.
@@ -35,6 +35,11 @@ plop.load
3535
// loads all 5 generators, no helpers, actionTypes or partials (even if they exist)
3636
plop.load('./plopfiles/component.js');
3737
```
38+
*load all assets from a path*
39+
```javascript
40+
// loads all 5 generators, all helpers, actionTypes and partials (if they exist)
41+
plop.load('./plopfiles/component.js', {}, true);
42+
```
3843
*load via a path with a custom include config*
3944
```javascript
4045
// loads all helpers, no generators, actionTypes or partials (even if they exist)

0 commit comments

Comments
 (0)