Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"puppeteer": "^2.0.0",
"ts-node": "^8.3.0",
"tsickle": "^0.37.1",
"tslint": "~5.18.0",
"tslint": "~5.20.1",
"typescript": "^3.6.4",
"yargs": "^14.2.0"
},
Expand Down
20 changes: 10 additions & 10 deletions projects/sampleBlog/e2e/protractor.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts

const { SpecReporter } = require('jasmine-spec-reporter');
const { SpecReporter } = require("jasmine-spec-reporter");

/**
* @type { import("protractor").Config }
*/
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./src/**/*.e2e-spec.ts'
"./src/**/*.e2e-spec.ts",
],
capabilities: {
browserName: 'chrome'
browserName: "chrome",
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
baseUrl: "http://localhost:4200/",
framework: "jasmine",
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
print: function() {},
},
onPrepare() {
require('ts-node').register({
project: require('path').join(__dirname, './tsconfig.json')
require("ts-node").register({
project: require("path").join(__dirname, "./tsconfig.json"),
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
}
};
},
};
2 changes: 1 addition & 1 deletion projects/scullyio/ng-lib/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export * from './lib/components.module';
export * from './lib/idleMonitor/idle-monitor.service';
export * from './lib/route-service/scully-routes.service';
export * from './lib/scully-content/scully-content.component';
export * from './lib/utils/isScully'
export * from './lib/utils/isScully';

21 changes: 8 additions & 13 deletions scully/renderPlugins/contentRenderPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import {readFileSync} from 'fs';
import {FilePlugin, plugins, registerPlugin} from '../pluginManagement/pluginRepository';
import {logError, yellow, logWarn} from '../utils/log';
import {HandledRoute} from '../routerPlugins/addOptionalRoutesPlugin';
// import * as fm from 'front-matter';
// import fm, {test} from 'front-matter'
// import * as fm from 'front-matter';
const fm = require('front-matter');

registerPlugin('render', 'contentFolder', contentRenderPlugin);
Expand All @@ -25,13 +22,7 @@ async function contentRenderPlugin(html: string, route: HandledRoute) {
}
}

