diff --git a/libs/scully-schematics/src/add-plugin/index.ts b/libs/scully-schematics/src/add-plugin/index.ts index 60fdb4ff3..45a924869 100644 --- a/libs/scully-schematics/src/add-plugin/index.ts +++ b/libs/scully-schematics/src/add-plugin/index.ts @@ -21,9 +21,9 @@ const addPlugin = (options: Schema) => ( ) => { const sourceRoot = getRoot(tree, options.project); const pathName = strings.dasherize( - `${sourceRoot}/scullyPlugins/${options.name}.js` + `${sourceRoot}/scully-plugins/` ); - return applyWithOverwrite(url('../files/add-plugin'), [ + return applyWithOverwrite(url(`../files/plugin/${options.pluginType}`), [ applyTemplates({ classify: strings.classify, dasherize: strings.dasherize, @@ -42,7 +42,7 @@ const registerPlugin = (options: Schema) => ( let scullyConfig = tree .read(`${getRoot(tree, options.project)}/${scullyConfigFile}`) .toString(); - scullyConfig = `require('./scullyPlugins/extra-plugin.js');\n${scullyConfig}`; + scullyConfig = `require('./scully-plugins/${strings.dasherize(options.name)}.plugin.js');\n${scullyConfig}`; tree.overwrite( `${getRoot(tree, options.project)}/${scullyConfigFile}`, scullyConfig diff --git a/libs/scully-schematics/src/add-plugin/schema.json b/libs/scully-schematics/src/add-plugin/schema.json index 7fc29d85b..a5751c4cf 100644 --- a/libs/scully-schematics/src/add-plugin/schema.json +++ b/libs/scully-schematics/src/add-plugin/schema.json @@ -7,12 +7,21 @@ "name": { "type": "string", "description": "add the name for the plugin", + "$default": { + "$source": "argv", + "index": 0 + }, "x-prompt": "What name do you want to use for the plugin?" }, "project": { "type": "string", "description": "add the project", "default": "defaultProject" + }, + "pluginType": { + "enum": ["router", "render"], + "type": "string", + "x-prompt": "What type of plugin do you want to create?" } }, "required": ["name"] diff --git a/libs/scully-schematics/src/add-plugin/schema.ts b/libs/scully-schematics/src/add-plugin/schema.ts index 2fa25f9f1..2c57e35ce 100644 --- a/libs/scully-schematics/src/add-plugin/schema.ts +++ b/libs/scully-schematics/src/add-plugin/schema.ts @@ -4,4 +4,8 @@ export interface Schema { */ name: string; project: string; + /** + * The type of plugin + */ + pluginType: 'router' | 'render'; } diff --git a/libs/scully-schematics/src/files/plugin/render/__name@dasherize__.plugin.js.template b/libs/scully-schematics/src/files/plugin/render/__name@dasherize__.plugin.js.template new file mode 100644 index 000000000..28b317293 --- /dev/null +++ b/libs/scully-schematics/src/files/plugin/render/__name@dasherize__.plugin.js.template @@ -0,0 +1,22 @@ +/** import from scully the register plugin function */ +const {registerPlugin} = require('@scullyio/scully'); + +/** create the plugin function */ +const <%= camelize(name) %> = (html, route) => { + const updatedHtml = html; + /** + This is a render plugin that needs return the updated HTML + using a Promise. + **/ + return Promise.resolve(updatedHtml); +}; + +/** + You can add extra validator for your custom plugin +*/ +const validator = async conf => []; + +/** + registerPlugin(TypeOfPlugin, name of the plugin, plugin function, validator) +*/ +registerPlugin('render', '<%= camelize(name) %>', <%= camelize(name) %>, validator); diff --git a/libs/scully-schematics/src/files/plugin/__name@dasherize__.plugin.js.template b/libs/scully-schematics/src/files/plugin/router/__name@dasherize__.plugin.js.template similarity index 100% rename from libs/scully-schematics/src/files/plugin/__name@dasherize__.plugin.js.template rename to libs/scully-schematics/src/files/plugin/router/__name@dasherize__.plugin.js.template