diff --git a/extraPlugin/extra-plugin.js b/extraPlugin/extra-plugin.js new file mode 100644 index 000000000..bb7e0e227 --- /dev/null +++ b/extraPlugin/extra-plugin.js @@ -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 => []; + diff --git a/scully.config.js b/scully.config.js index 296a9476a..b6eb03a1d 100644 --- a/scully.config.js +++ b/scully.config.js @@ -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', diff --git a/scully/package-lock.json b/scully/package-lock.json index bf2b8cea9..7a3e37a4a 100644 --- a/scully/package-lock.json +++ b/scully/package-lock.json @@ -1,6 +1,6 @@ { "name": "@scullyio/scully", - "version": "0.0.44", + "version": "0.0.45", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/scully/package.json b/scully/package.json index 9b6366030..8d27d48d9 100644 --- a/scully/package.json +++ b/scully/package.json @@ -1,6 +1,6 @@ { "name": "@scullyio/scully", - "version": "0.0.44", + "version": "0.0.45", "description": "Scully CLI", "repository": { "type": "GIT", diff --git a/scully/pluginManagement/pluginRepository.ts b/scully/pluginManagement/pluginRepository.ts index 626516423..56fdab248 100644 --- a/scully/pluginManagement/pluginRepository.ts +++ b/scully/pluginManagement/pluginRepository.ts @@ -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; export interface Plugin { diff --git a/scully/utils/compileConfig.ts b/scully/utils/compileConfig.ts index 8a15feae8..3042c6add 100644 --- a/scully/utils/compileConfig.ts +++ b/scully/utils/compileConfig.ts @@ -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 => { @@ -22,7 +22,8 @@ export const compileConfig = async (): Promise => { registerPlugin, configValidator, routeSplit, - require, + global, + require: (path: string) => (path.startsWith('@') ? require(path) : require(join(angularRoot, path))), }); // const tsCompilerConfig: CreateOptions = { // logError: true, @@ -46,3 +47,7 @@ export const compileConfig = async (): Promise => { return ({} as unknown) as ScullyConfig; } }; + +function myReq(path: string): Promise { + return import(join(scullyConfig.homeFolder, path)); +}