function insertContent(
startTag: string,
endTag: string,
html: string,
insertText: string,
...extras
) {
function insertContent(startTag: string, endTag: string, html: string, insertText: string, ...extras) {
try {
const [openingText, rest] = html.split(startTag);
const [takeout, endText] = rest.split(endTag);
Expand Down Expand Up @@ -61,7 +52,11 @@ async function handleFile(extension: string, fileContent: string) {
return plugin.handler(fileContent) as Promise<string>;
}

function getScript() {
return `<script>try {window['scullyContent'] = document.body.innerHTML.split('<!--scullyContent-begin-->')[1].split('<!--scullyContent-end-->')[0];} catch(e) {console.error('scully could not pare content',e);}</script>
`;
/**
* @returns a string representing the script that parses the page and loads the scullyContent variable.
* The string is kept on one line as the focus is to keep it as small as possible.
*/
function getScript(): string {
// tslint:disable-next-line:no-unused-expression
Comment thread
Splaktar marked this conversation as resolved.
return `<script>try {window['scullyContent'] = document.body.innerHTML.split('<!--scullyContent-begin-->')[1].split('<!--scullyContent-end-->')[0];} catch(e) {console.error('scully could not parse content',e);}</script>`;
}
1 change: 0 additions & 1 deletion scully/renderPlugins/routeContentRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {plugins} from '../pluginManagement/pluginRepository';
import {HandledRoute} from '../routerPlugins/addOptionalRoutesPlugin';
import {logError, yellow} from '../utils/log';
import {puppeteerRender} from './puppeteerRenderPlugin';
import { scullyConfig } from '../utils/config';

export const routeContentRenderer = async (route: HandledRoute) => {
const html = await puppeteerRender(route);
Expand Down
2 changes: 1 addition & 1 deletion scully/utils/compileConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const compileConfig = async (): Promise<ScullyConfig> => {
configValidator,
routeSplit,
global,
require: (path: string) => (path.startsWith('@') ? require(path) : require(join(angularRoot, path))),
require: (requirePath: string) => (requirePath.startsWith('@') ? require(requirePath) : require(join(angularRoot, requirePath))),
});
// const tsCompilerConfig: CreateOptions = {
// logError: true,
Expand Down
2 changes: 1 addition & 1 deletion scully/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const updateScullyConfig = async (config: Partial<ScullyConfig>) => {
const newConfig = Object.assign({}, scullyConfig, config);
if (config.outFolder === undefined) {
logWarn(
`The option outFolder isn't configures, we are using "${yellow(scullyConfig.outFolder)} by default now"`
`The option outFolder isn't configured, we are using "${yellow(scullyConfig.outFolder)} by default."`
);
} else {
config.outFolder = join(angularRoot, config.outFolder);
Expand Down
24 changes: 12 additions & 12 deletions scully/utils/defaultAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {addOptionalRoutes, HandledRoute} from '../routerPlugins/addOptionalRoute
import {traverseAppRoutes} from '../routerPlugins/traverseAppRoutesPlugin';
import {storeRoutes} from '../systemPlugins/storeRoutes';
import {writeToFs} from '../systemPlugins/writeToFs.plugin';
import {updateScullyConfig, loadConfig} from '../utils/config';
import {updateScullyConfig, loadConfig} from './config';
import {ScullyConfig} from './interfacesandenums';
import {log} from './log';
import {cpus} from 'os';
Expand All @@ -20,31 +20,31 @@ export const generateAll = async (config?: Partial<ScullyConfig>) => {
log('Finding all routes in application.');
const appRouteArray = await traverseAppRoutes();
log('Pull in data to create additional routes.');
const dataroutes = await addOptionalRoutes(appRouteArray);
storeRoutes(dataroutes);
const dataRoutes = await addOptionalRoutes(appRouteArray);
await storeRoutes(dataRoutes);
/** launch the browser, its shared among renderers */
const browser = await launchedBrowser();
/** start handling each route, works in chunked parrallel mode */
// await doChunks(dataroutes);
await renderParralell(dataroutes);
/** start handling each route, works in chunked parallel mode */
// await doChunks(dataRoutes);
await renderParallel(dataRoutes);
/** save router to static json thingie */
storeRoutes(dataroutes);
return dataroutes;
await storeRoutes(dataRoutes);
return dataRoutes;
} catch (e) {
// TODO: add better error handling
log(e);
}
return [];
};

async function renderParralell(dataroutes) {
async function renderParallel(dataRoutes) {
const renderRoute = route =>
routeContentRenderer(route).then((html: string) => writeToFs(route.route, html));
return asyncPool(cpus().length, dataroutes, renderRoute);
return asyncPool(cpus().length, dataRoutes, renderRoute);
}

async function doChunks(dataroutes) {
const chunked = chunk(dataroutes, cpus().length);
async function doChunks(dataRoutes) {
const chunked = chunk(dataRoutes, cpus().length);

return chunked.reduce(async (acc, part) => {
const x = await acc;
Expand Down
2 changes: 1 addition & 1 deletion scully/utils/findAngularJsonPath.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {dirname, resolve} from 'path';
import {resolve} from 'path';
import {existsSync, statSync} from 'fs';

export function findAngularJsonPath(path?: string): string {
Expand Down
4 changes: 2 additions & 2 deletions scully/utils/fsAngular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {join} from 'path';
import {Observable} from 'rxjs';
import {debounceTime, filter, tap} from 'rxjs/operators';
import {restartStaticServer, startScullyWatchMode} from '../scully';
import {green, log, logWarn, red} from '../utils/log';
import {green, log, logWarn, red} from './log';
import {scullyConfig} from './config';
import {createFolderFor} from './createFolderFor';

Expand All @@ -27,7 +27,7 @@ function reWatch(folder, reset = true, watch = false) {
watchFolder(join(folder, '../'))
.pipe(
// TODO test on mac, figure out what's coming in.
// only act upon changes of the actual folder i'm intrested in.
// only act upon changes of the actual folder I'm interested in.
filter(r => r.fileName.includes(filename)),
// tap(r => log(`debug only: filename:"${yellow(filename)}" changedName:"${yellow(r.fileName)}"`)),
/** give the CLI some time to finnish */
Expand Down
16 changes: 5 additions & 11 deletions scully/utils/fsFolder.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import {existsSync, readFileSync} from 'fs';
import {existsSync} from 'fs';
import {join} from 'path';
import {Observable} from 'rxjs';
import {throttleTime, filter, tap} from 'rxjs/operators';
import {log, red} from '../utils/log';
import {filter, throttleTime} from 'rxjs/operators';
import {log, red} from './log';
import {watch} from 'chokidar';
import {scullyConfig} from './config';
import {jsonc} from 'jsonc';
import {startScullyWatchMode} from '../scully';


Expand Down Expand Up @@ -34,16 +33,14 @@ export async function checkStaticFolder() {
} catch (e) {
console.log('error into read the config', e);
}


}

function reWatch(folder) {
const filename = join(folder);
watchFolder(filename)
.pipe(
// TODO test on mac, figure out what's coming in.
// only act upon changes of the actual folder i'm intrested in.
// only act upon changes of the actual folder I'm interested in.
filter(r => r.fileName.startsWith(folder)),
throttleTime(3000)
)
Expand Down Expand Up @@ -75,10 +72,7 @@ function watchFolder(folder): Observable<{eventType: string; fileName: string}>

export function existFolder(src) {
try {
if (!existsSync(src)) {
return false;
}
return true;
return existsSync(src);
} catch (e) {
return false;
}
Expand Down
1 change: 0 additions & 1 deletion scully/utils/httpGetJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,3 @@ export function httpGetJson(
});
});
}

2 changes: 1 addition & 1 deletion scully/utils/isPortTaken.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {createServer} from 'net';
import {logWarn} from '../utils/log';
import {logWarn} from './log';
// const net = require('net');

export const isPortTaken = (usedPort: number): Promise<boolean> =>
Expand Down
2 changes: 1 addition & 1 deletion scully/utils/restart.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {spawn} from 'child_process';

export function restartProcess() {
process.on('exit', function() {
process.on('exit', () => {
spawn(process.argv.shift(), process.argv, {
cwd: process.cwd(),
detached: true,
Expand Down
4 changes: 2 additions & 2 deletions scully/utils/startup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {generateAll} from './defaultAction';
import {ScullyConfig} from './interfacesandenums';
import {performance, PerformanceObserver} from 'perf_hooks';
import {yellow, log} from './log';
import {HandledRoute} from '../routerPlugins/addOptionalRoutesPlugin';
import {log, yellow} from './log';

/**
* Starts the entire process
* @param config:ScullyConfig
Expand Down
4 changes: 2 additions & 2 deletions scully/utils/validateConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function validateConfig(config: ScullyConfig) {
const result: Partial<ScullyConfig> = {routes: {}};
if (config.projectRoot) {
if (!checkFolderExists(config.projectRoot)) {
error(`ProjectRoot folder not found "${yellow(config.projectRoot)}"`);
error(`projectRoot folder not found "${yellow(config.projectRoot)}"`);
}
result.projectRoot = config.projectRoot;
} else {
Expand Down Expand Up @@ -51,7 +51,7 @@ export async function validateConfig(config: ScullyConfig) {
})
);
} else {
logWarn('No routes defined in "scully.config.js "');
logWarn('No routes defined in "scully.config.js"');
}
if (hasErrors) {
/** stop everything if there are errors in the config. */
Expand Down