-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from ineshbose/issue/118-setup_ngrok_locally
Dev environment change
- Loading branch information
Showing
23 changed files
with
613 additions
and
387 deletions.
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
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
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -1,9 +1 @@ | ||
declare module 'react-native-dotenv' { | ||
export const DEBUG: boolean; | ||
export const SECRET_KEY: string; | ||
export const ADMINS: string[]; | ||
export const ALLOWED_HOSTS: string[]; | ||
export const API_BASE: string; | ||
export const CLIENT_ID: string; | ||
export const CLIENT_SECRET: string; | ||
} | ||
declare module '*env'; |
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 |
---|---|---|
@@ -1,28 +1,32 @@ | ||
// Learn more https://docs.expo.io/guides/customizing-metro | ||
const { getDefaultConfig } = require('expo/metro-config'); | ||
const path = require('path'); | ||
|
||
const crypto = require('crypto'); | ||
const fs = require('fs'); | ||
const { getDefaultConfig } = require('expo/metro-config'); | ||
const setEnv = require('./set-env'); | ||
|
||
// Find the workspace root, this can be replaced with `find-yarn-workspace-root` | ||
const workspaceRoot = path.resolve(__dirname, '..'); | ||
const projectRoot = __dirname; | ||
module.exports = async () => { | ||
await setEnv.start(); | ||
// Find the workspace root, this can be replaced with `find-yarn-workspace-root` | ||
const workspaceRoot = path.resolve(__dirname, '..'); | ||
const projectRoot = __dirname; | ||
|
||
const config = getDefaultConfig(projectRoot); | ||
const config = getDefaultConfig(projectRoot); | ||
|
||
// Watch all files within the monorepo | ||
config.watchFolders = [workspaceRoot]; | ||
// Let Metro know where to resolve packages, and in what order | ||
config.resolver.nodeModulesPaths = [ | ||
path.resolve(projectRoot, 'node_modules'), | ||
path.resolve(workspaceRoot, 'node_modules'), | ||
]; | ||
// Watch all files within the monorepo | ||
config.watchFolders = [workspaceRoot]; | ||
// Let Metro know where to resolve packages, and in what order | ||
config.resolver.nodeModulesPaths = [ | ||
path.resolve(projectRoot, 'node_modules'), | ||
path.resolve(workspaceRoot, 'node_modules'), | ||
]; | ||
|
||
// Reread env file | ||
let hash = crypto.createHash('sha256'); | ||
hash.update(fs.readFileSync(path.resolve(projectRoot, '.env'))); | ||
config.cacheVersion = hash.digest('hex'); | ||
config.resetCache = true; | ||
// Reread env file | ||
let hash = crypto.createHash('sha256'); | ||
hash.update(fs.readFileSync(path.resolve(projectRoot, '.env'))); | ||
config.cacheVersion = hash.digest('hex'); | ||
config.resetCache = true; | ||
|
||
module.exports = config; | ||
return config; | ||
}; |
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,39 @@ | ||
const fs = require('fs'); | ||
const ngrok = require('ngrok'); | ||
const dotenv = require('dotenv'); | ||
|
||
const getPort = (url) => { | ||
url = (url.match(/^(([a-z]+:)?(\/\/)?[^\/]+).*$/) || ['', ''])[1] || url; | ||
var parts = url.split(':'), | ||
port = parseInt(parts[parts.length - 1], 10); | ||
if (parts[0] === 'http' && (isNaN(port) || parts.length < 3)) { | ||
return 80; | ||
} | ||
if (parts[0] === 'https' && (isNaN(port) || parts.length < 3)) { | ||
return 443; | ||
} | ||
return parts.length === 1 || isNaN(port) ? 80 : port; | ||
}; | ||
|
||
const writeToFile = (envData) => | ||
fs.writeFileSync( | ||
`${__dirname}/env/index.ts`, | ||
`export const {${Object.keys(envData).join(', ')}} = ${JSON.stringify( | ||
envData | ||
)};` | ||
); | ||
|
||
const start = (file = `${__dirname}/.env`) => { | ||
const env = dotenv.parse(fs.readFileSync(file, 'utf-8')); | ||
const port = getPort(env.API_BASE); | ||
if (env.DEBUG.toLowerCase() === 'true' && port) { | ||
ngrok.connect(port).then((value) => { | ||
env.API_BASE = `${value}${env.API_BASE.split(`${port}`)[1]}`; | ||
writeToFile(env); | ||
}); | ||
} else { | ||
writeToFile(env); | ||
} | ||
}; | ||
|
||
module.exports = { start }; |
Oops, something went wrong.