Skip to content

Commit 94e275c

Browse files
authored
Frosty/excluded files (#280)
* feat(excludedfiles): added guessParserOptions to scully.config Added ability to pass guessParserOptions to scully.config. Currently only supports excludedFiles so that you can remove files from guessParsers scan for routes. Also added some tests around extraRoutes, excludedFiles, and moved and improved the transferState tests. * fix(excludedfiles): fixed path for sampleBlog * Fix the docs for guessParserOptions
1 parent 308d423 commit 94e275c

19 files changed

+333
-112
lines changed

cypress/videos/sampleBlog.spec.js.mp4

172 KB
Binary file not shown.

docs/scully-configuration.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface ScullyConfig {
3939
puppeteerLaunchOptions?: LaunchOptions;
4040
hostName?: string;
4141
hostUrl?: string;
42+
guessParserOptions?: {excludedFiles: string[]};
4243
}
4344
```
4445

@@ -139,4 +140,9 @@ use a different name as `localhost` for the local server. Needed if doe to envir
139140

140141
Connect to a other server. If your app has special demands to host it, you might need to use your own server. When that is needed you can provide this setting to let scully know where to look for your running app. Make sure the server is up and running, and hosting the correct application.
141142

143+
### guessParserOptions
144+
145+
These are the `guessParserOptions` that get passed to the `guess-parser` library. Currently the only property supported
146+
`excludedFiles`, which allows you to exclude files from the `guess-parser` route discovery process.
147+
142148
[Full Documentation ➡️](scully.md)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"ng": "ng",
66
"test": "jest",
77
"test:watch": "jest --watch",
8-
"e2e": "cypress run --spec 'cypress/integration/**/*' --browser chrome interactive",
8+
"e2e": "cypress run --spec 'cypress/integration/**/*' --browser chrome",
99
"tsc": "tsc",
1010
"generate": "tsc -p ./scully/tsconfig.scully.json && node ./scully/bin",
1111
"scully:dev:watch": "tsc -w -p ./scully/tsconfig.scully.json",

projects/sampleBlog/src/app/app-routing.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const routes: Routes = [
66
path: 'about',
77
loadChildren: () => import('./about/about.module').then(m => m.AboutModule),
88
},
9+
{path: '', redirectTo: '/home', pathMatch: 'full'},
910
{
1011
path: 'home',
1112
loadChildren: () => import('./static/static.module').then(m => m.StaticModule),
@@ -19,12 +20,11 @@ const routes: Routes = [
1920
loadChildren: () => import('./user/user.module').then(m => m.UserModule),
2021
},
2122
{path: 'demo', loadChildren: () => import('./demo/demo.module').then(m => m.DemoModule)},
22-
{path: '', redirectTo: '/home', pathMatch: 'full'},
23+
{path: 'exclude', loadChildren: () => import('./exclude/exclude.module').then(m => m.ExcludeModule)},
2324
{
2425
path: '**',
2526
loadChildren: () => import('./pagenotfound/pagenotfound.module').then(m => m.PagenotfoundModule),
2627
},
27-
{path: '', redirectTo: 'home', pathMatch: 'full'},
2828
];
2929

3030
@NgModule({
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {NgModule} from '@angular/core';
2+
import {Routes, RouterModule} from '@angular/router';
3+
4+
import {ExcludeComponent} from './exclude.component';
5+
6+
const routes: Routes = [
7+
{path: 'present', component: ExcludeComponent},
8+
{path: 'notpresent', component: ExcludeComponent},
9+
];
10+
11+
@NgModule({
12+
imports: [RouterModule.forChild(routes)],
13+
exports: [RouterModule],
14+
})
15+
export class ExcludeRoutingModule {}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
2+
3+
import {ExcludeComponent} from './exclude.component';
4+
5+
describe('ExcludeComponent', () => {
6+
let component: ExcludeComponent;
7+
let fixture: ComponentFixture<ExcludeComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ExcludeComponent],
12+
}).compileComponents();
13+
}));
14+
15+
beforeEach(() => {
16+
fixture = TestBed.createComponent(ExcludeComponent);
17+
component = fixture.componentInstance;
18+
fixture.detectChanges();
19+
});
20+
21+
it('should create', () => {
22+
expect(component).toBeTruthy();
23+
});
24+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {Component, OnInit} from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-exclude',
5+
template: `
6+
<p>exclude works!</p>
7+
`,
8+
styles: [``],
9+
})
10+
export class ExcludeComponent implements OnInit {
11+
constructor() {}
12+
13+
ngOnInit() {}
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {NgModule} from '@angular/core';
2+
import {CommonModule} from '@angular/common';
3+
4+
import {ExcludeRoutingModule} from './exclude-routing.module';
5+
import {ExcludeComponent} from './exclude.component';
6+
7+
@NgModule({
8+
declarations: [ExcludeComponent],
9+
imports: [CommonModule, ExcludeRoutingModule],
10+
})
11+
export class ExcludeModule {}

scully.sampleBlog.config.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const {join} = require('path');
12
/** load the plugin */
23
require('./extraPlugin/extra-plugin.js');
34
require('./extraPlugin/tocPlugin');
@@ -7,8 +8,8 @@ exports.config = {
78
/** outDir is where the static distribution files end up */
89
outDir: './dist/static',
910
// hostName: '0.0.0.0',
10-
hostUrl: 'http://localHost:5000',
11-
extraRoutes: [''],
11+
// hostUrl: 'http://localHost:5000',
12+
extraRoutes: ['/exclude/present'],
1213
routes: {
1314
'/demo/:id': {
1415
type: 'extra',
@@ -71,4 +72,7 @@ exports.config = {
7172
type: 'ignored',
7273
},
7374
},
75+
guessParserOptions: {
76+
excludedFiles: ['projects/sampleBlog/src/app/exclude/exclude-routing.module.ts'],
77+
},
7478
};

scully/routerPlugins/traverseAppRoutesPlugin.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {parseAngularRoutes} from 'guess-parser';
22
import {join} from 'path';
33
import * as yargs from 'yargs';
4-
import {scullyConfig} from '../utils/config';
4+
import {scullyConfig, loadConfig} from '../utils/config';
55
import {existFolder} from '../utils/fsFolder';
66
import {green, logError, logWarn, yellow} from '../utils/log';
77

@@ -13,6 +13,10 @@ const {sge} = yargs
1313
export const traverseAppRoutes = async (appRootFolder = scullyConfig.projectRoot) => {
1414
const extraRoutes = await addExtraRoutes();
1515
let routes = [];
16+
const excludedFiles =
17+
scullyConfig.guessParserOptions && scullyConfig.guessParserOptions.excludedFiles
18+
? scullyConfig.guessParserOptions.excludedFiles
19+
: [];
1620
try {
1721
const file = join(appRootFolder, 'tsconfig.app.json');
1822
if (!existFolder(file)) {
@@ -21,9 +25,9 @@ export const traverseAppRoutes = async (appRootFolder = scullyConfig.projectRoot
2125
file
2226
)}". Using the apps source folder as source. This might lead to unpredictable results`
2327
);
24-
routes = parseAngularRoutes(appRootFolder).map(r => r.path);
28+
routes = parseAngularRoutes(appRootFolder, excludedFiles).map(r => r.path);
2529
} else {
26-
routes = parseAngularRoutes(file).map(r => r.path);
30+
routes = parseAngularRoutes(file, excludedFiles).map(r => r.path);
2731
}
2832
} catch (e) {
2933
if (sge) {

0 commit comments

Comments
 (0)