Skip to content

Commit cbe3072

Browse files
KyleAMathewspieh
authored andcommitted
feat(gatsby): people who are using a flag, invite them to try out other flags (#28338)
* feat(gatsby): people who are using a flag, invite them to try out other flags * Avoid scaling problems (cherry picked from commit 9c8f788)
1 parent e444a55 commit cbe3072

File tree

3 files changed

+42
-18
lines changed

3 files changed

+42
-18
lines changed

packages/gatsby/src/utils/__tests__/__snapshots__/handle-flags.ts.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ Object {
4141
- ALL_COMMANDS · (Umbrella Issue (test)) · test
4242
- 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.
4343
- 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.
44+
45+
There are 2 other flags available that you might be interested in:
46+
- ONLY_BUILDS · (Umbrella Issue (test)) · test
47+
- YET_ANOTHER · (Umbrella Issue (test)) · test
4448
",
4549
}
4650
`;

packages/gatsby/src/utils/__tests__/handle-flags.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ describe(`handle flags`, () => {
4646
description: `test`,
4747
umbrellaIssue: `test`,
4848
},
49+
{
50+
name: `YET_ANOTHER`,
51+
env: `GATSBY_EXPERIMENTAL_SOMETHING_COOL2`,
52+
command: `all`,
53+
description: `test`,
54+
umbrellaIssue: `test`,
55+
},
4956
]
5057

5158
const configFlags = {

packages/gatsby/src/utils/handle-flags.ts

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,31 +56,44 @@ const handleFlags = (
5656
// TODO remove flags that longer exist.
5757
// w/ message of thanks
5858

59+
const generateFlagLine = (flag): string => {
60+
let message = ``
61+
message += `\n- ${flag.name}`
62+
if (flag.experimental) {
63+
message += ` · ${chalk.white.bgRed.bold(`EXPERIMENTAL`)}`
64+
}
65+
if (flag.umbrellaIssue) {
66+
message += ` · (${terminalLink(`Umbrella Issue`, flag.umbrellaIssue)})`
67+
}
68+
message += ` · ${flag.description}`
69+
70+
return message
71+
}
72+
5973
let message = ``
6074
// Create message about what flags are active.
6175
if (enabledConfigFlags.length > 0) {
6276
message = `The following flags are active:`
6377
enabledConfigFlags.forEach(flag => {
64-
message += `\n- ${flag.name}`
65-
if (flag.experimental) {
66-
message += ` · ${chalk.white.bgRed.bold(`EXPERIMENTAL`)}`
67-
}
68-
if (flag.umbrellaIssue) {
69-
message += ` · (${terminalLink(`Umbrella Issue`, flag.umbrellaIssue)})`
70-
}
71-
message += ` · ${flag.description}`
78+
message += generateFlagLine(flag)
7279
})
7380

74-
// TODO renable once "gatsby flags` CLI command exists.
75-
// Suggest enabling other flags if they're not trying them all.
76-
// const otherFlagsCount = flags.length - enabledConfigFlags.length
77-
// if (otherFlagsCount > 0) {
78-
// message += `\n\nThere ${
79-
// otherFlagsCount === 1
80-
// ? `is one other flag`
81-
// : `are ${otherFlagsCount} other flags`
82-
// } available you can test — run "gatsby flags" to enable them`
83-
// }
81+
const otherFlagsCount = flags.length - enabledConfigFlags.length
82+
if (otherFlagsCount > 0) {
83+
message += `\n\nThere ${
84+
otherFlagsCount === 1
85+
? `is one other flag`
86+
: `are ${otherFlagsCount} other flags`
87+
} available that you might be interested in:`
88+
89+
const enabledFlagsSet = new Set()
90+
enabledConfigFlags.forEach(f => enabledFlagsSet.add(f.name))
91+
flags.forEach(flag => {
92+
if (!enabledFlagsSet.has(flag.name)) {
93+
message += generateFlagLine(flag)
94+
}
95+
})
96+
}
8497

8598
message += `\n`
8699
}

0 commit comments

Comments
 (0)