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(gatsby): people who are using a flag, invite them to try out other flags #28338

Merged
merged 2 commits into from
Nov 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ Object {
- ALL_COMMANDS · (Umbrella Issue (test)) · test
- DEV_SSR · (Umbrella Issue (https://github.com/gatsbyjs/gatsby/discussions/28138)) · SSR pages on full reloads during develop. Helps you detect SSR bugs and fix them without needing to do full builds.
- QUERY_ON_DEMAND · (Umbrella Issue (https://github.com/gatsbyjs/gatsby/discussions/27620)) · Only run queries when needed instead of running all queries upfront. Speeds starting the develop server.

There are 2 other flags available that you might be interested in:
- ONLY_BUILDS · (Umbrella Issue (test)) · test
- YET_ANOTHER · (Umbrella Issue (test)) · test
",
}
`;
7 changes: 7 additions & 0 deletions packages/gatsby/src/utils/__tests__/handle-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ describe(`handle flags`, () => {
description: `test`,
umbrellaIssue: `test`,
},
{
name: `YET_ANOTHER`,
env: `GATSBY_EXPERIMENTAL_SOMETHING_COOL2`,
command: `all`,
description: `test`,
umbrellaIssue: `test`,
},
]

const configFlags = {
Expand Down
49 changes: 31 additions & 18 deletions packages/gatsby/src/utils/handle-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,44 @@ const handleFlags = (
// TODO remove flags that longer exist.
// w/ message of thanks

const generateFlagLine = (flag): string => {
let message = ``
message += `\n- ${flag.name}`
if (flag.experimental) {
message += ` · ${chalk.white.bgRed.bold(`EXPERIMENTAL`)}`
}
if (flag.umbrellaIssue) {
message += ` · (${terminalLink(`Umbrella Issue`, flag.umbrellaIssue)})`
}
message += ` · ${flag.description}`

return message
}

let message = ``
// Create message about what flags are active.
if (enabledConfigFlags.length > 0) {
message = `The following flags are active:`
enabledConfigFlags.forEach(flag => {
message += `\n- ${flag.name}`
if (flag.experimental) {
message += ` · ${chalk.white.bgRed.bold(`EXPERIMENTAL`)}`
}
if (flag.umbrellaIssue) {
message += ` · (${terminalLink(`Umbrella Issue`, flag.umbrellaIssue)})`
}
message += ` · ${flag.description}`
message += generateFlagLine(flag)
})

// TODO renable once "gatsby flags` CLI command exists.
// Suggest enabling other flags if they're not trying them all.
// const otherFlagsCount = flags.length - enabledConfigFlags.length
// if (otherFlagsCount > 0) {
// message += `\n\nThere ${
// otherFlagsCount === 1
// ? `is one other flag`
// : `are ${otherFlagsCount} other flags`
// } available you can test — run "gatsby flags" to enable them`
// }
const otherFlagsCount = flags.length - enabledConfigFlags.length
if (otherFlagsCount > 0) {
message += `\n\nThere ${
otherFlagsCount === 1
? `is one other flag`
: `are ${otherFlagsCount} other flags`
} available that you might be interested in:`

const enabledFlagsSet = new Set()
enabledConfigFlags.forEach(f => enabledFlagsSet.add(f.name))
flags.forEach(flag => {
if (!enabledFlagsSet.has(flag.name)) {
message += generateFlagLine(flag)
}
})
}

message += `\n`
}
Expand Down