Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scully): add support to set the number of cores during rendering, #420

Merged
merged 3 commits into from
Mar 24, 2020
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
24 changes: 24 additions & 0 deletions docs/scully-provided-plugins.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: Scully system plugins
order: 700
---

# This document descrobes the plugins that are build into scully.

## json (router)

## ignored (router)

## contentFolder (router+render)

## seoHrefOptimise (render)

Adds an trailing slash (`/`) to all routes that are in the routeService. Increases SEO scoring

## adoc (fileHandler)

## md (fileHandler)

## default

The default routing plugin. Does add the route verbatim.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {DOCUMENT} from '@angular/common';
import {Inject, Injectable} from '@angular/core';
import {NavigationEnd, NavigationStart, Router} from '@angular/router';
import {BehaviorSubject, NEVER, Observable, of, from} from 'rxjs';
import {BehaviorSubject, NEVER, Observable, of} from 'rxjs';
import {
catchError,
filter,
Expand Down Expand Up @@ -167,7 +167,7 @@ export class TransferStateService {
/**
* starts monitoring the router, and keep the url from the last completed navigation handy.
*/
setupStartNavMonitoring() {
private setupStartNavMonitoring() {
if (!isScullyGenerated()) {
return;
}
Expand All @@ -176,7 +176,14 @@ export class TransferStateService {
this.nextUrl.subscribe();
}

async fetchTransferState(): Promise<void> {
useScullyTransferState<T>(name: string, originalState: Observable<T>): Observable<T> {
if (isScullyGenerated()) {
return this.getState(name);
}
return originalState.pipe(tap(state => this.setState(name, state)));
}

private async fetchTransferState(): Promise<void> {
/** helper to read the part before the first slash (ignores leading slash) */
const base = (url: string) => url.split('/').filter(part => part.trim() !== '')[0];
/** put this in the next event cycle so the correct route can be read */
Expand Down
2 changes: 2 additions & 0 deletions scully/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {logError, logWarn, yellow} from './log';
import {validateConfig} from './validateConfig';
import {compileConfig} from './compileConfig';
import {readAngularJson} from './read-anguar-json';
import {cpus} from 'os';
export const angularRoot = findAngularJsonPath();
export const scullyConfig: ScullyConfig = {} as ScullyConfig;

Expand Down Expand Up @@ -46,6 +47,7 @@ const loadIt = async () => {
projectRoot: projectConfig.root,
distFolder,
inlineStateOnly: false,
maxRenderThreads: cpus().length,
appPort: /** 1864 */ 'herodevs'.split('').reduce((sum, token) => (sum += token.charCodeAt(0)), 1000),
staticport: /** 1668 */ 'scully'.split('').reduce((sum, token) => (sum += token.charCodeAt(0)), 1000),
reloadPort: /** 2667 */ 'scullyLiveReload'
Expand Down
4 changes: 2 additions & 2 deletions scully/utils/handlers/renderParallel.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {cpus} from 'os';
import {performance} from 'perf_hooks';
import {routeContentRenderer} from '../../renderPlugins/routeContentRenderer';
import {writeToFs} from '../../systemPlugins/writeToFs.plugin';
import {asyncPool} from '../asyncPool';
import {scullyConfig} from '../config';
import {performanceIds} from '../performanceIds';

export async function renderParallel(dataRoutes) {
const renderRoute = route =>
routeContentRenderer(route).then((html: string) => writeToFs(route.route, html));
performance.mark('startRender');
performanceIds.add('Render');
const renderPool = await asyncPool(cpus().length, dataRoutes, renderRoute);
const renderPool = await asyncPool(scullyConfig.maxRenderThreads, dataRoutes, renderRoute);
performance.mark('stopRender');
return renderPool;
}
2 changes: 2 additions & 0 deletions scully/utils/interfacesandenums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export interface ScullyConfig {
hostUrl?: string;
/** optional guessParserOptions, if this is provided we are going to pass those options to the guess parser. */
guessParserOptions?: GuessParserOptions;
/** the maximum of concurrent puppeteer tabs open. defaults to the available amounts of cores */
maxRenderThreads: number;
}

interface RouteConfig {
Expand Down