MCPcopy
hub / github.com/infinitered/ignite / generateSplashScreen

Function generateSplashScreen

src/tools/generators.ts:846–972  ·  view source on GitHub ↗
(options: {
  androidSize: number
  iosSize: number
  backgroundColor: string
})

Source from the content-addressed store, hash-verified

844 * Generates splash screen for all platforms
845 */
846export async function generateSplashScreen(options: {
847 androidSize: number
848 iosSize: number
849 backgroundColor: string
850}) {
851 const { androidSize, iosSize, backgroundColor } = options || {}
852 const { path, exists, write, find } = filesystem
853 const cwd = process.cwd()
854
855 const inputFilePath = path(templatesDir(), "splash-screen", "logo.png")
856 const expoOutputDirPath = path(cwd, "assets/images")
857 const isExpoOutputDirExists = exists(expoOutputDirPath) === "dir"
858
859 const optionGenerationSuccesses = []
860
861 async function generateForExpo(
862 type: "ios" | "android" | "web" | "all",
863 size: number,
864 expoRules: { name?: string; width: number; height: number; scale: number }[],
865 ) {
866 for (const expoRule of expoRules) {
867 const { name, width, height, scale } = expoRule
868
869 const outputFileName = [`splash-logo`, type, name].filter(Boolean).join("-") + ".png"
870 const outputFilePath = path(expoOutputDirPath, outputFileName)
871 const logoSize = size * scale
872 const verticalPadding = Math.ceil((height - logoSize) / 2)
873 const horizontalPadding = Math.ceil((width - logoSize) / 2)
874
875 try {
876 await sharp(inputFilePath)
877 .resize(logoSize, logoSize, { fit: "fill" })
878 .extend({
879 top: verticalPadding,
880 bottom: verticalPadding,
881 left: horizontalPadding,
882 right: horizontalPadding,
883 background: { r: 0, g: 0, b: 0, alpha: 0 },
884 })
885 .toFile(outputFilePath)
886
887 direction(`✅ assets/images/${outputFileName}`)
888 optionGenerationSuccesses.push(true)
889 } catch (error) {}
890 }
891 }
892
893 heading(`Generating Expo splash screens (Android, iOS, and Web)...`)
894 if (isExpoOutputDirExists) {
895 await generateForExpo("ios", iosSize, [
896 { name: "mobile", width: 1284, height: 2778, scale: 3 },
897 { name: "tablet", width: 2048, height: 2732, scale: 2 },
898 ])
899 await generateForExpo("android", androidSize, [
900 { name: "universal", width: 1440, height: 2560, scale: 4 },
901 ])
902 await generateForExpo("web", 300, [{ width: 1920, height: 1080, scale: 1 }])
903 await generateForExpo("all", 180, [{ width: 1242, height: 2436, scale: 3 }])

Callers 1

generateFunction · 0.90

Calls 9

headingFunction · 0.90
warningFunction · 0.90
linkFunction · 0.90
pFunction · 0.90
directionFunction · 0.90
pathFunction · 0.85
templatesDirFunction · 0.85
generateForExpoFunction · 0.85
igniteCliRootDirFunction · 0.85

Tested by

no test coverage detected