Skip to content

Commit 0b3eea4

Browse files
authored
Added a way to detect Scully (#45)
* Added Scully mode detection. (in Scully/from generated)
1 parent 2db725f commit 0b3eea4

File tree

7 files changed

+22
-8
lines changed

7 files changed

+22
-8
lines changed

projects/sampleBlog/src/app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<header>
2-
<h1>Scully demo blog app!</h1>
2+
<h1>Scully demo blog app! <small>{{currentState}}</small></h1>
33
<a [routerLink]="['/home']">🏠</a>
44
</header>
55

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import {Component} from '@angular/core';
2-
import { IdleMonitorService } from '@scullyio/ng-lib';
2+
import {IdleMonitorService, isScullyGenerated, isScullyRunning} from '@scullyio/ng-lib';
33

44
@Component({
55
selector: 'app-root',
66
templateUrl: './app.component.html',
77
styleUrls: ['./app.component.css'],
88
})
99
export class AppComponent {
10-
title = 'sampleBlog';
10+
currentState = isScullyRunning()
11+
? 'rendering inside scully'
12+
: isScullyGenerated()
13+
? 'Loaded from static HTML'
14+
: 'SPA mode';
1115
constructor(private idle: IdleMonitorService) {}
1216
}

projects/scullyio/ng-lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@scullyio/ng-lib",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"repository": {
55
"type": "GIT",
66
"url": "https://github.com/scullyio/scully/tree/master/projects/scullyio/ng-lib"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// tslint:disable: no-string-literal
2+
export const isScullyRunning = () => window && window['ScullyIO'] === 'running';
3+
export const isScullyGenerated = () => window && window['ScullyIO'] === 'generated';

projects/scullyio/ng-lib/src/public-api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
export * from './lib/components.module';
66
export * from './lib/idleMonitor/idle-monitor.service';
77
export * from './lib/route-service/scully-routes.service';
8-
export * from './lib/scully-content/scully-content.component'
8+
export * from './lib/scully-content/scully-content.component';
9+
export * from './lib/utils/isScully'
910

scully/renderPlugins/puppeteerRenderPlugin.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// tslint:disable: no-string-literal
12
// const puppeteer = require('puppeteer');
23
import {Browser, Page} from 'puppeteer';
34
import {HandledRoute} from '../routerPlugins/addOptionalRoutesPlugin';
@@ -26,16 +27,21 @@ export const puppeteerRender = async (route: HandledRoute): Promise<string> => {
2627

2728
/** Inject this into the running page, runs in browser*/
2829
await page.evaluateOnNewDocument(() => {
30+
/** set "running" mode */
31+
window['ScullyIO'] = 'running';
2932
window.addEventListener('AngularReady', () => {
30-
// setTimeout(() => window['onCustomEvent'](),10000);
33+
/** add a small script tag to set "generated" mode */
34+
const d = document.createElement('script');
35+
d.innerHTML = `window['ScullyIO']='generated';`;
36+
document.head.appendChild(d);
3137
window['onCustomEvent']();
3238
});
3339
});
3440

3541
// enter url in page
3642
await page.goto(path);
3743

38-
await Promise.race([pageReady, waitForIt(25 * 1000)] );
44+
await Promise.race([pageReady, waitForIt(25 * 1000)]);
3945

4046
/**
4147
* The stange notation is needed bcs typescript messes

scully/utils/validateConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export async function validateConfig(config: ScullyConfig) {
5151
})
5252
);
5353
} else {
54-
logWarn('No routes defined in "scully.config"');
54+
logWarn('No routes defined in "scully.config.js "');
5555
}
5656
if (hasErrors) {
5757
/** stop everything if there are errors in the config. */

0 commit comments

Comments
 (0)