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 "gatsby plugin" command #27725

Merged
merged 3 commits into from Oct 30, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 19 additions & 36 deletions packages/gatsby-cli/src/create-cli.ts
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
@@ -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
@@ -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
}