Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions scully/utils/defaultAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ export const generateAll = async (config?: Partial<ScullyConfig>) => {
try {
log('Finding all routes in application.');
const appRouteArray = await traverseAppRoutes();
addExtraRoutes(appRouteArray, config);

if (appRouteArray.length<1) {
logWarn('No routes found in application, are you sure you installed the router? Terminating.')
process.exit(15);
}

log('Pull in data to create additional routes.');
const dataRoutes = await addOptionalRoutes(appRouteArray);
await storeRoutes(dataRoutes);
Expand Down Expand Up @@ -62,3 +65,16 @@ async function doChunks(dataRoutes) {
return x.concat(activeChunk);
}, Promise.resolve([]));
}

function addExtraRoutes(appRoutes, config){
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of simply allowing people to provide a string[] as the type of config.extraRotues, we could allow the type of extra routes to be (string | string[] | Promise | Promise<string[]>)[], which we could just flatten it all and then turn them all into promises, and run a Promises.all([flattenedAndPromisifiedExtraRoutes]) and then return them.

That is likely the most extensible and support the most amount of people. But... for now, I support this list of strings gets us quite a ways.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to have the promise<string[]>, as that is indeed the most extensible.
For now, I can live with this. I probably need to do a bit of redesign anyway, so we can start generating "pages" before we are done collecting all routes anyway.

if(config.extraRoutes) {
let extraRoutes = config.extraRoutes;
if(!Array.isArray([])) {
logWarn(`ExtraRoutes must be provided as an array. Current type: ${typeof extraRoutes}`);
} else {
log(`Adding all extra routes (${config.extraRoutes.length})`);
extraRoutes = config.extraRoutes || [];
extraRoutes.forEach(extraRoute => appRoutes.push(extraRoute));
}
}
}
1 change: 1 addition & 0 deletions scully/utils/interfacesandenums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface ScullyConfig {
outFolder?: string;
distFolder?: string;
routes: RouteConfig;
extraRoutes?: string[];
appPort: number;
staticport: number;
}
Expand Down