Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option to generate render or route plugin to add-plugin schematic #734

Merged
merged 1 commit into from
Jul 13, 2020
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
6 changes: 3 additions & 3 deletions libs/scully-schematics/src/add-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions libs/scully-schematics/src/add-plugin/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
4 changes: 4 additions & 0 deletions libs/scully-schematics/src/add-plugin/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ export interface Schema {
*/
name: string;
project: string;
/**
* The type of plugin
*/
pluginType: 'router' | 'render';
}
Original file line number Diff line number Diff line change
@@ -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);