Skip to content

Commit

Permalink
Sander/work on contextof vm (#51)
Browse files Browse the repository at this point in the history
* Added scully mode detection. (in scully/from generated)
* replaces require with custom one, and added node's global to context
* remove stray blog sample
  • Loading branch information
SanderElias authored Dec 19, 2019
1 parent 4d5b46a commit 1e558e0
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 25 deletions.
24 changes: 24 additions & 0 deletions extraPlugin/extra-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

const {configValidator} = require('../scully/bin');

console.log(__dirname)

exports.extraRoutesPlugin = (route, options) => {
const {createPath} = routeSplit(route);
if (options.numberOfPages) {
return Array.from({length: options.numberOfPages}, (_v, k) => k).map(n => ({
route: `${createPath(`${n}`)}`,
title: `page number ${n}`,
}));
}
if (options.data) {
return options.data.map(item => ({
route: createPath(item.data),
title: item.title || '',
}));
}
return [];
};
/** the validator is mandatory */
exports.extraRoutesPlugin[configValidator] = async options => [];

24 changes: 4 additions & 20 deletions scully.config.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
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}`)}`,
title: `page number ${n}`,
}));
}
if (options.data) {
return options.data.map(item => ({
route: createPath(item.data),
title: item.title || '',
}));
}
return [];
};
extraRoutesPlugin[configValidator] = async config => {
return [];
};

/** load the plugin */
const {extraRoutesPlugin} = require('./extraPlugin/extra-plugin.js')
/** register the plugin */
registerPlugin('router', 'extra', extraRoutesPlugin);


exports.config = {
/** projectRoot is mandatory! */
projectRoot: './projects/sampleBlog/src/app',
Expand Down
2 changes: 1 addition & 1 deletion 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.44",
"version": "0.0.45",
"description": "Scully CLI",
"repository": {
"type": "GIT",
Expand Down
3 changes: 2 additions & 1 deletion scully/pluginManagement/pluginRepository.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {HandledRoute} from '../routerPlugins/addOptionalRoutesPlugin';
import {logError, yellow} from '../utils/log';

export const configValidator = Symbol('configValidator');
// export const configValidator = Symbol('configValidator');
export const configValidator = `___Scully_Validate_config_plugin___`;

export type PluginHandler = (...args: any) => Promise<any>;
export interface Plugin {
Expand Down
9 changes: 7 additions & 2 deletions scully/utils/compileConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {join} from 'path';
import {createContext, runInContext} from 'vm';
import {ScullyConfig} from '..';
import {configValidator, registerPlugin} from '../pluginManagement/pluginRepository';
import {angularRoot} from './config';
import {angularRoot, scullyConfig} from './config';
import {routeSplit} from './routeSplit';

export const compileConfig = async (): Promise<ScullyConfig> => {
Expand All @@ -22,7 +22,8 @@ export const compileConfig = async (): Promise<ScullyConfig> => {
registerPlugin,
configValidator,
routeSplit,
require,
global,
require: (path: string) => (path.startsWith('@') ? require(path) : require(join(angularRoot, path))),
});
// const tsCompilerConfig: CreateOptions = {
// logError: true,
Expand All @@ -46,3 +47,7 @@ export const compileConfig = async (): Promise<ScullyConfig> => {
return ({} as unknown) as ScullyConfig;
}
};

function myReq(path: string): Promise<any> {
return import(join(scullyConfig.homeFolder, path));
}

0 comments on commit 1e558e0

Please sign in to comment.