From 021721d9b279b93e8a026736f7ac5f0620302739 Mon Sep 17 00:00:00 2001 From: Fiore Basile <fiore.basile@gmail.com> Date: Fri, 14 Jun 2019 12:23:52 +0200 Subject: [PATCH] adding .env and firebase init boot script --- .env.example | 6 ++++++ .gitignore | 4 ++-- config/envparser.js | 12 ++++++++++++ package.json | 5 +++-- quasar.conf.js | 3 +++ src/boot/firebase.js | 15 +++++++++++++++ yarn.lock | 5 +++++ 7 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 .env.example create mode 100644 config/envparser.js create mode 100644 src/boot/firebase.js diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..cb8c9cf --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +FIREBASE_API_KEY="" +FIREBASE_AUTH_DOMAIN="" +FIREBASE_DATABASE_URL="" +FIREBASE_PROJECT_ID="" +FIREBASE_STORAGE_BUCKET="" +FIREBASE_MESSAGING_SENDER_ID="" diff --git a/.gitignore b/.gitignore index d7c7a2d..ac907e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ .quasar .DS_Store .thumbs.db -node_modules /dist +node_modules /src-cordova/node_modules /src-cordova/platforms /src-cordova/plugins @@ -10,7 +10,7 @@ node_modules npm-debug.log* yarn-debug.log* yarn-error.log* - +.env # Editor directories and files .idea .vscode diff --git a/config/envparser.js b/config/envparser.js new file mode 100644 index 0000000..87ba78c --- /dev/null +++ b/config/envparser.js @@ -0,0 +1,12 @@ +const DotEnv = require("dotenv"); +const parsedEnv = DotEnv.config().parsed; + +module.exports = function() { + // Let's stringify our variables + for (key in parsedEnv) { + if (typeof parsedEnv[key] === "string") { + parsedEnv[key] = JSON.stringify(parsedEnv[key]); + } + } + return parsedEnv; +}; diff --git a/package.json b/package.json index 8c6e839..a221d07 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "author": "Fiore Basile <fiore.basile@gmail.com>", "private": true, "scripts": { - "start": "quasar serve --history dist/spa", + "start": "quasar serve --history .", "build": "quasar build", "test": "quasar test --unit jest", "test:unit": "jest --updateSnapshot", @@ -27,7 +27,8 @@ "devDependencies": { "@quasar/app": "^1.0.0-beta.0", "@quasar/quasar-app-extension-testing": "^1.0.0-rc.9", - "@quasar/quasar-app-extension-testing-unit-jest": "^1.0.0-beta.24" + "@quasar/quasar-app-extension-testing-unit-jest": "^1.0.0-beta.24", + "dotenv": "^8.0.0" }, "engines": { "node": ">= 8.9.0", diff --git a/quasar.conf.js b/quasar.conf.js index 3d0bcdb..2521c34 100644 --- a/quasar.conf.js +++ b/quasar.conf.js @@ -1,5 +1,7 @@ // Configuration for your app +const envparser = require("./config/envparser"); + module.exports = function(ctx) { return { // app boot file (/src/boot) @@ -70,6 +72,7 @@ module.exports = function(ctx) { build: { scopeHoisting: true, vueRouterMode: "history", + env: envparser(), // vueCompiler: true, // gzip: true, // analyze: true, diff --git a/src/boot/firebase.js b/src/boot/firebase.js new file mode 100644 index 0000000..e580bb6 --- /dev/null +++ b/src/boot/firebase.js @@ -0,0 +1,15 @@ +const firebaseConfig = function() { + return { + apiKey: process.env.FIREBASE_API_KEY, + authDomain: process.env.FIREBASE_AUTH_DOMAIN, + databaseURL: process.env.FIREBASE_DATABASE_URL, + projectId: process.env.FIREBASE_PROJECT_ID, + storageBucket: process.env.FIREBASE_STORAGE_BUCKET, + messagingSenderId: process.env.FIREBASE_MESSAGING_SENDER_ID + }; +}; +import firebase from "firebase"; + +export default async ({ Vue }) => { + firebase.initializeApp(firebaseConfig()); +}; diff --git a/yarn.lock b/yarn.lock index 86a74e1..91788ad 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3531,6 +3531,11 @@ dot-prop@^4.1.1: dependencies: is-obj "^1.0.0" +dotenv@^8.0.0: + version "8.0.0" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.0.0.tgz#ed310c165b4e8a97bb745b0a9d99c31bda566440" + integrity sha512-30xVGqjLjiUOArT4+M5q9sYdvuR4riM6yK9wMcas9Vbp6zZa+ocC9dp6QoftuhTPhFAiLK/0C5Ni2nou/Bk8lg== + download-git-repo@1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/download-git-repo/-/download-git-repo-1.1.0.tgz#7dc88a82ced064b1372a0002f8a3aebf10eb1d3c" -- GitLab