-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[create-astro] Finalize developer experience... with gradients 🚀 #3313
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
58bcf16
wip: port gradient helpers from sandbox ideas
bholmesdev d5578fd
feat: wire up rocket gradient 🚀
bholmesdev fb4472b
feat: wire up rocket gradient on install step
bholmesdev 859e4b2
refactor: update "next steps" wording
bholmesdev 46670b0
deps: add chalk (for rendering gradient)
bholmesdev a6b2656
chore: changeset
bholmesdev 559992b
chore: clean up sstray template string
bholmesdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'create-astro': patch | ||
--- | ||
|
||
Update "next steps" with more informative text on each CLI command. Oh, and gradients. A lot more gradients. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import chalk from 'chalk'; | ||
import ora from 'ora'; | ||
import type { Ora } from 'ora'; | ||
|
||
const gradientColors = [ | ||
`#ff5e00`, | ||
`#ff4c29`, | ||
`#ff383f`, | ||
`#ff2453`, | ||
`#ff0565`, | ||
`#ff007b`, | ||
`#f5008b`, | ||
`#e6149c`, | ||
`#d629ae`, | ||
`#c238bd`, | ||
]; | ||
|
||
export const rocketAscii = '■■▶'; | ||
|
||
// get a reference to scroll through while loading | ||
// visual representation of what this generates: | ||
// gradientColors: "..xxXX" | ||
// referenceGradient: "..xxXXXXxx....xxXX" | ||
const referenceGradient = [ | ||
...gradientColors, | ||
// draw the reverse of the gradient without | ||
// accidentally mutating the gradient (ugh, reverse()) | ||
...[...gradientColors].reverse(), | ||
...gradientColors, | ||
]; | ||
|
||
// async-friendly setTimeout | ||
const sleep = (time: number) => | ||
new Promise((resolve) => { | ||
setTimeout(resolve, time); | ||
}); | ||
|
||
function getGradientAnimFrames() { | ||
const frames = []; | ||
for (let start = 0; start < gradientColors.length * 2; start++) { | ||
const end = start + gradientColors.length - 1; | ||
frames.push( | ||
referenceGradient | ||
.slice(start, end) | ||
.map((g) => chalk.bgHex(g)(' ')) | ||
.join('') | ||
); | ||
} | ||
return frames; | ||
} | ||
|
||
function getIntroAnimFrames() { | ||
const frames = []; | ||
for (let end = 1; end <= gradientColors.length; end++) { | ||
const leadingSpacesArr = Array.from( | ||
new Array(Math.abs(gradientColors.length - end - 1)), | ||
() => ' ' | ||
); | ||
const gradientArr = gradientColors.slice(0, end).map((g) => chalk.bgHex(g)(' ')); | ||
frames.push([...leadingSpacesArr, ...gradientArr].join('')); | ||
} | ||
return frames; | ||
} | ||
|
||
/** | ||
* Generate loading spinner with rocket flames! | ||
* @param text display text next to rocket | ||
* @returns Ora spinner for running .stop() | ||
*/ | ||
export async function loadWithRocketGradient(text: string): Promise<Ora> { | ||
const frames = getIntroAnimFrames(); | ||
const intro = ora({ | ||
spinner: { | ||
interval: 30, | ||
frames, | ||
}, | ||
text: `${rocketAscii} ${text}`, | ||
}); | ||
intro.start(); | ||
await sleep((frames.length - 1) * intro.interval); | ||
intro.stop(); | ||
const spinner = ora({ | ||
spinner: { | ||
interval: 80, | ||
frames: getGradientAnimFrames(), | ||
}, | ||
text: `${rocketAscii} ${text}`, | ||
}).start(); | ||
|
||
return spinner; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used to render characters by custom hex values for the gradient. This should only add 1-2 KB to the final install size, which was much better than other "gradient generators" on npm. We can also swap out kleur for chalk if we feel really strongly about optimization (kept kleur for consistency with Astro core though)