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
14 changes: 14 additions & 0 deletions libs/scully/dist/.nx-results
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"command": "build",
"results": {
"ng-lib": false,
"scully": false,
"plugins-scully-plugin-flash-prevention": false,
"plugins-base-href-rewrite": false,
"scully-schematics": false,
"plugins-from-data": false,
"plugins-extra": false,
"sample-blog": false,
"scully-docs": false
}
}
25 changes: 21 additions & 4 deletions libs/scully/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,31 @@ import {
getPluginConfig,
setConfig,
setPluginConfig,
findPlugin
findPlugin,
} from './lib/pluginManagement/pluginConfig';
import {
configValidator,
registerPlugin
registerPlugin,
} from './lib/pluginManagement/pluginRepository';
import './lib/pluginManagement/systemPlugins';
import { ContentMetaData } from './lib/renderPlugins/content-render-utils/readFileAndCheckPrePublishSlug';
import { HandledRoute } from './lib/routerPlugins/addOptionalRoutesPlugin';
import { scullyConfig, updateScullyConfig } from './lib/utils/config';
import {
scullyConfig,
updateScullyConfig,
loadConfig,
} from './lib/utils/config';
import { httpGetJson } from './lib/utils/httpGetJson';
import { RouteTypes, ScullyConfig } from './lib/utils/interfacesandenums';
import { replaceFirstRouteParamWithVal } from './lib/utils/replaceFirstRouteParamWithVal';
import { routeSplit } from './lib/utils/routeSplit';
import { getHandledRoutes } from './lib/utils/services/routeStorage';
import { startScully } from './lib/utils/startup';
import { staticServer } from './lib/utils/serverstuff/staticServer';
import { handleTravesal } from './lib/utils/handlers/handleTravesal';
import { routeDiscovery } from './lib/utils/handlers/routeDiscovery';
import { executePluginsForRoute } from './lib/renderPlugins/executePlugins';
import { writeToFs } from './lib/systemPlugins/writeToFs.plugin';

export * from './lib/utils/log';
export {
Expand All @@ -38,6 +47,14 @@ export {
setPluginConfig,
getPluginConfig,
findPlugin,
/** WIP part, those might be remove again in near future. */
staticServer,
loadConfig,
handleTravesal,
routeDiscovery,
writeToFs,
executePluginsForRoute,
/** end WIP */
getConfig as getMyConfig,
setConfig as setMyConfig
setConfig as setMyConfig,
};
31 changes: 17 additions & 14 deletions libs/scully/src/lib/renderPlugins/puppeteerRenderPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const puppeteerRender = async (route: HandledRoute): Promise<string> => {
page = await browser.newPage();

let resolve;
const pageReady = new Promise(r => (resolve = r));
const pageReady = new Promise((r) => (resolve = r));

if (scullyConfig.bareProject) {
await page.setRequestInterception(true);
Expand Down Expand Up @@ -76,7 +76,7 @@ export const puppeteerRender = async (route: HandledRoute): Promise<string> => {
complete: () => {
console.log('page should be idle');
resolve();
}
},
});
}

