Skip to content

Commit

Permalink
feat: Add "gatsby plugin" command (#27725)
Browse files Browse the repository at this point in the history
* feat: Add "gatsby plugin" command

* Lint

* Add env flag
  • Loading branch information
ascorbic authored Oct 30, 2020
1 parent 023daf2 commit 5869cc5
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 36 deletions.
55 changes: 19 additions & 36 deletions packages/gatsby-cli/src/create-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,25 @@ function buildLocalCommands(cli: yargs.Argv, isLocalSite: boolean): void {
}
),
})

cli.command({
command: `plugin <cmd> [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 {
Expand Down Expand Up @@ -508,42 +527,6 @@ export const createCli = (argv: Array<string>): 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.`,
Expand Down
6 changes: 6 additions & 0 deletions packages/gatsby/src/commands/plugin-add.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default async function run({ plugins }: IProgram): Promise<void> {
if (!plugins?.length) {
console.log(`Please specify a plugin to install`)
}
console.log(plugins)
}
36 changes: 36 additions & 0 deletions packages/gatsby/src/commands/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import add from "./plugin-add"

module.exports = async (args: IProgram): Promise<void> => {
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
}

0 comments on commit 5869cc5

Please sign in to comment.