Skip to content

Commit

Permalink
feat: add new rendering system
Browse files Browse the repository at this point in the history
* feat(scully): scully now also parses environment var SCULLY for cli options.

* feat(monorepo): make renderer as an CMD-line param en env setting for test config files

* chore(scully-plugin-playwright): merged into branch, and added to loadrenderer. Fixed loading issue

* docs(scully): add beforeAll documentation

* feat(schematics): add installation for now optional PPT plugin

* fix(scully-plugin-playwright): remove non-exiting enable function

* chore(monorepo): add updated packagenumbers for released packages, and update publish tool to ask
  • Loading branch information
SanderElias authored Nov 22, 2021
1 parent 8f3970b commit 05c1cfa
Show file tree
Hide file tree
Showing 25 changed files with 267 additions and 125 deletions.
2 changes: 2 additions & 0 deletions docs/Reference/command-line-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ title: Command Line Options

# Command Line Options

From Version 2.0.3 on all CLI parameters can also be provided by an environment variable called `SCULLY` (all caps).

#### serve

```bash
Expand Down
31 changes: 31 additions & 0 deletions docs/Reference/plugins/types/beforeAll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: beforeAll Plugin Type
published: true
lang: en
position: 104
---

# `beforeAll` Plugin Type

## Overview

An `beforeAll` plugin is run right after the config is loaded, but before any further processing is started. It can be used to run tasks that might be needed by other plugins, or copy files in from other locations. Or any other task you need to do _before_ every Scully run.


The interface is:
```
() => Promise<void|undefined|boolean>
```


```ts
const { registerPlugin } = require('@scullyio/scully');

function customCopyPlugin() {
// Do something to your Scully site
/** copy some extra files into my dist folder */
}

