Skip to content

Commit

Permalink
add firebase support
Browse files Browse the repository at this point in the history
  • Loading branch information
danstepanov committed Nov 9, 2023
1 parent 4dce8fa commit 3539976
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 1 deletion.
7 changes: 7 additions & 0 deletions cli/src/commands/create-expo-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ const command: GluegunCommand = {
type: 'authentication',
})
}
if (options.firebase) {
// Add firebase package
cliResults.packages.push({
name: 'firebase',
type: 'authentication',
})
}

// Destructure the results but set the projectName if the first param is passed in
if (first) {
Expand Down
5 changes: 5 additions & 0 deletions cli/src/templates/base/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
"react-native-url-polyfill": "^2.0.0",
<% } %>
<% if (props.authenticationPackage?.name === "firebase") { %>
"firebase": "^10.5.2",
"react-native-url-polyfill": "^2.0.0",
<% } %>
"expo": "~49.0.11",
"expo-status-bar": "~1.6.0",
"react": "18.2.0",
Expand Down
8 changes: 8 additions & 0 deletions cli/src/templates/packages/firebase/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
EXPO_PUBLIC_FIREBASE_API_KEY=api_key
EXPO_PUBLIC_FIREBASE_AUTH_DOMAIN=project-id.firebaseapp.com
EXPO_PUBLIC_DATABASE_URL=https://project-id.firebaseio.com
EXPO_PUBLIC_PROJECT_ID=project-id
EXPO_PUBLIC_STORAGE_BUCKET=project-id.appspot.com
EXPO_PUBLIC_MESSAGING_SENDER_ID=sender-id
EXPO_PUBLIC_APP_ID=app-id
EXPO_PUBLIC_MEASUREMENT_ID=G-measurement-id
6 changes: 6 additions & 0 deletions cli/src/templates/packages/firebase/metro.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { getDefaultConfig } = require('@expo/metro-config');

const defaultConfig = getDefaultConfig(import.meta.dir);
defaultConfig.resolver.sourceExts.push('cjs');

module.exports = defaultConfig;
26 changes: 26 additions & 0 deletions cli/src/templates/packages/firebase/utils/firebase.ts.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { initializeApp } from 'firebase/app';

// Optionally import the services that you want to use
// import {...} from "firebase/auth";
// import {...} from "firebase/database";
// import {...} from "firebase/firestore";
// import {...} from "firebase/functions";
// import {...} from "firebase/storage";

// Initialize Firebase
const firebaseConfig = {
apiKey: process.env.EXPO_PUBLIC_FIREBASE_API_KEY,
authDomain: process.env.EXPO_PUBLIC_FIREBASE_AUTH_DOMAIN,
databaseURL: process.env.EXPO_PUBLIC_FIREBASE_DATABASE_URL,
projectId: process.env.EXPO_PUBLIC_PROJECT_ID,
storageBucket: process.env.EXPO_PUBLIC_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.EXPO_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.EXPO_PUBLIC_FIREBASE_APP_ID,
measurementId: process.env.EXPO_PUBLIC_FIREBASE_MEASUREMENT_ID,
};

const firebase = initializeApp(firebaseConfig);
// For more information on how to access Firebase in your project,
// see the Firebase documentation: https://firebase.google.com/docs/web/setup#access-firebase

export default firebase;
11 changes: 11 additions & 0 deletions cli/src/utilities/configureProjectFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,16 @@ export function configureProjectFiles(
files = [...files, ...supabaseFiles];
}

// add supabase files if needed
if (authenticationPackage?.name === 'firebase') {
const firebaseFiles = [
'packages/firebase/utils/firebase.ts.ejs',
'packages/firebase/metro.config.js',
'packages/firebase/.env',
];

files = [...files, ...firebaseFiles];
}

return files
}
4 changes: 4 additions & 0 deletions cli/src/utilities/generateProjectFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export function generateProjectFiles(
target = target.replace('packages/supabase/', '')
}

if (authenticationPackage?.name === 'firebase') {
target = target.replace('packages/firebase/', '')
}

target = target.replace('base/', '')

if (stylingPackage?.name === 'tamagui') {
Expand Down
17 changes: 16 additions & 1 deletion cli/src/utilities/printOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export async function printOutput(
info(``)
highlight('Head over to https://database.new to create a new Supabase project.')
info(``)
highlight(`Get the Project URL and anon key from the API settings.`)
highlight(`Get the Project URL and anon key from the API settings:`)
info(`1. Go to the API settings page in the Dashboard.`)
info(`2. Find your Project URL, anon, and service_role keys on this page.`)
info(`3. Copy these keys and paste them into your .env file.`)
Expand All @@ -80,6 +80,21 @@ export async function printOutput(
info(``)
success(`Once you're done, run the following to get started: `)
info(``)
} else if (cliResults.packages.some((pkg) => pkg.name === 'firebase')) {
success(`Success! 🎉 Now, here's what's next:`)
info(``)
highlight('Head over to https://console.firebase.google.com/ to create a new Firebase project.')
info(``)
highlight(`Get the API key and other unique identifiers:`)
info(`1. Register a web app in your Firebase project:`)
highlight(`https://firebase.google.com/docs/web/setup#register-app`)
info(`2. Find your API key and other identifiers.`)
info(`3. Copy these keys and paste them into your .env file.`)
info(`4. Optionally, follow one of these guides to get started with Firebase:`)
highlight(`https://docs.expo.dev/guides/using-firebase/#next-steps`)
info(``)
success(`Once you're done, run the following to get started: `)
info(``)
} else {
success('Success! 🎉 Now, just run the following to get started: ')
info(``)
Expand Down

0 comments on commit 3539976

Please sign in to comment.