Skip to content
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

Es/mapbox token #1148

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ buck-out/
# Private env variables
.env
.bitrise.secrets.yml
env.js

# nodejs-mobile assets generated by build script
# TODO: somehow modify gradle build scripts so that these can be stored in
Expand Down
5 changes: 5 additions & 0 deletions bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ workflows:
inputs:
- npm_version: ""
- command: run build:translations
- [email protected]:
title: Build environment variables
inputs:
- npm_version: ""
- command: run build:env
- [email protected]:
title: Set version name & code
inputs:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"android-no-backend-rebuild": "react-native run-android --variant=appDebug --appIdSuffix=debug",
"android-storybook": "react-native run-android --variant=storybookDebug --appIdSuffix=storybook.debug",
"android-icca": "RN_SRC_EXT=icca react-native run-android --variant=iccaDebug --appIdSuffix=icca.debug",
"build:env": "node ./scripts/build-env.js",
"build:backend": "./scripts/build-backend.sh",
"build:intl-polyfills": "node ./scripts/build-intl-polyfills.js",
"build:translations": "node ./scripts/build-translations.js && npm run build:intl-polyfills",
Expand Down
34 changes: 34 additions & 0 deletions scripts/generate_env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const fs = require("fs");
const path = require("path");

// Path to your .env file
const envPath = path.resolve(__dirname, "../.env");

// Read the contents of the .env file
const envFileContent = fs.readFileSync(envPath, "utf8");

// Split the file contents into lines
const lines = envFileContent.split("\n");

// Create an object to hold the environment variables
const envVariables = {};

// Iterate over each line and set environment variables
lines.forEach(line => {
// Skip empty lines and comments
if (line.trim() !== "" && !line.startsWith("#")) {
// Split the line into key-value pairs
const [key, value] = line.split("=");
// Set the environment variable in the object
envVariables[key.trim()] = value.trim();
}
});

// Convert the object to a string representation
const envString = JSON.stringify(envVariables, null, 4);

// Write the environment variables to a JavaScript file
const outputPath = path.resolve(__dirname, "../env.js");
fs.writeFileSync(outputPath, `export default ${envString};`, "utf8");

console.log("Environment variables injected into env.js");
3 changes: 0 additions & 3 deletions src/config.json

This file was deleted.

4 changes: 2 additions & 2 deletions src/frontend/hooks/useMapAvailability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import MapboxGL from "@react-native-mapbox-gl/maps";

import api from "../api";
import { normalizeStyleURL } from "../lib/mapbox";
import config from "../../config.json";
import env from "../../../env";

/** URL used for map style when no custom map and user is online */
export const onlineStyleURL = normalizeStyleURL(
MapboxGL.StyleURL.Outdoors + "?" + Date.now(),
config.mapboxAccessToken
env.MAPBOX_ACCESS_TOKEN
);

export type MapAvailability = "unknown" | "available" | "unavailable";
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/sharedComponents/Map/MapView.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import type { LocationContextType } from "../../context/LocationContext";
import type { ObservationsMap } from "../../context/ObservationsContext";
import { useIsFullyFocused } from "../../hooks/useIsFullyFocused";
import bugsnag from "../../lib/logger";
import config from "../../../config.json";
import { OfflineMapLayers } from "../OfflineMapLayers";
import { UserLocation } from "./UserLocation";
import env from "../../../../env";

// This is the default zoom used when the map first loads, and also the zoom
// that the map will zoom to if the user clicks the "Locate" button and the
Expand All @@ -38,7 +38,7 @@ Logger.setLogCallback(log => {
);
});

MapboxGL.setAccessToken(config.mapboxAccessToken);
MapboxGL.setAccessToken(env.MAPBOX_ACCESS_TOKEN);
// Forces Mapbox to always be in connected state, rather than reading system
// connectivity state
MapboxGL.setConnected(true);
Expand Down
Loading