From 5869cc5ab2189b257944a4c3f99af564be81ea80 Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Fri, 30 Oct 2020 11:13:35 +0000 Subject: [PATCH] feat: Add "gatsby plugin" command (#27725) * feat: Add "gatsby plugin" command * Lint * Add env flag --- packages/gatsby-cli/src/create-cli.ts | 55 ++++++++-------------- packages/gatsby/src/commands/plugin-add.ts | 6 +++ packages/gatsby/src/commands/plugin.ts | 36 ++++++++++++++ 3 files changed, 61 insertions(+), 36 deletions(-) create mode 100644 packages/gatsby/src/commands/plugin-add.ts create mode 100644 packages/gatsby/src/commands/plugin.ts diff --git a/packages/gatsby-cli/src/create-cli.ts b/packages/gatsby-cli/src/create-cli.ts index 4cb2cffd6edf5..16011f669570b 100644 --- a/packages/gatsby-cli/src/create-cli.ts +++ b/packages/gatsby-cli/src/create-cli.ts @@ -393,6 +393,25 @@ function buildLocalCommands(cli: yargs.Argv, isLocalSite: boolean): void { } ), }) + + cli.command({ + command: `plugin [plugins...]`, + describe: `Useful commands relating to Gatsby plugins`, + builder: yargs => + yargs + .positional(`cmd`, { + choices: process.env.GATSBY_EXPERIMENTAL_PLUGIN_COMMANDS + ? [`docs`, `add`, `configure`] + : [`docs`], + describe: "Valid commands include `docs`.", + type: `string`, + }) + .positional(`plugins`, { + describe: `The plugin names`, + type: `string`, + }), + handler: getCommandHandler(`plugin`), + }) } function isLocalGatsbySite(): boolean { @@ -508,42 +527,6 @@ export const createCli = (argv: Array): yargs.Arguments => { report.log(`Telemetry collection ${enabled ? `enabled` : `disabled`}`) }), }) - .command({ - command: `plugin [cmd]`, - describe: `Useful commands relating to Gatsby plugins`, - builder: yargs => - yargs.positional(`cmd`, { - choices: [`docs`], - describe: "Valid commands include `docs`.", - type: `string`, - }), - handler: handlerP(({ cmd }) => { - if (cmd === `docs`) { - console.log(` - Using a plugin: - - What is a Plugin? (https://www.gatsbyjs.com/docs/what-is-a-plugin/) - - Using a Plugin in Your Site (https://www.gatsbyjs.com/docs/using-a-plugin-in-your-site/) - - What You Don't Need Plugins For (https://www.gatsbyjs.com/docs/what-you-dont-need-plugins-for/) - - Loading Plugins from Your Local Plugins Folder (https://www.gatsbyjs.com/docs/loading-plugins-from-your-local-plugins-folder/) - - Plugin Library (https://www.gatsbyjs.com/plugins/) - - Creating a plugin: - - Naming a Plugin (https://www.gatsbyjs.com/docs/naming-a-plugin/) - - Files Gatsby Looks for in a Plugin (https://www.gatsbyjs.com/docs/files-gatsby-looks-for-in-a-plugin/) - - Creating a Generic Plugin (https://www.gatsbyjs.com/docs/creating-a-generic-plugin/) - - Creating a Local Plugin (https://www.gatsbyjs.com/docs/creating-a-local-plugin/) - - Creating a Source Plugin (https://www.gatsbyjs.com/docs/creating-a-source-plugin/) - - Creating a Transformer Plugin (https://www.gatsbyjs.com/docs/creating-a-transformer-plugin/) - - Submit to Plugin Library (https://www.gatsbyjs.com/contributing/submit-to-plugin-library/) - - Source Plugin Tutorial (https://www.gatsbyjs.com/tutorial/source-plugin-tutorial/) - - Maintaining a Plugin (https://www.gatsbyjs.com/docs/maintaining-a-plugin/) - - Join Discord #plugin-authoring channel to ask questions! (https://gatsby.dev/discord/) - `) - } else { - console.log(`Current valid subcommands are: 'docs'`) // right now this is hardcoded because we only have a single command - } - }), - }) .command({ command: `options [cmd] [key] [value]`, describe: `View or set your gatsby-cli configuration settings.`, diff --git a/packages/gatsby/src/commands/plugin-add.ts b/packages/gatsby/src/commands/plugin-add.ts new file mode 100644 index 0000000000000..78dd8f7c5e8d4 --- /dev/null +++ b/packages/gatsby/src/commands/plugin-add.ts @@ -0,0 +1,6 @@ +export default async function run({ plugins }: IProgram): Promise { + if (!plugins?.length) { + console.log(`Please specify a plugin to install`) + } + console.log(plugins) +} diff --git a/packages/gatsby/src/commands/plugin.ts b/packages/gatsby/src/commands/plugin.ts new file mode 100644 index 0000000000000..082e07af5d679 --- /dev/null +++ b/packages/gatsby/src/commands/plugin.ts @@ -0,0 +1,36 @@ +import add from "./plugin-add" + +module.exports = async (args: IProgram): Promise => { + const { report, cmd } = args + switch (cmd) { + case `docs`: + console.log(` + Using a plugin: + - What is a Plugin? (https://www.gatsbyjs.com/docs/what-is-a-plugin/) + - Using a Plugin in Your Site (https://www.gatsbyjs.com/docs/using-a-plugin-in-your-site/) + - What You Don't Need Plugins For (https://www.gatsbyjs.com/docs/what-you-dont-need-plugins-for/) + - Loading Plugins from Your Local Plugins Folder (https://www.gatsbyjs.com/docs/loading-plugins-from-your-local-plugins-folder/) + - Plugin Library (https://www.gatsbyjs.com/plugins/) + + Creating a plugin: + - Naming a Plugin (https://www.gatsbyjs.com/docs/naming-a-plugin/) + - Files Gatsby Looks for in a Plugin (https://www.gatsbyjs.com/docs/files-gatsby-looks-for-in-a-plugin/) + - Creating a Generic Plugin (https://www.gatsbyjs.com/docs/creating-a-generic-plugin/) + - Creating a Local Plugin (https://www.gatsbyjs.com/docs/creating-a-local-plugin/) + - Creating a Source Plugin (https://www.gatsbyjs.com/docs/creating-a-source-plugin/) + - Creating a Transformer Plugin (https://www.gatsbyjs.com/docs/creating-a-transformer-plugin/) + - Submit to Plugin Library (https://www.gatsbyjs.com/contributing/submit-to-plugin-library/) + - Source Plugin Tutorial (https://www.gatsbyjs.com/tutorial/source-plugin-tutorial/) + - Maintaining a Plugin (https://www.gatsbyjs.com/docs/maintaining-a-plugin/) + - Join Discord #plugin-authoring channel to ask questions! (https://gatsby.dev/discord/) + `) + return void 0 + + case `add`: + return add(args) + + default: + report.error(`Unknown command ${cmd}`) + } + return void 0 +}