Skip to content

Commit

Permalink
feat: better default plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
raae committed Feb 3, 2022
1 parent 2636205 commit c9d417a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
7 changes: 6 additions & 1 deletion demo/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
module.exports = {
plugins: ["@raae/gatsby-plugin-starter"],
plugins: {
resolve: "@raae/gatsby-plugin-starter",
options: {
emoji: "pirate",
},
},
};
5 changes: 5 additions & 0 deletions plugin/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exports.EMOJIS = {
crown: "👑",
pirate: "🏴‍☠️",
princess: "👸",
};
9 changes: 9 additions & 0 deletions plugin/gatsby-browser.js
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
// https://www.gatsbyjs.com/docs/reference/config-files/gatsby-browser/

const { EMOJIS } = require("./constants");

exports.onInitialClientRender = (_, pluginOptions) => {
const { message, emoji } = pluginOptions;
const selectedEmoji = EMOJIS[emoji];

alert(`${selectedEmoji} ${message} ${selectedEmoji}`);
};
13 changes: 9 additions & 4 deletions plugin/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
// https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/

const { EMOJIS } = require("./constants");

const validKeys = Object.keys(EMOJIS);

exports.pluginOptionsSchema = ({ Joi }) => {
return Joi.object({
option1: Joi.string()
.valid("unicorn", "pirate")
.default("unicorn")
.description(`Plugin option 1`),
message: Joi.string().default("Hello from the Plugin"),
emoji: Joi.string()
.valid(...validKeys)
.default(validKeys[0])
.description(`Select between the emoji options`),
});
};

0 comments on commit c9d417a

Please # to comment.