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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Scully

[![](./assets/logos/PNG/scullyio-logo.png)]()

[![GitHub](https://img.shields.io/github/license/scullyio/scully)](https://github.com/scullyio/scully/blob/master/LICENSE)
[![Gitter](https://img.shields.io/gitter/room/scullyio/community)](https://gitter.im/scullyio/community)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
Expand Down
1 change: 1 addition & 0 deletions scully.sampleBlog.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ exports.config = {
/** outDir is where the static distribution files end up */
outDir: './dist/static',
// hostName: '0.0.0.0',
hostUrl: 'http://localHost:5000',
extraRoutes: [''],
routes: {
'/demo/:id': {
Expand Down
4 changes: 2 additions & 2 deletions scully/routerPlugins/traverseAppRoutesPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ ${green('When there are extraRoutes in your config, we will still try to render
}
// process.exit(15);
const allRoutes = [...routes, ...extraRoutes];
if (allRoutes.findIndex(r => r === '') === -1) {
if (allRoutes.findIndex(r => r.trim() === '' || r.trim() === '/') === -1) {
/** make sure the root Route is always rendered. */
allRoutes.push('');
allRoutes.push('/');
}
return allRoutes;
};
Expand Down
35 changes: 20 additions & 15 deletions scully/scully.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import {join} from 'path';
import * as yargs from 'yargs';
import './pluginManagement/systemPlugins';
import {startBackgroundServer} from './startBackgroundServer';
import {loadConfig, scullyConfig} from './utils/config';
import {loadConfig} from './utils/config';
import {moveDistAngular} from './utils/fsAngular';
import {httpGetJson} from './utils/httpGetJson';
import {isPortTaken} from './utils/isPortTaken';
import {logError} from './utils/log';
import {logError, logWarn, yellow} from './utils/log';
import {startScully} from './utils/startup';
import {waitForServerToBeAvailable} from './utils/waitForServerToBeAvailable';
import {bootServe, isBuildThere, watchMode} from './watchMode';
Expand Down Expand Up @@ -62,29 +62,34 @@ if (process.argv.includes('version')) {
const folder = join(scullyConfig.homeFolder, scullyConfig.distFolder);
/** copy in current build artifacts */
await moveDistAngular(folder, scullyConfig.outDir, {removeStaticDist, reset: false});

/** server ports already in use? */
const isTaken = await isPortTaken(scullyConfig.staticport);
if (!isTaken) {
startBackgroundServer(scullyConfig);
} else {
// debug only
console.log(`Background servers already running.`);
}

if (!(await waitForServerToBeAvailable().catch(e => false))) {
logError('Could not connect to server');
process.exit(15);
if (typeof scullyConfig.hostUrl === 'string') {
logWarn(`
You are using "${yellow(scullyConfig.hostUrl)}" as server.
`);
} else {
/** server ports already in use? */
if (!isTaken) {
startBackgroundServer(scullyConfig);
} else {
// debug only
console.log(`Background servers already running.`);
}
if (!(await waitForServerToBeAvailable().catch(e => false))) {
logError('Could not connect to server');
process.exit(15);
}
}
if (watch) {
watchMode(
join(scullyConfig.homeFolder, scullyConfig.distFolder) ||
join(scullyConfig.homeFolder, './dist/browser')
);
} else {
console.log('servers available');
// console.log('servers available');
await startScully();
if (!isTaken) {
if (!isTaken && typeof scullyConfig.hostUrl !== 'string') {
// kill serve ports
await httpGetJson(`http://${scullyConfig.hostName}:${scullyConfig.appPort}/killMe`, {
suppressErrors: true,
Expand Down
2 changes: 2 additions & 0 deletions scully/utils/cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const rawRoutesCache = new Set<string>();
export const flushRawRoutesCache = () => rawRoutesCache.clear();
11 changes: 5 additions & 6 deletions scully/utils/defaultAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,28 @@ import {chunk} from './chunk';
import {loadConfig} from './config';
import {log, logWarn} from './log';
import {performanceIds} from './performanceIds';
import {rawRoutesCache} from './cache';

export const {baseFilter} = yargs
.string('bf')
.alias('bf', 'baseFilter')
.default('bf', '')
.describe('bf', 'provide a minimatch glob for the unhandled routes').argv;

const cache = new Set<string>();

console.log(baseFilter);
export const generateAll = async (localBaseFilter = baseFilter) => {
await loadConfig;
try {
let unhandledRoutes;
if (cache.size == 0) {
if (rawRoutesCache.size === 0) {
log('Finding all routes in application.');
performance.mark('startTraverse');
unhandledRoutes = await traverseAppRoutes();
performance.mark('stopTraverse');
performanceIds.add('Traverse');
unhandledRoutes.forEach(r => cache.add(r));
unhandledRoutes.forEach(r => rawRoutesCache.add(r));
} else {
unhandledRoutes = [...cache.keys()];
unhandledRoutes = [...rawRoutesCache.keys()];
}

if (unhandledRoutes.length < 1) {
Expand All @@ -46,7 +45,7 @@ export const generateAll = async (localBaseFilter = baseFilter) => {
performanceIds.add('Discovery');
log('Pull in data to create additional routes.');
const handledRoutes = await addOptionalRoutes(
unhandledRoutes.filter((r: string) => r && r.startsWith(localBaseFilter))
unhandledRoutes.filter((r: string) => typeof r === 'string' && r.startsWith(localBaseFilter))
);
performance.mark('stopDiscovery');
/** save routerinfo, so its available during rendering */
Expand Down