Compare commits

...

18 Commits

Author SHA1 Message Date
09c23d04f4 1.0.20 2021-01-12 14:18:17 +00:00
3f359cb58c fix(core): update 2021-01-12 14:18:16 +00:00
a85eb48343 1.0.19 2021-01-09 01:48:37 +00:00
7c851b5ed2 fix(core): update 2021-01-09 01:48:36 +00:00
bcd69059f8 1.0.18 2021-01-08 22:08:02 +00:00
acba539a6f fix(core): update 2021-01-08 22:08:01 +00:00
446b4c38ea 1.0.17 2021-01-08 22:06:26 +00:00
bc6d3f45f8 fix(core): update 2021-01-08 22:06:25 +00:00
bd381ff23f 1.0.16 2020-08-06 17:50:03 +00:00
7e5bdf8521 fix(core): update 2020-08-06 17:50:00 +00:00
f427141c7c 1.0.15 2020-08-06 15:30:54 +00:00
e8191187a1 fix(core): update 2020-08-06 15:30:54 +00:00
6e1dcccd81 1.0.14 2020-08-06 15:18:54 +00:00
f8eee10a40 1.0.13 2020-08-06 15:18:48 +00:00
a6492a5465 1.0.12 2020-08-06 15:18:40 +00:00
eb9c2bd284 1.0.11 2020-08-06 15:17:01 +00:00
9991e234ce fix(core): update 2020-08-06 15:17:01 +00:00
d6ba1bbed7 1.0.10 2020-08-06 15:14:56 +00:00
9 changed files with 1641 additions and 1174 deletions

4
.gitignore vendored
View File

@ -15,8 +15,6 @@ node_modules/
# builds # builds
dist/ dist/
dist_web/ dist_*/
dist_serve/
dist_ts_web/
# custom # custom

View File

@ -19,22 +19,35 @@ mirror:
stage: security stage: security
script: script:
- npmci git mirror - npmci git mirror
only:
- tags
tags: tags:
- lossless - lossless
- docker - docker
- notpriv - notpriv
snyk: auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security stage: security
script: script:
- npmci npm prepare - npmci npm prepare
- npmci command npm install --ignore-scripts - npmci command npm install --ignore-scripts
- npmci command snyk test - npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=dev
tags: tags:
- lossless
- docker - docker
- notpriv allow_failure: true
# ==================== # ====================
# test stage # test stage
@ -49,9 +62,7 @@ testStable:
- npmci npm test - npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- lossless
- docker - docker
- priv
testBuild: testBuild:
stage: test stage: test
@ -62,9 +73,7 @@ testBuild:
- npmci command npm run build - npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- lossless
- docker - docker
- notpriv
release: release:
stage: release stage: release
@ -84,6 +93,8 @@ release:
codequality: codequality:
stage: metadata stage: metadata
allow_failure: true allow_failure: true
only:
- tags
script: script:
- npmci command npm install -g tslint typescript - npmci command npm install -g tslint typescript
- npmci npm prepare - npmci npm prepare

View File

@ -15,7 +15,7 @@
"properties": { "properties": {
"projectType": { "projectType": {
"type": "string", "type": "string",
"enum": ["website", "element", "service", "npm"] "enum": ["website", "element", "service", "npm", "wcc"]
} }
} }
} }

2621
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,10 @@
{ {
"name": "@pushrocks/smartssr", "name": "@pushrocks/smartssr",
"version": "1.0.9", "version": "1.0.20",
"private": false, "private": false,
"description": "a smart server side renderer supporting shadow dom", "description": "a smart server side renderer supporting shadow dom",
"main": "dist/index.js", "main": "dist_ts/index.js",
"typings": "dist/index.d.ts", "typings": "dist_ts/index.d.ts",
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
@ -13,30 +13,34 @@
"format": "(gitzone format)" "format": "(gitzone format)"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.24", "@gitzone/tsbuild": "^2.1.25",
"@gitzone/tstest": "^1.0.43", "@gitzone/tstest": "^1.0.52",
"@pushrocks/smartserve": "^1.1.41", "@pushrocks/smartserve": "^1.1.41",
"@pushrocks/tapbundle": "^3.2.9", "@pushrocks/tapbundle": "^3.2.9",
"@types/node": "^14.0.27", "@types/node": "^14.14.20",
"tslint": "^6.1.3", "tslint": "^6.1.3",
"tslint-config-prettier": "^1.15.0" "tslint-config-prettier": "^1.15.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/smartdelay": "^2.0.10", "@pushrocks/smartdelay": "^2.0.10",
"@pushrocks/smartfile": "^7.0.12", "@pushrocks/smartfile": "^8.0.8",
"@pushrocks/smartpromise": "^3.0.6", "@pushrocks/smartpromise": "^3.1.3",
"@pushrocks/smartpuppeteer": "^1.0.15", "@pushrocks/smartpuppeteer": "^1.0.19",
"@pushrocks/smarttime": "^3.0.24" "@pushrocks/smarttime": "^3.0.38"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",
"ts_web/**/*", "ts_web/**/*",
"dist/**/*", "dist/**/*",
"dist_web/**/*", "dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*", "dist_ts_web/**/*",
"assets/**/*", "assets/**/*",
"cli.js", "cli.js",
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"
],
"browserslist": [
"last 1 chrome versions"
] ]
} }

