boilersuit
Advanced tools
Comparing version 0.4.1 to 0.4.2
@@ -143,66 +143,76 @@ const colors = require('colors'); // eslint-disable-line | ||
...Object.keys(schema.import[key]) | ||
.map(domain => [ | ||
...(schema.import[key][domain].selectors | ||
? schema.import[key][domain].selectors.map(selector => { | ||
const importedState = importedSchema[domain].initialState; | ||
if (typeof importedState[selector] === 'undefined') { | ||
errors.push( | ||
`Import failed: ` + | ||
`${selector}`.cyan + | ||
` not found in the initialState of ` + | ||
`${domain} `.cyan + | ||
`in ` + | ||
`"${key}suit.json"`.cyan, | ||
); | ||
} | ||
return { | ||
value: `${domain}${capitalize(selector)}`, | ||
property: `makeSelect${capitalize(domain)}${capitalize( | ||
selector, | ||
)}`, | ||
selector: `makeSelect${capitalize(domain)}${capitalize( | ||
selector, | ||
)}`, | ||
path: key, | ||
type: 'selector', | ||
initialValue: | ||
importedSchema[domain].initialState[selector], | ||
fileName: `${key}selectors`, | ||
}; | ||
}) | ||
: []), | ||
...(schema.import[key][domain].actions | ||
? schema.import[key][domain].actions.map(action => { | ||
const importedAction = | ||
importedSchema[domain].actions[action]; | ||
if (!importedAction) { | ||
errors.push( | ||
`Import failed: ` + | ||
`${action}`.cyan + | ||
` not found in ` + | ||
`${domain} `.cyan + | ||
`in ` + | ||
`"${key}suit.json"`.cyan, | ||
); | ||
return {}; | ||
} | ||
return { | ||
property: `${action}`, | ||
action, | ||
describe: importedAction.describe || '', | ||
path: key, | ||
payload: | ||
importedAction.payload || | ||
( | ||
importedAction.set && | ||
Object.values(importedAction.set).filter(value => | ||
`${value}`.includes('payload'), | ||
) | ||
).length, | ||
type: 'action', | ||
fileName: `${key}actions`, | ||
}; | ||
}) | ||
: []), | ||
]) | ||
.map(domain => { | ||
const domainObject = schema.import[key][domain]; | ||
const hasSelectors = | ||
typeof domainObject.selectors !== 'undefined'; | ||
const selectors = !hasSelectors | ||
? [] | ||
: typeof domainObject.selectors === 'string' | ||
? [domainObject.selectors] | ||
: domainObject.selectors; | ||
const hasActions = typeof domainObject.actions !== 'undefined'; | ||
const actions = !hasActions | ||
? [] | ||
: typeof domainObject.actions === 'string' | ||
? [domainObject.actions] | ||
: domainObject.actions; | ||
return [ | ||
...selectors.map(selector => { | ||
const importedState = importedSchema[domain].initialState; | ||
if (typeof importedState[selector] === 'undefined') { | ||
errors.push( | ||
`Import failed: ` + | ||
`${selector}`.cyan + | ||
` not found in the initialState of ` + | ||
`${domain} `.cyan + | ||
`in ` + | ||
`"${key}suit.json"`.cyan, | ||
); | ||
} | ||
return { | ||
value: `${domain}${capitalize(selector)}`, | ||
property: `makeSelect${capitalize(domain)}${capitalize( | ||
selector, | ||
)}`, | ||
selector: `makeSelect${capitalize(domain)}${capitalize( | ||
selector, | ||
)}`, | ||
path: key + key[key.length - 1] === '/' ? '' : '/', | ||
type: 'selector', | ||
initialValue: importedSchema[domain].initialState[selector], | ||
fileName: `${key}selectors`, | ||
}; | ||
}), | ||
...actions.map(action => { | ||
const importedAction = importedSchema[domain].actions[action]; | ||
if (!importedAction) { | ||
errors.push( | ||
`Import failed: ` + | ||
`${action}`.cyan + | ||
` not found in ` + | ||
`${domain} `.cyan + | ||
`in ` + | ||
`"${key}suit.json"`.cyan, | ||
); | ||
return {}; | ||
} | ||
return { | ||
property: `${action}`, | ||
action, | ||
describe: importedAction.describe || '', | ||
path: key, | ||
payload: | ||
importedAction.payload || | ||
( | ||
importedAction.set && | ||
Object.values(importedAction.set).filter(value => | ||
`${value}`.includes('payload'), | ||
) | ||
).length, | ||
type: 'action', | ||
fileName: `${key}actions`, | ||
}; | ||
}), | ||
]; | ||
}) | ||
.reduce((a, b) => [...a, ...b], []), | ||
@@ -209,0 +219,0 @@ ]; |
const colors = require('colors'); // eslint-disable-line | ||
const writeIndex = require('./writeIndex'); | ||
const writeImportsToIndex = require('./writeImportsToIndex'); | ||
const Cases = require('../../../tools/cases'); | ||
@@ -15,15 +16,21 @@ const { | ||
fixInlineImports, | ||
...arrayOfDomains.map(({ domainName, actions, initialState }) => b => { | ||
const cases = new Cases(parseCamelCaseToArray(domainName)); | ||
const allDomainCases = cases.all(); | ||
...arrayOfDomains | ||
.filter(({ mapToContainer }) => mapToContainer !== false) | ||
.map(({ domainName, actions, initialState }) => b => { | ||
const cases = new Cases(parseCamelCaseToArray(domainName)); | ||
const allDomainCases = cases.all(); | ||
return writeIndex({ | ||
return writeIndex({ | ||
buffer: b, | ||
cases: allDomainCases, | ||
initialState, | ||
keyChanges, | ||
actions, | ||
}); | ||
}), | ||
b => | ||
writeImportsToIndex({ | ||
imports, | ||
buffer: b, | ||
imports, | ||
cases: allDomainCases, | ||
initialState, | ||
keyChanges, | ||
actions, | ||
}); | ||
}), | ||
}), | ||
]); |
@@ -11,10 +11,3 @@ const Cases = require('../../../tools/cases'); | ||
module.exports = ({ | ||
buffer, | ||
cases, | ||
initialState, | ||
actions, | ||
keyChanges, | ||
imports, | ||
}) => { | ||
module.exports = ({ buffer, cases, initialState, actions, keyChanges }) => { | ||
/** Checks if the passAsProp keyword is present */ | ||
@@ -41,8 +34,2 @@ const hasPropFiltering = Object.values(actions).filter(actionValues => | ||
]), | ||
b => | ||
transforms(b, [ | ||
...imports.map(({ property, fileName }) => | ||
ensureImport(property, fileName, { destructure: true }), | ||
), | ||
]), | ||
/** Import actions */ | ||
@@ -78,11 +65,2 @@ b => | ||
}), | ||
...imports | ||
.filter(({ type }) => type === 'selector') | ||
.filter( | ||
({ selector, value }) => | ||
b.indexOf(` ${value}: ${selector}(),`) === -1, | ||
) | ||
.map(({ selector, value }) => | ||
concat([` ${value}: ${selector}(),`]), | ||
), | ||
' // @suit-end', | ||
@@ -104,19 +82,2 @@ b.slice(index), | ||
' // @suit-start', | ||
...imports | ||
.filter(({ type }) => type === 'action') | ||
.filter( | ||
({ action }) => | ||
b.indexOf( | ||
`submit${capitalize(action)}: (`, | ||
b.indexOf('mapDispatchToProps'), | ||
) === -1, | ||
) | ||
.map(({ action, describe, payload }) => | ||
concat([ | ||
describe ? ` /** ${describe} */` : null, | ||
` submit${capitalize(action)}: (${ | ||
payload ? 'payload' : '' | ||
}) => dispatch(${action}(${payload ? 'payload' : ''})),`, | ||
]), | ||
), | ||
...Object.keys(actions) | ||
@@ -248,25 +209,2 @@ .filter(key => { | ||
.map(key => ` // submit${capitalize(key)}: PropTypes.func,`), | ||
...imports | ||
.filter(({ type }) => type === 'selector') | ||
.filter( | ||
({ value }) => propTypesSlice.indexOf(`${value}: PropTypes`) === -1, | ||
) | ||
.map( | ||
({ initialValue, value }) => | ||
` // ${value}: PropTypes.${propTypeFromTypeOf( | ||
typeof initialValue, | ||
)},`, | ||
), | ||
...imports | ||
.filter(({ type }) => type === 'action') | ||
.filter( | ||
({ property }) => | ||
propTypesSlice.indexOf( | ||
`submit${capitalize(property)}: PropTypes.func,`, | ||
) === -1, | ||
) | ||
.map( | ||
({ property }) => | ||
` // submit${capitalize(property)}: PropTypes.func,`, | ||
), | ||
]; | ||
@@ -273,0 +211,0 @@ const arrayOfLines = b.split('\n'); |
{ | ||
"name": "boilersuit", | ||
"description": "A CLI tool for generating selectors, reducers, actions, constants and sagas in react-boilerplate", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "author": "Matt Pocock <matt.pocock@thevirtualforge.com>", |
@@ -227,2 +227,26 @@ <div style="text-align: center"><img src="https://raw.githubusercontent.com/mattpocock/boilersuit/master/logo.png" max-height="240px" alt="boilerplate logo"/></div> | ||
### mapToContainer | ||
Sometimes, you don't want to actually pass your reducer to the container that it shares a file with. This is especially true when initialising some global functions that lots of subcontainers share, such as configurations. | ||
When you don't want to pass the reducer to the container, just specify `"mapToContainer": false` on the reducer. This will stop index.js from being written at all by this reducer. | ||
```json | ||
{ | ||
"getImages": { | ||
"mapToContainer": false, | ||
"initialState": { | ||
"isLoading": false, | ||
"hasSucceeded": true, | ||
"data": null, | ||
"errorMessage": "", | ||
"hasError": false | ||
}, | ||
"actions": { | ||
//... | ||
} | ||
} | ||
} | ||
``` | ||
### actions | ||
@@ -229,0 +253,0 @@ |
@@ -10,3 +10,3 @@ const { concat } = require('./utils'); | ||
); | ||
if (!domainKeys.length) { | ||
if (!domainKeys.length && !schema.import) { | ||
errors.push( | ||
@@ -13,0 +13,0 @@ concat([ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
462574
69
3422
567