Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Binary file modified cypress/videos/sampleBlog.spec.js.mp4
Binary file not shown.
6 changes: 6 additions & 0 deletions docs/scully-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface ScullyConfig {
puppeteerLaunchOptions?: LaunchOptions;
hostName?: string;
hostUrl?: string;
guessParserOptions?: {excludedFiles: string[]};
}
```

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

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.

### guessParserOptions

These are the `guessParserOptions` that get passed to the `guess-parser` library. Currently the only property supported
`excludedFiles`, which allows you to exclude files from the `guess-parser` route discovery process.

[Full Documentation ➡️](scully.md)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"ng": "ng",
"test": "jest",
"test:watch": "jest --watch",
"e2e": "cypress run --spec 'cypress/integration/**/*' --browser chrome interactive",
"e2e": "cypress run --spec 'cypress/integration/**/*' --browser chrome",
"tsc": "tsc",
"generate": "tsc -p ./scully/tsconfig.scully.json && node ./scully/bin",
"scully:dev:watch": "tsc -w -p ./scully/tsconfig.scully.json",
Expand Down
4 changes: 2 additions & 2 deletions projects/sampleBlog/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const routes: Routes = [
path: 'about',
loadChildren: () => import('./about/about.module').then(m => m.AboutModule),
},
{path: '', redirectTo: '/home', pathMatch: 'full'},
{
path: 'home',
loadChildren: () => import('./static/static.module').then(m => m.StaticModule),
Expand All @@ -19,12 +20,11 @@ const routes: Routes = [
loadChildren: () => import('./user/user.module').then(m => m.UserModule),
},
{path: 'demo', loadChildren: () => import('./demo/demo.module').then(m => m.DemoModule)},
{path: '', redirectTo: '/home', pathMatch: 'full'},
{path: 'exclude', loadChildren: () => import('./exclude/exclude.module').then(m => m.ExcludeModule)},
{
path: '**',
loadChildren: () => import('./pagenotfound/pagenotfound.module').then(m => m.PagenotfoundModule),
},
{path: '', redirectTo: 'home', pathMatch: 'full'},
];

@NgModule({
Expand Down
15 changes: 15 additions & 0 deletions projects/sampleBlog/src/app/exclude/exclude-routing.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {NgModule} from '@angular/core';
import {Routes, RouterModule} from '@angular/router';

import {ExcludeComponent} from './exclude.component';

const routes: Routes = [
{path: 'present', component: ExcludeComponent},
{path: 'notpresent', component: ExcludeComponent},
];

@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class ExcludeRoutingModule {}
24 changes: 24 additions & 0 deletions projects/sampleBlog/src/app/exclude/exclude.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {async, ComponentFixture, TestBed} from '@angular/core/testing';

import {ExcludeComponent} from './exclude.component';

describe('ExcludeComponent', () => {
let component: ExcludeComponent;
let fixture: ComponentFixture<ExcludeComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ExcludeComponent],
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(ExcludeComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
14 changes: 14 additions & 0 deletions projects/sampleBlog/src/app/exclude/exclude.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {Component, OnInit} from '@angular/core';

@Component({
selector: 'app-exclude',
template: `
<p>exclude works!</p>
`,
styles: [``],
})
export class ExcludeComponent implements OnInit {
constructor() {}

ngOnInit() {}
}
11 changes: 11 additions & 0 deletions projects/sampleBlog/src/app/exclude/exclude.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';

import {ExcludeRoutingModule} from './exclude-routing.module';
import {ExcludeComponent} from './exclude.component';

@NgModule({
declarations: [ExcludeComponent],
imports: [CommonModule, ExcludeRoutingModule],
})
export class ExcludeModule {}
8 changes: 6 additions & 2 deletions scully.sampleBlog.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const {join} = require('path');
/** load the plugin */
require('./extraPlugin/extra-plugin.js');
require('./extraPlugin/tocPlugin');
Expand All @@ -7,8 +8,8 @@ exports.config = {
/** outDir is where the static distribution files end up */
outDir: './dist/static',
// hostName: '0.0.0.0',
hostUrl: 'http://localHost:5000',
extraRoutes: [''],
// hostUrl: 'http://localHost:5000',
extraRoutes: ['/exclude/present'],
routes: {
'/demo/:id': {
type: 'extra',
Expand Down Expand Up @@ -71,4 +72,7 @@ exports.config = {
type: 'ignored',
},
},
guessParserOptions: {
excludedFiles: ['projects/sampleBlog/src/app/exclude/exclude-routing.module.ts'],
},
};
10 changes: 7 additions & 3 deletions scully/routerPlugins/traverseAppRoutesPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {parseAngularRoutes} from 'guess-parser';
import {join} from 'path';
import * as yargs from 'yargs';
import {scullyConfig} from '../utils/config';
import {scullyConfig, loadConfig} from '../utils/config';
import {existFolder} from '../utils/fsFolder';
import {green, logError, logWarn, yellow} from '../utils/log';

Expand All @@ -13,6 +13,10 @@ const {sge} = yargs
export const traverseAppRoutes = async (appRootFolder = scullyConfig.projectRoot) => {
const extraRoutes = await addExtraRoutes();
let routes = [];
const excludedFiles =
scullyConfig.guessParserOptions && scullyConfig.guessParserOptions.excludedFiles
? scullyConfig.guessParserOptions.excludedFiles
: [];
try {
const file = join(appRootFolder, 'tsconfig.app.json');
if (!existFolder(file)) {
Expand All @@ -21,9 +25,9 @@ export const traverseAppRoutes = async (appRootFolder = scullyConfig.projectRoot
file
)}". Using the apps source folder as source. This might lead to unpredictable results`
);
routes = parseAngularRoutes(appRootFolder).map(r => r.path);
routes = parseAngularRoutes(appRootFolder, excludedFiles).map(r => r.path);
} else {
routes = parseAngularRoutes(file).map(r => r.path);
routes = parseAngularRoutes(file, excludedFiles).map(r => r.path);
}
} catch (e) {
if (sge) {
Expand Down
7 changes: 7 additions & 0 deletions scully/utils/interfacesandenums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export interface ScullyConfig {
hostName?: string;
/** optional hostURL, if this is provided, we are going to use this server instead of the build-in one. */
hostUrl?: string;
/** optional guessParserOptions, if this is provided we are going to pass those options to the guess parser. */
guessParserOptions?: GuessParserOptions;
}

interface RouteConfig {
Expand Down Expand Up @@ -80,3 +82,8 @@ export type RouteTypeUnknown = {
} & {
[paramName: string]: any;
};

interface GuessParserOptions {
// Files to pass to the guess parser that will be excluded from the route-discovery process.
excludedFiles: string[];
}
2 changes: 1 addition & 1 deletion src/__tests__/__snapshots__/home.spec.ts.snap

Large diffs are not rendered by default.

150 changes: 150 additions & 0 deletions src/__tests__/__snapshots__/transfer-state.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`TransferState should add state to page 1 1`] = `
Object {
"address": Object {
"city": "Gwenborough",
"geo": Object {
"lat": "-37.3159",
"lng": "81.1496",
},
"street": "Kulas Light",
"suite": "Apt. 556",
"zipcode": "92998-3874",
},
"company": Object {
"bs": "harness real-time e-markets",
"catchPhrase": "Multi-layered client-server neural-net",
"name": "Romaguera-Crona",
},
"email": "Sincere@april.biz",
"id": 1,
"name": "Leanne Graham",
"phone": "1-770-736-8031 x56442",
"username": "Bret",
"website": "hildegard.org",
}
`;

exports[`TransferState should add state to page 1 2`] = `
Array [
Object {
"body": "quia et suscipit
suscipit recusandae consequuntur expedita et cum
reprehenderit molestiae ut ut quas totam
nostrum rerum est autem sunt rem eveniet architecto",
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"userId": 1,
},
Object {
"body": "est rerum tempore vitae
sequi sint nihil reprehenderit dolor beatae ea dolores neque
fugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis
qui aperiam non debitis possimus qui neque nisi nulla",
"id": 2,
"title": "qui est esse",
"userId": 1,
},
Object {
"body": "et iusto sed quo iure
voluptatem occaecati omnis eligendi aut ad
voluptatem doloribus vel accusantium quis pariatur
molestiae porro eius odio et labore et velit aut",
"id": 3,
"title": "ea molestias quasi exercitationem repellat qui ipsa sit aut",
"userId": 1,
},
Object {
"body": "ullam et saepe reiciendis voluptatem adipisci
sit amet autem assumenda provident rerum culpa
quis hic commodi nesciunt rem tenetur doloremque ipsam iure
quis sunt voluptatem rerum illo velit",
"id": 4,
"title": "eum et est occaecati",
"userId": 1,
},
Object {
"body": "repudiandae veniam quaerat sunt sed
alias aut fugiat sit autem sed est
voluptatem omnis possimus esse voluptatibus quis
est aut tenetur dolor neque",
"id": 5,
"title": "nesciunt quas odio",
"userId": 1,
},
Object {
"body": "ut aspernatur corporis harum nihil quis provident sequi
mollitia nobis aliquid molestiae
perspiciatis et ea nemo ab reprehenderit accusantium quas
voluptate dolores velit et doloremque molestiae",
"id": 6,
"title": "dolorem eum magni eos aperiam quia",
"userId": 1,
},
Object {
"body": "dolore placeat quibusdam ea quo vitae
magni quis enim qui quis quo nemo aut saepe
quidem repellat excepturi ut quia
sunt ut sequi eos ea sed quas",
"id": 7,
"title": "magnam facilis autem",
"userId": 1,
},
Object {
"body": "dignissimos aperiam dolorem qui eum
facilis quibusdam animi sint suscipit qui sint possimus cum
quaerat magni maiores excepturi
ipsam ut commodi dolor voluptatum modi aut vitae",
"id": 8,
"title": "dolorem dolore est ipsam",
"userId": 1,
},
Object {
"body": "consectetur animi nesciunt iure dolore
enim quia ad
veniam autem ut quam aut nobis
et est aut quod aut provident voluptas autem voluptas",
"id": 9,
"title": "nesciunt iure omnis dolorem tempora et accusantium",
"userId": 1,
},
Object {
"body": "quo et expedita modi cum officia vel magni
doloribus qui repudiandae
vero nisi sit
quos veniam quod sed accusamus veritatis error",
"id": 10,
"title": "optio molestias id quia eum",
"userId": 1,
},
]
`;

exports[`TransferState should add state to page 2 1`] = `undefined`;

exports[`TransferState should add state to page 2 2`] = `
Object {
"address": Object {
"city": "Gwenborough",
"geo": Object {
"lat": "-37.3159",
"lng": "81.1496",
},
"street": "Kulas Light",
"suite": "Apt. 556",
"zipcode": "92998-3874",
},
"company": Object {
"bs": "harness real-time e-markets",
"catchPhrase": "Multi-layered client-server neural-net",
"name": "Romaguera-Crona",
},
"email": "Sincere@april.biz",
"id": 1,
"name": "Leanne Graham",
"phone": "1-770-736-8031 x56442",
"username": "Bret",
"website": "hildegard.org",
}
`;
Loading