Skip to content

Commit a903d63

Browse files
committed
**feature:** Add new option IGNORE_SPEC: Now you can skip the generation of spec files
1 parent 8baadcd commit a903d63

File tree

9 files changed

+73
-22
lines changed

9 files changed

+73
-22
lines changed

ngx-reduxor.config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"BASE_PATH": "./examples",
3-
"SEPARATE_DIRECTORY": false
3+
"SEPARATE_DIRECTORY": false,
4+
"IGNORE_SPEC": false
45
}

src/actions/basic-actions.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,13 @@ module.exports = {
2020
type: 'add',
2121
path: '{{ basePath }}/{{ folder name "reducers"}}/{{kebabCase name}}.reducer.spec.ts',
2222
templateFile: './templates/Basic/_reducer.spec.ts'
23-
}
24-
],
23+
}],
24+
25+
reducerWithoutSpec: [{
26+
type: 'add',
27+
path: '{{ basePath }}/{{ folder name "reducers" }}/{{kebabCase name}}.reducer.ts',
28+
templateFile: './templates/Basic/_reducer.ts'
29+
}],
2530

2631
/*
2732
* Effect generator
@@ -33,7 +38,13 @@ module.exports = {
3338
}, {
3439
type: 'add',
3540
path: '{{ basePath }}/{{ folder name "effects" }}/{{kebabCase name}}.effects.spec.ts',
36-
templateFile: './templates/Basic/_effects.spec.ts'
41+
templateFile: './templates/Basic/_effect.spec.ts'
42+
}],
43+
44+
effectWithoutSpec: [{
45+
type: 'add',
46+
path: '{{ basePath }}/{{ folder name "effects" }}/{{kebabCase name}}.effects.ts',
47+
templateFile: './templates/Basic/_effect.ts'
3748
}],
3849

3950
/*
@@ -47,5 +58,11 @@ module.exports = {
4758
type: 'add',
4859
path: '{{ basePath }}/{{ folder name "services" }}/{{kebabCase name}}.service.spec.ts',
4960
templateFile: './templates/Basic/_service.spec.ts'
61+
}],
62+
63+
serviceWithoutSpec: [{
64+
type: 'add',
65+
path: '{{ basePath }}/{{ folder name "services" }}/{{kebabCase name}}.service.ts',
66+
templateFile: './templates/Basic/_service.ts'
5067
}]
5168
}

src/actions/crud-actions.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ module.exports = {
2222
templateFile: './templates/CRUD/_reducer.spec.ts'
2323
}
2424
],
25+
26+
reducerWithoutSpec: [{
27+
type: 'add',
28+
path: '{{ basePath }}/{{ folder name "reducers" }}/{{kebabCase name}}.reducer.ts',
29+
templateFile: './templates/CRUD/_reducer.ts'
30+
}],
2531

2632
/*
2733
* Effect generator
@@ -33,7 +39,13 @@ module.exports = {
3339
}, {
3440
type: 'add',
3541
path: '{{ basePath }}/{{ folder name "effects" }}/{{kebabCase name}}.effects.spec.ts',
36-
templateFile: './templates/CRUD/_effects.spec.ts'
42+
templateFile: './templates/CRUD/_effect.spec.ts'
43+
}],
44+
45+
effectWithoutSpec: [{
46+
type: 'add',
47+
path: '{{ basePath }}/{{ folder name "effects" }}/{{kebabCase name}}.effects.ts',
48+
templateFile: './templates/CRUD/_effect.ts'
3749
}],
3850

3951
/*
@@ -47,5 +59,11 @@ module.exports = {
4759
type: 'add',
4860
path: '{{ basePath }}/{{ folder name "services" }}/{{kebabCase name}}.service.spec.ts',
4961
templateFile: './templates/CRUD/_service.spec.ts'
62+
}],
63+
64+
serviceWithoutSpec: [{
65+
type: 'add',
66+
path: '{{ basePath }}/{{ folder name "services" }}/{{kebabCase name}}.service.ts',
67+
templateFile: './templates/CRUD/_service.ts'
5068
}]
5169
}

src/actions/crud-entity-actions.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,13 @@ module.exports = {
2020
type: 'add',
2121
path: '{{ basePath }}/{{ folder name "reducers"}}/{{kebabCase name}}.reducer.spec.ts',
2222
templateFile: './templates/CRUD-entity/_reducer.spec.ts'
23-
}
24-
],
23+
}],
24+
25+
reducerWithoutSpec: [{
26+
type: 'add',
27+
path: '{{ basePath }}/{{ folder name "reducers" }}/{{kebabCase name}}.reducer.ts',
28+
templateFile: './templates/CRUD-entity/_reducer.ts'
29+
}],
2530

2631
/*
2732
* Effect generator
@@ -33,7 +38,13 @@ module.exports = {
3338
}, {
3439
type: 'add',
3540
path: '{{ basePath }}/{{ folder name "effects" }}/{{kebabCase name}}.effects.spec.ts',
36-
templateFile: './templates/CRUD-entity/_effects.spec.ts'
41+
templateFile: './templates/CRUD-entity/_effect.spec.ts'
42+
}],
43+
44+
effectWithoutSpec: [{
45+
type: 'add',
46+
path: '{{ basePath }}/{{ folder name "effects" }}/{{kebabCase name}}.effects.ts',
47+
templateFile: './templates/CRUD-entity/_effect.ts'
3748
}],
3849

3950
/*
@@ -47,6 +58,12 @@ module.exports = {
4758
type: 'add',
4859
path: '{{ basePath }}/{{ folder name "services" }}/{{kebabCase name}}.service.spec.ts',
4960
templateFile: './templates/CRUD-entity/_service.spec.ts'
61+
}],
62+
63+
serviceWithoutSpec: [{
64+
type: 'add',
65+
path: '{{ basePath }}/{{ folder name "services" }}/{{kebabCase name}}.service.ts',
66+
templateFile: './templates/CRUD-entity/_service.ts'
5067
}]
5168
}
5269

src/default.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"BASE_PATH": "./src/store",
33
"SEPARATE_DIRECTORY": false,
4-
"HAS_ROUTER_SERIALIZER": false
4+
"IGNORE_SPEC": false
55
}

src/generators/create.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ const fs = require('fs-extra');
33
// actions
44
const basicActions = require('../actions/basic-actions');
55
const crudActions = require('../actions/crud-actions');
6-
7-
// actions with entity
86
const crudEntityActions = require('../actions/crud-entity-actions');
97

108
// modules
@@ -41,24 +39,24 @@ module.exports = function(options) {
4139
}
4240
],
4341
actions: (data) => {
44-
let actions = [];
45-
if(data.store === 'Basic') {
46-
actions = actions.concat(basicActions.action, basicActions.reducer, basicActions.effect, basicActions.service);
47-
} else { // CRUD
48-
if (data.entity === 'Yes') {
49-
actions = actions.concat(crudEntityActions.action, crudEntityActions.reducer, crudEntityActions.effect, crudEntityActions.service);
50-
} else {
51-
actions = actions.concat(crudActions.action, crudActions.reducer, crudActions.effect, crudActions.service);
52-
}
53-
}
42+
let actions =
43+
options.IGNORE_SPEC ?
44+
data.store === 'Basic' ? [basicActions.action, basicActions.reducerWithoutSpec, basicActions.effectWithoutSpec, basicActions.serviceWithoutSpec]
45+
: data.entity === 'Yes' ? [crudEntityActions.action, crudEntityActions.reducerWithoutSpec, crudEntityActions.effectWithoutSpec, crudEntityActions.serviceWithoutSpec]
46+
: [crudActions.action, crudActions.reducerWithoutSpec, crudActions.effectWithoutSpec, crudActions.serviceWithoutSpec]
47+
: data.store === 'Basic' ? [basicActions.action, basicActions.reducer, basicActions.effect, basicActions.service]
48+
: data.entity === 'Yes' ? [crudEntityActions.action, crudEntityActions.reducer, crudEntityActions.effect, crudEntityActions.service]
49+
: [crudActions.action, crudActions.reducer, crudActions.effect, crudActions.service]
50+
5451
const indexExists = fs.existsSync(options.BASE_PATH, 'app.store.ts');
5552
const allEffectsExists = fs.existsSync(options.BASE_PATH, 'all-effects.ts');
5653
const storeReduxorModuleExists = fs.existsSync(options.BASE_PATH, 'store-reduxor.module.ts');
5754
actions = indexExists ? actions.concat(modulesActions.updateIndex) : actions.concat(modulesActions.addIndex);
5855
actions = allEffectsExists ? actions.concat(modulesActions.updateAllEffects) : actions.concat(modulesActions.addAllEffects);
5956
actions = storeReduxorModuleExists ? actions.concat(modulesActions.updateStoreReduxorModule) : actions.concat(modulesActions.addStoreReduxorModule);
6057

61-
return actions;
58+
const actionsFlattened = actions.reduce((a, b) => a.concat(b));
59+
return actionsFlattened;
6260
}
6361
}
6462
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)