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
8 changes: 4 additions & 4 deletions extraPlugin/extra-plugin.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const {configValidator, routeSplit} = require('../scully/bin');
const {configValidator, routeSplit, registerPlugin} = require('../scully/bin');

console.log(__dirname);

const extraRoutesPlugin = (route, options) => {
const {createPath} = routeSplit(route);
if (options.numberOfPages) {
return Array.from({length: options.numberOfPages}, (_v, k) => k).map(n => ({
route: `${createPath(`${n}`)}`,
route: createPath(n.toString()),
title: `page number ${n}`,
}));
}
Expand Down Expand Up @@ -44,5 +44,5 @@ extraRoutesPlugin[configValidator] = async options => {
return errors;
};

exports.extraRoutesPlugin = extraRoutesPlugin;
/** the validator is mandatory */
registerPlugin('router', 'extra', extraRoutesPlugin);
module.exports.extraRoutesPlugin = extraRoutesPlugin;
594 changes: 346 additions & 248 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"zone.js": "~0.10.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.900.0-rc.5",
"@angular-devkit/build-angular": "^0.900.0-rc.7",
"@angular-devkit/build-ng-packagr": "~0.900.0-rc.5",
"@angular/cli": "~9.0.0-rc.5",
"@angular/compiler-cli": "~9.0.0-rc.6",
Expand Down
2 changes: 1 addition & 1 deletion projects/sampleBlog/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const routes: Routes = [
loadChildren: () => import('./user/user.module').then(m => m.UserModule),
},
{path: 'demo', loadChildren: () => import('./demo/demo.module').then(m => m.DemoModule)},
{path: '', redirectTo: '/home', pathMatch: 'full'}
// {path: '', redirectTo: '/home/', pathMatch: 'full'}
];

@NgModule({
Expand Down
5 changes: 2 additions & 3 deletions scully.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/** load the plugin */
const {extraRoutesPlugin} = require('./extraPlugin/extra-plugin.js');
/** register the plugin */
registerPlugin('router', 'extra', extraRoutesPlugin);
require('./extraPlugin/extra-plugin.js')


exports.config = {
/** projectRoot is mandatory! */
Expand Down
53 changes: 16 additions & 37 deletions scully/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 scully/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scullyio/scully",
"version": "0.0.45",
"version": "0.0.49",
"description": "Scully CLI",
"repository": {
"type": "GIT",
Expand Down
8 changes: 7 additions & 1 deletion scully/renderPlugins/launchedBrowser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import {Browser, launch, LaunchOptions} from 'puppeteer';
import {Observable} from 'rxjs';
import {shareReplay, take} from 'rxjs/operators';
import * as yargs from 'yargs';

const {showBrowser} = yargs
.boolean('sb')
.alias('sb', 'showBrowser')
.describe('sb', 'Shows the puppeteer controlled browser').argv;

/** use shareReplay so the browser will stay in memory during the lifetime of the program */
const launched = obsBrowser().pipe(shareReplay({refCount: false, bufferSize: 1}));
Expand All @@ -9,7 +15,7 @@ let browser: Browser;

function obsBrowser(
options: LaunchOptions = {
headless: true,
headless: !showBrowser,
// dumpio: true,
args: ['--no-sandbox', '--disable-setuid-sandbox'],
}
Expand Down
43 changes: 10 additions & 33 deletions scully/utils/compileConfig.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,24 @@
import {readFileSync} from 'fs';
import {pathExists} from 'fs-extra';
import {join} from 'path';
// import {create, CreateOptions} from 'ts-node';
import {createContext, runInContext} from 'vm';
import * as yargs from 'yargs';
import {ScullyConfig} from '..';
import {configValidator, registerPlugin} from '../pluginManagement/pluginRepository';
import {angularRoot, scullyConfig} from './config';
import {routeSplit} from './routeSplit';

export const {configFile: configFileName} = yargs
.string('cf')
.alias('cf', 'configFile')
.default('cf', 'scully.config.js')
.describe('cf', 'provide name for config file').argv;

export const compileConfig = async (): Promise<ScullyConfig> => {
try {
const filename = 'scully.config.js';
const path = join(angularRoot, filename);
const path = join(angularRoot, configFileName);
if (!(await pathExists(path))) {
/** no ts config, nothing to do. */
return ({} as unknown) as ScullyConfig;
}
const runtimeEnvironment = createContext({
exports: {},
console,
registerPlugin,
configValidator,
routeSplit,
global,
require: (requirePath: string) => (requirePath.startsWith('@') ? require(requirePath) : require(join(angularRoot, requirePath))),
});
// const tsCompilerConfig: CreateOptions = {
// logError: true,
// compilerOptions: {
// sourceMap: true,
// target: 'es2018',
// module: 'commonjs',
// lib: ['dom', 'es2018'],
// types: ['../types.d.ts']
// // typeRoots: ['node', '/scully/bin/utils/routeSplit.d.ts'],
// },
// };
// const ts = create(tsCompilerConfig);
const tsCode = readFileSync(path).toString();
// const jsCode = ts.compile(tsCode, filename, 0);
const jsCode = tsCode;
runInContext(jsCode, runtimeEnvironment, {filename, displayErrors: true});
return runtimeEnvironment.exports.config;
const {config} = await import(path);
return config;
} catch (e) {
console.error(e);
return ({} as unknown) as ScullyConfig;
Expand Down
5 changes: 3 additions & 2 deletions scully/utils/validateConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {configValidator, plugins} from '../pluginManagement/pluginRepository';
import {angularRoot} from './config';
import {ScullyConfig} from './interfacesandenums';
import {logError, logWarn, yellow} from './log';
import {configFileName} from './compileConfig';

// TODO: make sure all route options are validated.
let hasErrors = false;
Expand All @@ -24,7 +25,7 @@ export async function validateConfig(config: ScullyConfig) {
result.projectRoot = config.projectRoot;
} else {
// TODO define a constant for the config file name string
error(`projectRoot missing in "${yellow('scully.config.js')}"`);
error(`projectRoot missing in "${yellow(configFileName)}"`);
}
if (config.routes) {
await Promise.all(
Expand All @@ -51,7 +52,7 @@ export async function validateConfig(config: ScullyConfig) {
})
);
} else {
logWarn('No routes defined in "scully.config.js"');
logWarn(`No routes defined in "${yellow(configFileName)}"`);
}
if (hasErrors) {
/** stop everything if there are errors in the config. */
Expand Down