View File

@ -8,13 +8,20 @@ a smart server side renderer supporting shadow dom
* [docs (typedoc)](https://pushrocks.gitlab.io/smartssr/) * [docs (typedoc)](https://pushrocks.gitlab.io/smartssr/)
## Status for master ## Status for master
[![pipeline status](https://gitlab.com/pushrocks/smartssr/badges/master/pipeline.svg)](https://gitlab.com/pushrocks/smartssr/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartssr/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartssr/commits/master) Status Category | Status Badge
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartssr.svg)](https://www.npmjs.com/package/@pushrocks/smartssr) -- | --
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartssr/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartssr) GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartssr/badges/master/pipeline.svg)](https://lossless.cloud)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartssr/badges/master/coverage.svg)](https://lossless.cloud)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartssr)](https://lossless.cloud)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/) Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartssr)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartssr)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartssr)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartssr)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage ## Usage

View File

@ -5,7 +5,7 @@ let testSSRInstance: smartssr.SmartSSR;
tap.test('should create a valid smartssr instance', async () => { tap.test('should create a valid smartssr instance', async () => {
testSSRInstance = new smartssr.SmartSSR({ testSSRInstance = new smartssr.SmartSSR({
debug: true debug: true,
}); });
}); });
@ -13,11 +13,13 @@ tap.test('should start the smartssr instance', async () => {
await testSSRInstance.start(); await testSSRInstance.start();
}); });
tap.test('should render central.eu', async tools => { tap.skip.test('should render central.eu', async (tools) => {
await testSSRInstance.renderPage('https://central.eu/article/5e76873b9cf69b7bf6bc78bc/Introducing%3A%20central.eu'); await testSSRInstance.renderPage(
'https://central.eu/article/5e76873b9cf69b7bf6bc78bc/Introducing%3A%20central.eu'
);
}); });
tap.skip.test('should render lossless.com', async () => { tap.test('should render lossless.com', async () => {
await testSSRInstance.renderPage('https://lossless.com'); await testSSRInstance.renderPage('https://lossless.com');
}); });

View File

