diff --git a/libs/scully/dist/.nx-results b/libs/scully/dist/.nx-results new file mode 100644 index 000000000..0dd4f9fbc --- /dev/null +++ b/libs/scully/dist/.nx-results @@ -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 + } +} diff --git a/libs/scully/src/index.ts b/libs/scully/src/index.ts index ba5ebb8d5..91032fe74 100644 --- a/libs/scully/src/index.ts +++ b/libs/scully/src/index.ts @@ -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 { @@ -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, }; diff --git a/libs/scully/src/lib/renderPlugins/puppeteerRenderPlugin.ts b/libs/scully/src/lib/renderPlugins/puppeteerRenderPlugin.ts index cedd60373..93e585f9c 100644 --- a/libs/scully/src/lib/renderPlugins/puppeteerRenderPlugin.ts +++ b/libs/scully/src/lib/renderPlugins/puppeteerRenderPlugin.ts @@ -43,7 +43,7 @@ export const puppeteerRender = async (route: HandledRoute): Promise => { 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); @@ -76,7 +76,7 @@ export const puppeteerRender = async (route: HandledRoute): Promise => { complete: () => { console.log('page should be idle'); resolve(); - } + }, }); } @@ -135,16 +135,7 @@ export const puppeteerRender = async (route: HandledRoute): Promise => { 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(() => { @@ -187,7 +178,19 @@ export const puppeteerRender = async (route: HandledRoute): Promise => { // 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()); @@ -208,7 +211,7 @@ export const puppeteerRender = async (route: HandledRoute): Promise => { }; 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) => diff --git a/libs/scully/src/lib/utils/handlers/handleTravesal.ts b/libs/scully/src/lib/utils/handlers/handleTravesal.ts index ec56ebe52..8517c16a9 100644 --- a/libs/scully/src/lib/utils/handlers/handleTravesal.ts +++ b/libs/scully/src/lib/utils/handlers/handleTravesal.ts @@ -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 { +export async function handleTravesal( + { forceScan } = { forceScan: false } +): Promise { 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()]; } diff --git a/libs/scully/src/lib/utils/serverstuff/staticServer.ts b/libs/scully/src/lib/utils/serverstuff/staticServer.ts index 205e1ec17..663deed82 100644 --- a/libs/scully/src/lib/utils/serverstuff/staticServer.ts +++ b/libs/scully/src/lib/utils/serverstuff/staticServer.ts @@ -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; @@ -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()); @@ -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}/` @@ -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) => { @@ -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')) ); @@ -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); } diff --git a/libs/scully/src/scully.ts b/libs/scully/src/scully.ts index 851554faf..ae5f4613d 100644 --- a/libs/scully/src/scully.ts +++ b/libs/scully/src/scully.ts @@ -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; diff --git a/libs/scully/tsconfig.lib.json b/libs/scully/tsconfig.json similarity index 84% rename from libs/scully/tsconfig.lib.json rename to libs/scully/tsconfig.json index 3dbdefd84..0b4252ce1 100644 --- a/libs/scully/tsconfig.lib.json +++ b/libs/scully/tsconfig.json @@ -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/**/*"] } diff --git a/package-lock.json b/package-lock.json index 0828b6e31..027864e40 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5655,9 +5655,9 @@ "dev": true }, "@types/mime": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/@types/mime/-/mime-2.0.1.tgz", - "integrity": "sha512-FwI9gX75FgVBJ7ywgnq/P7tw+/o1GUbtP0KzbtusLigAOgIgNISRK0ZPl4qertvXSIE8YbsVJueQ90cDt9YYyw==" + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/@types/mime/-/mime-2.0.2.tgz", + "integrity": "sha512-4kPlzbljFcsttWEq6aBW0OZe6BDajAmyvr2xknBG92tejQnvdGtT9+kXSZ580DqpxY9qG2xeQVF9Dq0ymUTo5Q==" }, "@types/minimatch": { "version": "3.0.3", @@ -5722,9 +5722,9 @@ "dev": true }, "@types/qs": { - "version": "6.9.2", - "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.2.tgz", - "integrity": "sha512-a9bDi4Z3zCZf4Lv1X/vwnvbbDYSNz59h3i3KdyuYYN+YrLjSeJD0dnphdULDfySvUv6Exy/O0K6wX/kQpnPQ+A==" + "version": "6.9.3", + "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.3.tgz", + "integrity": "sha512-7s9EQWupR1fTc2pSMtXRQ9w9gLOcrJn+h7HOXw4evxyvVqMi4f+q7d2tnFe3ng3SNHjtK+0EzGMGFUQX4/AQRA==" }, "@types/range-parser": { "version": "1.2.3", @@ -5772,9 +5772,9 @@ "dev": true }, "@types/serve-static": { - "version": "1.13.3", - "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.3.tgz", - "integrity": "sha512-oprSwp094zOglVrXdlo/4bAHtKTAxX6VT8FOZlBKrmyLbNvE1zxZyJ6yikMVtHIvwP45+ZQGJn+FdXGKTozq0g==", + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.4.tgz", + "integrity": "sha512-jTDt0o/YbpNwZbQmE/+2e+lfjJEJJR0I3OFaKQKPWkASkCoW3i6fsUnqudSMcNAfbtmADGu8f4MV4q+GqULmug==", "requires": { "@types/express-serve-static-core": "*", "@types/mime": "*" @@ -8187,6 +8187,11 @@ "integrity": "sha512-BLM56aPo9vLLFVa8+/+pJLnrZ7QGGTVHWsCwieAWT9o9K8UeGaQbzZbGoabWLOo2ksBCztoXdqBZBplqLDDCSg==", "dev": true }, + "arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==" + }, "argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", @@ -9247,8 +9252,7 @@ "buffer-from": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", - "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", - "dev": true + "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==" }, "buffer-indexof": { "version": "1.1.1", @@ -11614,8 +11618,7 @@ "diff": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", - "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", - "dev": true + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==" }, "diff-sequences": { "version": "25.2.6", @@ -18979,8 +18982,7 @@ "make-error": { "version": "1.3.6", "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", - "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", - "dev": true + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==" }, "make-fetch-happen": { "version": "5.0.2", @@ -19977,6 +19979,12 @@ "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==" }, + "node-cleanup": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/node-cleanup/-/node-cleanup-2.1.2.tgz", + "integrity": "sha1-esGavSl+Caf3KnFUXZUbUX5N3iw=", + "dev": true + }, "node-fetch-npm": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/node-fetch-npm/-/node-fetch-npm-2.0.4.tgz", @@ -22455,6 +22463,12 @@ "event-stream": "=3.3.4" } }, + "pseudomap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", + "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=", + "dev": true + }, "psl": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", @@ -24152,7 +24166,6 @@ "version": "0.5.19", "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.19.tgz", "integrity": "sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==", - "dev": true, "requires": { "buffer-from": "^1.0.0", "source-map": "^0.6.0" @@ -24161,8 +24174,7 @@ "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" } } }, @@ -24562,6 +24574,12 @@ "integrity": "sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM=", "dev": true }, + "string-argv": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/string-argv/-/string-argv-0.1.2.tgz", + "integrity": "sha512-mBqPGEOMNJKXRo7z0keX0wlAhbBAjilUdPW13nN0PecVryZxdHIeM7TqbsSUA7VYuS00HGC6mojP7DlQzfa9ZA==", + "dev": true + }, "string-length": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/string-length/-/string-length-3.1.0.tgz", @@ -25349,6 +25367,75 @@ } } }, + "ts-node": { + "version": "8.10.2", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-8.10.2.tgz", + "integrity": "sha512-ISJJGgkIpDdBhWVu3jufsWpK3Rzo7bdiIXJjQc0ynKxVOVcg2oIrf2H2cejminGrptVc6q6/uynAHNCuWGbpVA==", + "requires": { + "arg": "^4.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "source-map-support": "^0.5.17", + "yn": "3.1.1" + } + }, + "tsc-watch": { + "version": "4.2.8", + "resolved": "https://registry.npmjs.org/tsc-watch/-/tsc-watch-4.2.8.tgz", + "integrity": "sha512-EtWdmVZYFxTxSHqtmpowtvC/son28Hgl3qxYnD6sy+uGQXsWYDQxwmL8EneWca2kzAIYNZq3CGrUdK1jjbL4Vw==", + "dev": true, + "requires": { + "cross-spawn": "^5.1.0", + "node-cleanup": "^2.1.2", + "ps-tree": "^1.2.0", + "string-argv": "^0.1.1", + "strip-ansi": "^4.0.0" + }, + "dependencies": { + "ansi-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", + "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", + "dev": true + }, + "cross-spawn": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", + "integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=", + "dev": true, + "requires": { + "lru-cache": "^4.0.1", + "shebang-command": "^1.2.0", + "which": "^1.2.9" + } + }, + "lru-cache": { + "version": "4.1.5", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", + "integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==", + "dev": true, + "requires": { + "pseudomap": "^1.0.2", + "yallist": "^2.1.2" + } + }, + "strip-ansi": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", + "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "dev": true, + "requires": { + "ansi-regex": "^3.0.0" + } + }, + "yallist": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", + "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=", + "dev": true + } + } + }, "tsconfig-paths": { "version": "3.9.0", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz", @@ -27383,6 +27470,11 @@ "fd-slicer": "~1.1.0" } }, + "yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==" + }, "zone.js": { "version": "0.10.3", "resolved": "https://registry.npmjs.org/zone.js/-/zone.js-0.10.3.tgz", diff --git a/workspace.json b/workspace.json index 6c222ac46..9e9291bd3 100644 --- a/workspace.json +++ b/workspace.json @@ -13,7 +13,7 @@ "linter": "eslint", "config": "libs/scully/.eslintrc", "tsConfig": [ - "libs/scully/tsconfig.lib.json", + "libs/scully/tsconfig.json", "libs/scully/tsconfig.spec.json" ], "exclude": ["**/node_modules/**", "!libs/scully/**"] @@ -31,7 +31,7 @@ "builder": "@nrwl/node:package", "options": { "outputPath": "dist/libs/scully", - "tsConfig": "libs/scully/tsconfig.lib.json", + "tsConfig": "libs/scully/tsconfig.json", "packageJson": "libs/scully/package.json", "main": "libs/scully/src/index.ts", "assets": ["libs/scully/*.md"]