const validator = async () => [];
registerPlugin('beforeAll', 'copy in my custom files', customCopyPlugin);
```
3 changes: 3 additions & 0 deletions docs/Reference/plugins/types/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ After the Angular application renders, the HTML content is passed to a `render`
#### [`allDone`](/docs/Reference/plugins/types/allDone)

`allDone` plugins are like `routeDiscoveryDone` plugins, except they are called _after_ Scully finishes executing all its processes.
#### [`beforeAll`](/docs/Reference/plugins/types/beforeAll.md)

`beforeAll` plugins are like `allDone` plugins, except they are called _before_ Scully starts to do any off its processes.
21 changes: 12 additions & 9 deletions docs/concepts/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ Scully is designed to take an app, analyze it, and then write out all the static

## The process

1. Traverse, read the source of the application to find all routes.
2. Merge in [extraRoutes](/docs/Reference/config#extraroutes-string--string--promisestring--string), where we specify routes we know, but can't automatically traverse
3. We now have a list of [unhandled routes]
4. Enrich/expand the found [unhandled routes] routes with router-plugins.
5. Process/change the resulting [handled routes] list with routeProcess plugins.
6. Write out the `scully.routes.json` files.
7. Trigger routeDiscoveryDone with results from 5
8. Trigger the render plugins for each route (render will be specified later)
9. Trigger allDone plugins
1. Compile the user plugins and utils using `./scully/tsconfig.json`
2. Compile and load the `scully.<projectName>.config.ts`
3. Run all of the [beforeAll](/docs/Reference/plugins/types/beforeAll.md)
4. Traverse, read the source of the application to find all routes.
5. Merge in [extraRoutes](/docs/Reference/config#extraroutes-string--string--promisestring--string), where we specify routes we know, but can't automatically traverse
6. We now have a list of [unhandled routes]
7. Enrich/expand the found [unhandled routes] routes with router-plugins.
8. Process/change the resulting [handled routes] list with routeProcess plugins.
9. Write out the `scully.routes.json` files.
10. Trigger routeDiscoveryDone with results from 5
11. Trigger the render plugins for each route (render will be specified later)
12. Trigger allDone plugins

Please note that not all of those tasks might need to run every time. Scully will automatically reuse traversed(item 1) routes. A user might be using filters that will limit the work done in item 6. Also, when they use filtering, item 5 will be skipped, because we don’t want to write partial data to the JSON file.

Expand Down
2 changes: 1 addition & 1 deletion libs/plugins/scully-plugin-playwright/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scullyio/scully-plugin-playwright",
"version": "0.0.1",
"version": "0.0.2",
"repository": {
"type": "GIT",
"url": "https://github.com/scullyio/scully/tree/main/libs/plugins/scully-plugin-playwright"
Expand Down
23 changes: 12 additions & 11 deletions libs/plugins/scully-plugin-playwright/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { green, log, logError, logOk, registerPlugin, routeRenderer } from '@scullyio/scully';
import { exec } from 'child_process';
import { LaunchOptions } from 'playwright';
import { playwrightRenderer } from './lib/plugins-scully-plugin-playwright';
import { playwrightRender, playwrightRenderer } from './lib/plugins-scully-plugin-playwright';
import { launchedBrowser, launchedBrowser$ } from './lib/plugins-scully-plugin-playwright-utils';

async function runScript(cmd: string) {
Expand All @@ -23,17 +23,18 @@ const plugin = async () => {
});
log(` ${green('✔')} Playwright installation successfully`);
}
export function enablePW() {
registerPlugin('beforeAll', 'installPWDeps', plugin);

registerPlugin('scullySystem', routeRenderer, playwrightRenderer, undefined, { replaceExistingPlugin: true });
registerPlugin('beforeAll', 'installPWDeps', plugin);
/** enable as default routeRenderer */
registerPlugin('scullySystem', routeRenderer, playwrightRenderer, undefined, { replaceExistingPlugin: true });
/** also add as its own thing, perhaps we want to combine later, or use it differently */
registerPlugin('enterprise', playwrightRender, playwrightRenderer);
registerPlugin('enterprise', 'getPWLaunchedBrowser', async () => launchedBrowser$)
registerPlugin('beforeAll', 'startLaunching the browser', async () => {
logOk('Playwright is being launched')
launchedBrowser();
})

registerPlugin('enterprise', 'getPWLaunchedBrowser', async () => launchedBrowser$)
registerPlugin('beforeAll', 'startLaunching the browser', async () => {
logOk('Playwright is being launched')
launchedBrowser();
})
}

export { playwrightRender } from './lib/plugins-scully-plugin-playwright';
export type BrowserLaunchOptions = LaunchOptions & { browser: string };
export type BrowserLaunchOptions = LaunchOptions & { browser: string };
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import { launchedBrowser, reLaunch, waitForIt } from './plugins-scully-plugin-pl
let version = '0.0.0';
try {
const pkg = join(__dirname, '../../../package.json');
// console.log(pkg)
version = jsonc.parse(readFileSync(pkg).toString()).version || '0.0.0';
} catch (e) {
// this is only for internals builds
// version = jsonc.parse(readFileSync(join(__dirname, '../../../package.json')).toString()).version || '0.0.0';
}
export const title404 = '404 - URL not provided in the app Scully is serving';
const errorredPages = new Map<string, number>();
Expand Down Expand Up @@ -187,4 +185,4 @@ const windowSet = (page: Page, name: string, value: any) =>
})
`);

registerPlugin('scullySystem', playwrightRender, playwrightRenderer);
registerPlugin('scullySystem', playwrightRender, playwrightRenderer);
4 changes: 2 additions & 2 deletions libs/plugins/scully-plugin-puppeteer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scullyio/scully-plugin-puppeteer",
"version": "2.0.0",
"version": "2.0.1",
"description": "Scully Puppeteer render plugin",
"main": "./src/index.js",
"license": "MIT",
Expand All @@ -24,4 +24,4 @@
"plugin",
"render"
]
}
}
3 changes: 3 additions & 0 deletions libs/plugins/scully-plugin-puppeteer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import { launchedBrowser } from './lib/launchedBrowser';
import { puppeteerRender } from './lib/plugins-scully-plugin-puppeteer';
import { launchedBrowser$ } from './lib/launchedBrowser';