Expand Down Expand Up @@ -135,16 +135,7 @@ export const puppeteerRender = async (route: HandledRoute): Promise<string> => {
await page.goto(path);
pageLoaded.next();

/**
* when the browser is shown, use a 2 minute timeout, otherwise
* wait for page-read || timeout @ 25 seconds.
*/
if (showBrowser) {
await waitForIt(120 * 1000);
} else {
await Promise.race([pageReady, waitForIt(timeOutValueInSeconds * 1000)]);
}
// await Promise.race([ waitForIt(120 * 1000)]);
await Promise.race([pageReady, waitForIt(timeOutValueInSeconds * 1000)]);

/** when done, add in some scully content. */
await page.evaluate(() => {
Expand Down Expand Up @@ -187,7 +178,19 @@ export const puppeteerRender = async (route: HandledRoute): Promise<string> => {
// pageHtml = await page.evaluate(`(async () => {
// return new XMLSerializer().serializeToString(document.doctype) + document.documentElement.outerHTML
// })()`);
await page.close();
/**
* when the browser is shown, use a 2 minute timeout, otherwise
* wait for page-read || timeout @ 25 seconds.
*/
if (showBrowser) {
page.evaluate(
"console.log('\\n\\n------------------------------\\nScully is done, page left open for 120 seconds for inspection\\n------------------------------\\n\\n')"
);
//* don't close the browser, but leave it open for inspection for 120 secs
waitForIt(120 * 1000).then(() => page.close());
} else {
await page.close();
}
} catch (err) {
// tslint:disable-next-line: no-unused-expression
page && typeof page.close === 'function' && (await page.close());
Expand All @@ -208,7 +211,7 @@ export const puppeteerRender = async (route: HandledRoute): Promise<string> => {
};

export function waitForIt(milliSeconds: number) {
return new Promise(resolve => setTimeout(() => resolve(), milliSeconds));
return new Promise((resolve) => setTimeout(() => resolve(), milliSeconds));
}

const windowSet = (page: Page, name: string, value: Serializable) =>
Expand Down
11 changes: 8 additions & 3 deletions libs/scully/src/lib/utils/handlers/handleTravesal.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import { performance } from 'perf_hooks';
import { traverseAppRoutes } from '../../routerPlugins/traverseAppRoutesPlugin';
import { rawRoutesCache } from '../cache';
import { rawRoutesCache, flushRawRoutesCache } from '../cache';
import { log, logWarn } from '../log';
import { performanceIds } from '../performanceIds';

export async function handleTravesal(): Promise<string[]> {
export async function handleTravesal(
{ forceScan } = { forceScan: false }
): Promise<string[]> {
let unhandledRoutes: string[];
if (forceScan) {
flushRawRoutesCache();
}
if (rawRoutesCache.size === 0) {
log('Finding all routes in application.');
performance.mark('startTraverse');
unhandledRoutes = await traverseAppRoutes();
performance.mark('stopTraverse');
performanceIds.add('Traverse');
unhandledRoutes.forEach(r => rawRoutesCache.add(r));
unhandledRoutes.forEach((r) => rawRoutesCache.add(r));
} else {
unhandledRoutes = [...rawRoutesCache.keys()];
}
Expand Down
15 changes: 10 additions & 5 deletions libs/scully/src/lib/utils/serverstuff/staticServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let angularServerInstance: { close: () => void };
let scullyServerInstance: { close: () => void };
let dataServerInstance: { close: () => void };

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export async function staticServer(port?: number) {
try {
port = port || scullyConfig.staticport;
Expand All @@ -37,7 +38,7 @@ export async function staticServer(port?: number) {
redirect: true,
setHeaders(res, path, stat) {
res.set('x-timestamp', Date.now());
}
},
};

scullyServer.use(compression());
Expand All @@ -61,7 +62,7 @@ export async function staticServer(port?: number) {
scullyServerInstance = addSSL(scullyServer, hostName, port).listen(
port,
hostName,
x => {
(x) => {
log(
`Scully static server started on "${yellow(
`http${ssl ? 's' : ''}://${hostName}:${port}/`
Expand All @@ -77,7 +78,7 @@ export async function staticServer(port?: number) {
res.json({
res: true,
homeFolder: scullyConfig.homeFolder,
projectName: scullyConfig.projectName
projectName: scullyConfig.projectName,
});
});
angularDistServer.get('/killMe', async (req, res) => {
Expand All @@ -90,7 +91,7 @@ export async function staticServer(port?: number) {
/** use express to serve all static assets in dist folder. */
angularDistServer.use(express.static(distFolder, options));
/** provide for every route */
routes.forEach(route => {
routes.forEach((route) => {
angularDistServer.get(route, (req, res) =>
res.sendFile(join(distFolder, '/index.html'))
);
Expand All @@ -109,13 +110,17 @@ export async function staticServer(port?: number) {
angularDistServer,
hostName,
scullyConfig.appPort
).listen(scullyConfig.appPort, hostName, x => {
).listen(scullyConfig.appPort, hostName, (x) => {
log(
`Angular distribution server started on "${yellow(
`http${ssl ? 's' : ''}://${hostName}:${scullyConfig.appPort}/`
)}" `
);
});
return {
angularDistServer,
scullyServer,
};
} catch (e) {
logError(`Could not start Scully serve`, e);
}
Expand Down
1 change: 1 addition & 0 deletions libs/scully/src/scully.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { logError, logWarn, yellow } from './lib/utils/log';
import { startScully } from './lib/utils/startup';
import { waitForServerToBeAvailable } from './lib/utils';
import { bootServe, isBuildThere, watchMode } from './lib/watchMode';
import * as yargs from 'yargs';

/** the default of 10 is too shallow for generating pages. */
require('events').defaultMaxListeners = 100;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,5 @@
"allowSyntheticDefaultImports": true
},
"files": ["src/index.ts", "src/scully.ts"],
"exclude": [
"src/bin/**/*",
"src/bin/**/*.d.ts",
"src/bin/index.js",
"../../dist/**/*"
]
"exclude": ["../../dist/**/*"]
}
Loading