Compare commits
48 Commits
Author | SHA1 | Date | |
---|---|---|---|
866cb79aa7 | |||
5a59abd1df | |||
b0c6fb662d | |||
2a8c0dec5f | |||
bb5f70a28e | |||
e87833c59f | |||
cc5f93305b | |||
67052baad0 | |||
08fc62d06f | |||
975e463fd6 | |||
3bc93871f9 | |||
49db495bb9 | |||
d0ee536301 | |||
344e213c41 | |||
0ae13c970e | |||
0502e7bc99 | |||
c0a425e16d | |||
90089357cf | |||
e36aed4b2b | |||
4d2aa7a0ee | |||
759fa1ff43 | |||
042caeeeb5 | |||
6ddfaffbff | |||
567507c88b | |||
35f7bdd984 | |||
602fa2b7ff | |||
b1aae3e5b9 | |||
6b381d6115 | |||
25006901d9 | |||
ee613836d1 | |||
4b53173618 | |||
46a0220273 | |||
46a6c903e1 | |||
134151eb70 | |||
ac1c3ac53d | |||
09c23d04f4 | |||
3f359cb58c | |||
a85eb48343 | |||
7c851b5ed2 | |||
bcd69059f8 | |||
acba539a6f | |||
446b4c38ea | |||
bc6d3f45f8 | |||
bd381ff23f | |||
7e5bdf8521 | |||
f427141c7c | |||
e8191187a1 | |||
6e1dcccd81 |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@ -0,0 +1,66 @@
|
||||
name: Default (not tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags-ignore:
|
||||
- '**'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install pnpm and npmci
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
|
||||
- name: Run npm prepare
|
||||
run: npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@ -0,0 +1,124 @@
|
||||
name: Default (tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
||||
|
||||
release:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Release
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm publish
|
||||
|
||||
metadata:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
continue-on-error: true
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Code quality
|
||||
run: |
|
||||
npmci command npm install -g typescript
|
||||
npmci npm install
|
||||
|
||||
- name: Trigger
|
||||
run: npmci trigger
|
||||
|
||||
- name: Build docs and upload artifacts
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
pnpm install -g @gitzone/tsdoc
|
||||
npmci command tsdoc
|
||||
continue-on-error: true
|
@ -12,30 +12,38 @@ stages:
|
||||
- release
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- pnpm install -g pnpm
|
||||
- pnpm install -g @shipzone/npmci
|
||||
- npmci npm prepare
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
audit:
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command pnpm audit --audit-level=high --prod
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command pnpm audit --audit-level=high --dev
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
@ -44,7 +52,6 @@ audit:
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
@ -55,10 +62,9 @@ testStable:
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
- npmci npm build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
@ -84,10 +90,9 @@ codequality:
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci command npm install -g typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
@ -107,11 +112,9 @@ trigger:
|
||||
pages:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
- npmci command npm run buildDocs
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "current file",
|
||||
"type": "node",
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"${relativeFile}"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": "test.ts",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"test/test.ts"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -3,10 +3,10 @@
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartssr",
|
||||
"shortDescription": "a smart server side renderer supporting shadow dom",
|
||||
"npmPackagename": "@pushrocks/smartssr",
|
||||
"description": "a smart server side renderer supporting shadow dom",
|
||||
"npmPackagename": "@push.rocks/smartssr",
|
||||
"license": "MIT",
|
||||
"projectDomain": "push.rocks"
|
||||
}
|
||||
|
11113
package-lock.json
generated
11113
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
35
package.json
35
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartssr",
|
||||
"version": "1.0.13",
|
||||
"name": "@push.rocks/smartssr",
|
||||
"version": "1.0.38",
|
||||
"private": false,
|
||||
"description": "a smart server side renderer supporting shadow dom",
|
||||
"main": "dist_ts/index.js",
|
||||
@ -9,24 +9,24 @@
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/ --web)",
|
||||
"build": "(tsbuild --web)",
|
||||
"format": "(gitzone format)"
|
||||
"build": "(tsbuild --web --allowimplicitany)",
|
||||
"serve": "tsrun scripts/serve.ts",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.24",
|
||||
"@gitzone/tstest": "^1.0.43",
|
||||
"@pushrocks/smartserve": "^1.1.41",
|
||||
"@pushrocks/tapbundle": "^3.2.9",
|
||||
"@types/node": "^14.0.27",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.15.0"
|
||||
"@gitzone/tsbuild": "^2.1.66",
|
||||
"@gitzone/tsrun": "^1.2.44",
|
||||
"@gitzone/tstest": "^1.0.77",
|
||||
"@push.rocks/tapbundle": "^5.0.8",
|
||||
"@types/node": "^20.4.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/smartdelay": "^2.0.10",
|
||||
"@pushrocks/smartfile": "^7.0.12",
|
||||
"@pushrocks/smartpromise": "^3.0.6",
|
||||
"@pushrocks/smartpuppeteer": "^1.0.15",
|
||||
"@pushrocks/smarttime": "^3.0.24"
|
||||
"@push.rocks/smartdelay": "^3.0.1",
|
||||
"@push.rocks/smartfile": "^10.0.26",
|
||||
"@push.rocks/smartpath": "^5.0.5",
|
||||
"@push.rocks/smartpromise": "^4.0.2",
|
||||
"@push.rocks/smartpuppeteer": "^2.0.2",
|
||||
"@push.rocks/smarttime": "^4.0.1"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
@ -42,5 +42,6 @@
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
],
|
||||
"type": "module"
|
||||
}
|
||||
|
4744
pnpm-lock.yaml
generated
Normal file
4744
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
30
readme.md
30
readme.md
@ -1,27 +1,26 @@
|
||||
# @pushrocks/smartssr
|
||||
# @push.rocks/smartssr
|
||||
a smart server side renderer supporting shadow dom
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartssr)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartssr)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartssr)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartssr/)
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartssr)
|
||||
* [gitlab.com (source)](https://gitlab.com/push.rocks/smartssr)
|
||||
* [github.com (source mirror)](https://github.com/push.rocks/smartssr)
|
||||
* [docs (typedoc)](https://push.rocks.gitlab.io/smartssr/)
|
||||
|
||||
## Status for master
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
|
||||
## Usage
|
||||
|
||||
@ -33,7 +32,6 @@ We are always happy for code contributions. If you are not the code contributing
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
## Legal
|
||||
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
||||
|
23
test/test.ts
23
test/test.ts
@ -1,5 +1,5 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as smartssr from '../ts/index';
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import * as smartssr from '../ts/index.js';
|
||||
|
||||
let testSSRInstance: smartssr.SmartSSR;
|
||||
|
||||
@ -9,26 +9,17 @@ tap.test('should create a valid smartssr instance', async () => {
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('should start the smartssr instance', async () => {
|
||||
await testSSRInstance.start();
|
||||
});
|
||||
|
||||
tap.test('should render central.eu', async (tools) => {
|
||||
await testSSRInstance.renderPage(
|
||||
'https://central.eu/article/5e76873b9cf69b7bf6bc78bc/Introducing%3A%20central.eu'
|
||||
);
|
||||
});
|
||||
|
||||
tap.skip.test('should render lossless.com', async () => {
|
||||
await testSSRInstance.renderPage('https://lossless.com');
|
||||
});
|
||||
|
||||
tap.skip.test('should render https://lossless.gmbh', async () => {
|
||||
const renderedPage = await testSSRInstance.renderPage('https://lossless.gmbh');
|
||||
tap.test('should render lossless.com', async () => {
|
||||
await testSSRInstance.renderPage('https://lossless.com');
|
||||
});
|
||||
|
||||
tap.test('should stop the smartssr instance', async () => {
|
||||
await testSSRInstance.stop();
|
||||
tap.test('should render https://lossless.gmbh', async () => {
|
||||
const renderedPage = await testSSRInstance.renderPage('https://lossless.gmbh');
|
||||
console.log(renderedPage);
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartssr',
|
||||
version: '1.0.38',
|
||||
description: 'a smart server side renderer supporting shadow dom'
|
||||
}
|
@ -1 +1 @@
|
||||
export * from './smartssr.classes.smartssr';
|
||||
export * from './smartssr.classes.smartssr.js';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import * as plugins from './smartssr.plugins';
|
||||
import * as paths from './smartssr.paths';
|
||||
import * as plugins from './smartssr.plugins.js';
|
||||
import * as paths from './smartssr.paths.js';
|
||||
|
||||
import { serializeFunction } from './smartssr.function.serialize';
|
||||
import { serializeFunction } from './smartssr.function.serialize.js';
|
||||
|
||||
export interface ISmartSSROptions {
|
||||
debug: boolean;
|
||||
@ -11,7 +11,6 @@ export interface ISmartSSROptions {
|
||||
*
|
||||
*/
|
||||
export class SmartSSR {
|
||||
public browser: plugins.smartpuppeteer.puppeteer.Browser;
|
||||
public options: ISmartSSROptions;
|
||||
|
||||
constructor(optionsArg?: ISmartSSROptions) {
|
||||
@ -23,62 +22,57 @@ export class SmartSSR {
|
||||
};
|
||||
}
|
||||
|
||||
public async start() {
|
||||
this.browser = await plugins.smartpuppeteer.getEnvAwareBrowserInstance();
|
||||
}
|
||||
public async stop() {
|
||||
if (this.browser) {
|
||||
await plugins.smartdelay.delayFor(3000);
|
||||
await this.browser.close();
|
||||
this.browser = null;
|
||||
} else {
|
||||
console.log('browser was not in started mode');
|
||||
}
|
||||
}
|
||||
|
||||
public async renderPage(urlArg: string) {
|
||||
const overallTimeMeasurement = new plugins.smarttime.HrtMeasurement();
|
||||
overallTimeMeasurement.start();
|
||||
const resultDeferred = plugins.smartpromise.defer<string>();
|
||||
const context = await this.browser.createIncognitoBrowserContext();
|
||||
const page = await context.newPage();
|
||||
page.on('console', (msg) => {
|
||||
console.log(`${urlArg}: ${msg.text()}`);
|
||||
});
|
||||
const browser = new plugins.smartpuppeteer.IncognitoBrowser();
|
||||
const renderTimeMeasurement = new plugins.smarttime.HrtMeasurement();
|
||||
let renderedPageString: string;
|
||||
let screenshotBuffer: Buffer;
|
||||
await browser.start();
|
||||
try {
|
||||
const context = await browser.getNewIncognitoContext();
|
||||
const page = await context.newPage();
|
||||
|
||||
page.on('load', async (...args) => {
|
||||
await plugins.smartdelay.delayFor(5000);
|
||||
let screenshotBuffer: Buffer;
|
||||
// lets protect against left open tabs
|
||||
plugins.smartdelay.delayFor(30000).then(async () => {
|
||||
try {
|
||||
await browser.stop();
|
||||
} catch {}
|
||||
});
|
||||
|
||||
page.on('console', (msg) => {
|
||||
console.log(`${urlArg}: ${msg.text()}`);
|
||||
});
|
||||
|
||||
renderTimeMeasurement.start();
|
||||
await page.goto(urlArg, {
|
||||
waitUntil: 'networkidle2',
|
||||
timeout: 30000,
|
||||
});
|
||||
|
||||
if (this.options.debug) {
|
||||
screenshotBuffer = await page.screenshot({
|
||||
screenshotBuffer = (await page.screenshot({
|
||||
encoding: 'binary',
|
||||
});
|
||||
})) as Buffer;
|
||||
}
|
||||
|
||||
await page.$eval('body', serializeFunction);
|
||||
const pageContent = await page.content();
|
||||
const renderedPageString = pageContent;
|
||||
renderedPageString = pageContent;
|
||||
resultDeferred.resolve(renderedPageString);
|
||||
renderTimeMeasurement.stop();
|
||||
|
||||
if (this.options.debug) {
|
||||
plugins.smartfile.memory.toFsSync(
|
||||
renderedPageString,
|
||||
plugins.path.join(paths.noGitDir, 'test.html')
|
||||
);
|
||||
const fs = await import('fs');
|
||||
fs.writeFileSync(plugins.path.join(paths.noGitDir, 'test.png'), screenshotBuffer);
|
||||
}
|
||||
});
|
||||
|
||||
const renderTimeMeasurement = new plugins.smarttime.HrtMeasurement();
|
||||
renderTimeMeasurement.start();
|
||||
await page.goto(urlArg);
|
||||
const result = await resultDeferred.promise;
|
||||
renderTimeMeasurement.stop();
|
||||
|
||||
// lets clean up async
|
||||
context.close();
|
||||
// lets clean up async
|
||||
await page.close();
|
||||
await context.close();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
await browser.stop();
|
||||
return;
|
||||
}
|
||||
await browser.stop();
|
||||
|
||||
overallTimeMeasurement.stop();
|
||||
console.log(
|
||||
@ -87,6 +81,17 @@ export class SmartSSR {
|
||||
console.log(
|
||||
`The rendering alone took ${renderTimeMeasurement.milliSeconds} milliseconds for ${urlArg}`
|
||||
);
|
||||
return result;
|
||||
|
||||
// debug
|
||||
if (this.options.debug) {
|
||||
plugins.smartfile.memory.toFsSync(
|
||||
renderedPageString,
|
||||
plugins.path.join(paths.noGitDir, 'test.html')
|
||||
);
|
||||
const fs = await import('fs');
|
||||
fs.writeFileSync(plugins.path.join(paths.noGitDir, 'test.png'), screenshotBuffer);
|
||||
}
|
||||
|
||||
return resultDeferred.promise;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
declare var document: Document;
|
||||
export function serializeFunction(rootNode) {
|
||||
export function serializeFunction(rootNode: Node) {
|
||||
const uuidv4 = () => {
|
||||
return 'unixxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
||||
const r = (Math.random() * 16) | 0;
|
||||
@ -26,7 +26,7 @@ export function serializeFunction(rootNode) {
|
||||
};
|
||||
const loopProtection: any[] = [];
|
||||
|
||||
function serializeNode(nodeArg: HTMLElement, logThis = false) {
|
||||
function serializeNode(nodeArg: HTMLElement | any, logThis = false) {
|
||||
if (loopProtection.includes(nodeArg)) {
|
||||
return;
|
||||
}
|
||||
@ -39,31 +39,54 @@ export function serializeFunction(rootNode) {
|
||||
const nodeUUID = uuidv4();
|
||||
|
||||
nodeArg.classList.add(nodeUUID);
|
||||
|
||||
// find all slots
|
||||
const slots = nodeArg.shadowRoot.querySelectorAll('slot');
|
||||
|
||||
// handle slot element
|
||||
slots.forEach((slot) => {
|
||||
nodeArg.childNodes.forEach((lightNode) => slot.parentNode.insertBefore(lightNode, slot));
|
||||
slot.parentNode.removeChild(slot);
|
||||
const slotsForMove: HTMLSlotElement[] = [];
|
||||
slots.forEach((slot: any) => {
|
||||
slotsForMove.push(slot);
|
||||
});
|
||||
|
||||
for (const slot of slotsForMove) {
|
||||
const slottedLightNodesForMove: any[] = [];
|
||||
slot.assignedNodes().forEach((lightNode) => slottedLightNodesForMove.push(lightNode));
|
||||
slottedLightNodesForMove.forEach((lightNode) =>
|
||||
slot.parentNode.insertBefore(lightNode, slot)
|
||||
);
|
||||
}
|
||||
|
||||
// lets modify the css
|
||||
const childNodes = nodeArg.shadowRoot.childNodes;
|
||||
// tslint:disable-next-line: prefer-for-of
|
||||
const noteForAppending: HTMLElement[] = [];
|
||||
childNodes.forEach((childNode) => {
|
||||
|
||||
// lets care about static css first
|
||||
if (
|
||||
(nodeArg.constructor as any).styles &&
|
||||
(nodeArg.constructor as any).styles instanceof Array
|
||||
) {
|
||||
for (const objectArg of (nodeArg.constructor as any).styles) {
|
||||
const styleTag = document.createElement('style');
|
||||
styleTag.textContent = prependCss(nodeUUID, objectArg.cssText);
|
||||
noteForAppending.push(styleTag);
|
||||
}
|
||||
}
|
||||
|
||||
childNodes.forEach((childNode: ChildNode) => {
|
||||
if (childNode instanceof HTMLElement) {
|
||||
if (childNode.tagName === 'STYLE') {
|
||||
childNode.textContent = prependCss(nodeUUID, childNode.textContent);
|
||||
} else {
|
||||
if (nodeArg.tagName?.includes('ARTICLEGRID')) {
|
||||
console.log('hello ' + childNode.id);
|
||||
}
|
||||
serializeNode(childNode, logThis);
|
||||
}
|
||||
noteForAppending.push(childNode);
|
||||
}
|
||||
});
|
||||
while (nodeArg.firstChild) {
|
||||
nodeArg.removeChild(nodeArg.firstChild);
|
||||
}
|
||||
noteForAppending.forEach((childNode) => {
|
||||
nodeArg.append(childNode);
|
||||
});
|
||||
|
@ -1,5 +1,8 @@
|
||||
import * as plugins from './smartssr.plugins';
|
||||
import * as plugins from './smartssr.plugins.js';
|
||||
|
||||
export const packageDir = plugins.path.join(__dirname, '../');
|
||||
export const packageDir = plugins.path.join(
|
||||
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
|
||||
'../'
|
||||
);
|
||||
export const noGitDir = plugins.path.join(packageDir, './.nogit');
|
||||
plugins.smartfile.fs.ensureDirSync(noGitDir);
|
||||
|
@ -4,10 +4,11 @@ import * as path from 'path';
|
||||
export { path };
|
||||
|
||||
// @pushrocks scope
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
import * as smartpuppeteer from '@pushrocks/smartpuppeteer';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smarttime from '@pushrocks/smarttime';
|
||||
import * as smartdelay from '@push.rocks/smartdelay';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
import * as smartpuppeteer from '@push.rocks/smartpuppeteer';
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import * as smarttime from '@push.rocks/smarttime';
|
||||
|
||||
export { smartdelay, smartfile, smartpuppeteer, smartpromise, smarttime };
|
||||
export { smartdelay, smartfile, smartpath, smartpuppeteer, smartpromise, smarttime };
|
||||
|
11
tsconfig.json
Normal file
11
tsconfig.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "nodenext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
}
|
||||
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
||||
{
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
Reference in New Issue
Block a user