/** little hack to be able to share the browser instance */
registerPlugin('enterprise','getPPTLaunchedBrowser',async () => launchedBrowser$)
/** instead of always starting, now use the beforeAll plugin */
registerPlugin('beforeAll', 'startLaunching the browser', async () => {
logOk('Puppeteer is being launched')
launchedBrowser();
})
/** use ppt as 'default' renderer plugin */
registerPlugin('scullySystem', routeRenderer, puppeteerRender);
4 changes: 2 additions & 2 deletions libs/scully-schematics/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scullyio/init",
"version": "2.0.3",
"version": "2.0.4",
"description": "Add scully to your angular app",
"repository": {
"type": "GIT",
Expand Down Expand Up @@ -48,4 +48,4 @@
"peerDependencies": {
"guess-parser": "^0.4.22"
}
}
}
16 changes: 6 additions & 10 deletions libs/scully-schematics/src/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,12 @@ const addDependencies = (local: boolean = false) => (tree: Tree, context: Schema
_scullyCLI = 'file:local_modules/@scullyio/scully';
}
addPackageToPackageJson(tree, '@scullyio/scully', `${_scullyCLI}`);
const ngCoreVersionTag = getPackageVersionFromPackageJson(tree, '@angular/core');
if (+ngCoreVersionTag.search(/(\^8|~8)/g) === 0) {
context.logger.info('Install ng-lib for Angular v8');
_scullyComponentVersion = 'file:scullyio/ng-lib-v8.tgz';
addPackageToPackageJson(tree, '@scullyio/ng-lib-v8', `${_scullyComponentVersion}`);
} else {
context.logger.info('Installing ng-lib');
addPackageToPackageJson(tree, '@scullyio/ng-lib', `${_scullyComponentVersion}`);
}
// context.logger.info('✅️ Added dependency');
context.logger.info('Installing ng-lib');
addPackageToPackageJson(tree, '@scullyio/ng-lib', `${_scullyComponentVersion}`);
// TODO: add handling for different renderers!
context.logger.info('Installing Puppeteer plugin');
addPackageToPackageJson(tree, '@scullyio/scully-plugin-puppeteer', `${_scullyComponentVersion}`);

};
const importScullyModule = (project: string) => (tree: Tree, context: SchematicContext) => {
if (!project) {
Expand Down
7 changes: 3 additions & 4 deletions libs/scully/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scullyio/scully",
"version": "2.0.2",
"version": "2.0.3",
"description": "Scully CLI",
"repository": {
"type": "GIT",
Expand Down Expand Up @@ -32,11 +32,10 @@
"marked": "^2.0.0",
"open": "^7.3.0",
"os": "^0.1.1",
"puppeteer": "^10.2.0",
"selfsigned": "^1.10.8",
"ws": "^7.4.0",
"yamljs": "^0.3.0",
"yargs": "^16.1.1"
"yargs": "^17.2.1"
},
"optionalDependencies": {
"asciidoctor.js": "^1.5.9"
Expand All @@ -54,7 +53,7 @@
"@types/node": "^13.13.5",
"@types/ws": "^7.2.1",
"@types/yamljs": "^0.2.30",
"@types/yargs": "^15.0.4",
"@types/yargs": "^17.0.7",
"codelyzer": "^5.1.2",
"prettier": "^1.19.1"
},
Expand Down
1 change: 1 addition & 0 deletions libs/scully/src/lib/utils/cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
yargs
.env('SCULLY')
/** Kill other server without asking */
.boolean('ks')
.default('ks', false)
Expand Down
13 changes: 13 additions & 0 deletions libs/scully/src/lib/utils/compileConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import {
findConfigFile,
flattenDiagnosticMessageText,
parseConfigFileTextToJson,
ScriptTarget,
ModuleKind,
sys,
transpileModule,
TranspileOutput,
ModuleResolutionKind,
} from 'typescript';
import { configFileName, pluginFolder, project } from './cli-options';
import { registerExitHandler } from './exitHandler';
Expand Down Expand Up @@ -139,6 +142,16 @@ async function compileTSConfig(path) {
const js: TranspileOutput = transpileModule(source, {
fileName: path,
reportDiagnostics: true,
moduleName: 'scully',
compilerOptions: {
lib: ["ES2020", "dom"],
module: ModuleKind.CommonJS,
target: ScriptTarget.ES2020,
allowJs: true,
allowSyntheticDefaultImports: true,
skipLibCheck: true,
moduleResolution: ModuleResolutionKind.NodeJs
}
});
if (js.diagnostics.length > 0) {
logError(
Expand Down
2 changes: 1 addition & 1 deletion libs/scully/src/scully.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ yargs(process.argv.slice(2))
.command(['$0'], 'start processing the app', scullyInit)
.demandCommand()
.help()
.wrap(72)
.wrap(92)
.argv


Loading

0 comments on commit 05c1cfa

Please sign in to comment.