@ -11,25 +11,26 @@ export interface ISmartSSROptions {
* *
*/ */
export class SmartSSR { export class SmartSSR {
public browser: plugins.smartpuppeteer.puppeteer.Browser; public browser: plugins.smartpuppeteer.IncognitoBrowser;
public options: ISmartSSROptions; public options: ISmartSSROptions;
constructor(optionsArg?: ISmartSSROptions) { constructor(optionsArg?: ISmartSSROptions) {
this.options = { this.options = {
... { ...{
debug: false debug: false,
}, },
...optionsArg ...optionsArg,
}; };
} }
public async start() { public async start() {
this.browser = await plugins.smartpuppeteer.getEnvAwareBrowserInstance(); this.browser = new plugins.smartpuppeteer.IncognitoBrowser();
await this.browser.start();
} }
public async stop() { public async stop() {
if (this.browser) { if (this.browser) {
await plugins.smartdelay.delayFor(3000); await plugins.smartdelay.delayFor(3000);
await this.browser.close(); await this.browser.stop();
this.browser = null; this.browser = null;
} else { } else {
console.log('browser was not in started mode'); console.log('browser was not in started mode');
@ -40,50 +41,56 @@ export class SmartSSR {
const overallTimeMeasurement = new plugins.smarttime.HrtMeasurement(); const overallTimeMeasurement = new plugins.smarttime.HrtMeasurement();
overallTimeMeasurement.start(); overallTimeMeasurement.start();
const resultDeferred = plugins.smartpromise.defer<string>(); const resultDeferred = plugins.smartpromise.defer<string>();
const context = await this.browser.createIncognitoBrowserContext(); const context = await this.browser.getNewIncognitoContext();
const page = await context.newPage(); const page = await context.newPage();
page.on('console', msg => { page.on('console', (msg) => {
console.log(`${urlArg}: ${msg.text()}`); console.log(`${urlArg}: ${msg.text()}`);
}); });
page.on('load', async (...args) => {
await plugins.smartdelay.delayFor(5000);
let screenshotBuffer: Buffer;
if (this.options.debug) {
screenshotBuffer = await page.screenshot({
encoding: 'binary'
});
}
await page.$eval('body', serializeFunction);
const pageContent = await page.content();
const renderedPageString = pageContent;
resultDeferred.resolve(renderedPageString);
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(); const renderTimeMeasurement = new plugins.smarttime.HrtMeasurement();
renderTimeMeasurement.start(); renderTimeMeasurement.start();
await page.goto(urlArg); await page.goto(urlArg, {
waitUntil: 'networkidle2',
timeout: 0
});
let screenshotBuffer: Buffer;
if (this.options.debug) {
screenshotBuffer = await page.screenshot({
encoding: 'binary',
});
}
await page.$eval('body', serializeFunction);
const pageContent = await page.content();
const renderedPageString = pageContent;
resultDeferred.resolve(renderedPageString);
const result = await resultDeferred.promise; const result = await resultDeferred.promise;
renderTimeMeasurement.stop(); renderTimeMeasurement.stop();
// lets clean up async // lets clean up async
context.close(); await context.close();
overallTimeMeasurement.stop(); overallTimeMeasurement.stop();
console.log(`Overall it took ${overallTimeMeasurement.milliSeconds} milliseconds to render ${urlArg}`); console.log(
console.log(`The rendering alone took ${renderTimeMeasurement.milliSeconds} milliseconds for ${urlArg}`) `Overall it took ${overallTimeMeasurement.milliSeconds} milliseconds to render ${urlArg}`
);
console.log(
`The rendering alone took ${renderTimeMeasurement.milliSeconds} milliseconds for ${urlArg}`
);
// 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 result; return result;
} }
} }

View File

@ -42,11 +42,19 @@ export function serializeFunction(rootNode) {
const slots = nodeArg.shadowRoot.querySelectorAll('slot'); const slots = nodeArg.shadowRoot.querySelectorAll('slot');
// handle slot element // handle slot element
const slotsForMove: HTMLSlotElement[] = [];
slots.forEach((slot) => { slots.forEach((slot) => {
nodeArg.childNodes.forEach((lightNode) => slot.parentNode.insertBefore(lightNode, slot)); slotsForMove.push(slot);
slot.parentNode.removeChild(slot);
}); });
for (const slot of slotsForMove) {
const slottedLightNodesForMove = [];
slot.assignedNodes().forEach((lightNode) => slottedLightNodesForMove.push(lightNode));
slottedLightNodesForMove.forEach((lightNode) =>
slot.parentNode.insertBefore(lightNode, slot)
);
}
// lets modify the css // lets modify the css
const childNodes = nodeArg.shadowRoot.childNodes; const childNodes = nodeArg.shadowRoot.childNodes;
// tslint:disable-next-line: prefer-for-of // tslint:disable-next-line: prefer-for-of
@ -56,15 +64,12 @@ export function serializeFunction(rootNode) {
if (childNode.tagName === 'STYLE') { if (childNode.tagName === 'STYLE') {
childNode.textContent = prependCss(nodeUUID, childNode.textContent); childNode.textContent = prependCss(nodeUUID, childNode.textContent);
} else { } else {
if (nodeArg.tagName?.includes('ARTICLEGRID')) {
console.log('hello ' + childNode.id);
}
serializeNode(childNode, logThis); serializeNode(childNode, logThis);
} }
noteForAppending.push(childNode); noteForAppending.push(childNode);
} }
}); });
noteForAppending.forEach(childNode => { noteForAppending.forEach((childNode) => {
nodeArg.append(childNode); nodeArg.append(childNode);
}); });
} else { } else {