1+ const { configValidator, routeSplit} = require ( '../scully/bin' ) ;
12
2- const { configValidator} = require ( '../scully/bin' ) ;
3-
4- console . log ( __dirname )
5-
6- exports . extraRoutesPlugin = ( route , options ) => {
3+ const extraRoutesPlugin = ( route , options ) => {
74 const { createPath} = routeSplit ( route ) ;
85 if ( options . numberOfPages ) {
96 return Array . from ( { length : options . numberOfPages } , ( _v , k ) => k ) . map ( n => ( {
@@ -19,6 +16,31 @@ exports.extraRoutesPlugin = (route, options) => {
1916 }
2017 return [ ] ;
2118} ;
22- /** the validator is mandatory */
23- exports . extraRoutesPlugin [ configValidator ] = async options => [ ] ;
2419
20+ extraRoutesPlugin [ configValidator ] = async options => {
21+ const errors = [ ] ;
22+
23+ if ( options . numberOfPages && typeof options . numberOfPages !== 'number' ) {
24+ errors . push (
25+ `extraroutesPlugin plugin numberOfPages should be a number, not a ${ typeof options . numberOfPages } `
26+ ) ;
27+ }
28+ if ( options . numberOfPages && options . data ) {
29+ errors . push ( `extraroutesPlugin plugin can't have property 'numberOfPages' and 'data' at the same time` ) ;
30+ }
31+ if ( options . data ) {
32+ if ( ! Array . isArray ( options . data ) ) {
33+ errors . push ( `extraroutesPlugin property 'data' needs to be an array` ) ;
34+ } else {
35+ if ( ! options . data . every ( item => typeof item . title === 'string' && typeof item . data === 'string' ) ) {
36+ errors . push (
37+ `extraroutesPlugin property 'data' needs to have 'title' and 'data' strings on every tuple`
38+ ) ;
39+ }
40+ }
41+ }
42+ return errors ;
43+ } ;
44+
45+ exports . extraRoutesPlugin = extraRoutesPlugin ;
46+ /** the validator is mandatory */
0 commit comments