Use dotenv for dev mode customisation

Summary: Allow using of .env file to pass env vars to be used in dev mode. Currently this allow to configure defaults for enabling fast refresh, automatic opening of dev tools and plugins to load.

Reviewed By: passy

Differential Revision: D24398938

fbshipit-source-id: 30a5d86b7906a7723a404cf84a1b8d50ae497dbc
This commit is contained in:
Anton Nikolaev
2020-10-22 11:34:24 -07:00
committed by Facebook GitHub Bot
parent 2d9cf5a905
commit d4debc4185
6 changed files with 9 additions and 2 deletions

1
.gitignore vendored
View File

@@ -6,6 +6,7 @@ bundle.js
bundle.map bundle.map
*.bundle.js *.bundle.js
*.bundle.map *.bundle.map
.env
# conflicts with FB internal infra # conflicts with FB internal infra
.watchmanconfig .watchmanconfig

1
desktop/.gitignore vendored
View File

@@ -5,3 +5,4 @@ node_modules/
/static/defaultPlugins/index.json /static/defaultPlugins/index.json
/app/src/defaultPlugins/index.tsx /app/src/defaultPlugins/index.tsx
/coverage /coverage
.env

View File

@@ -171,6 +171,7 @@
"chalk": "^4.0.0", "chalk": "^4.0.0",
"cross-env": "^7.0.2", "cross-env": "^7.0.2",
"detect-port": "^1.1.1", "detect-port": "^1.1.1",
"dotenv": "^8.2.0",
"electron": "10.1.3", "electron": "10.1.3",
"electron-builder": "^22.8.0", "electron-builder": "^22.8.0",
"eslint": "^7.9.0", "eslint": "^7.9.0",

View File

@@ -25,7 +25,7 @@ export const pluginCacheDir = path.join(flipperDataDir, 'plugins');
export async function getPluginSourceFolders(): Promise<string[]> { export async function getPluginSourceFolders(): Promise<string[]> {
const pluginFolders: string[] = []; const pluginFolders: string[] = [];
if (process.env.FLIPPER_NO_EMBEDDED_PLUGINS === 'true') { if (process.env.FLIPPER_NO_EMBEDDED_PLUGINS) {
console.log( console.log(
'🥫 Skipping embedded plugins because "--no-embedded-plugins" flag provided', '🥫 Skipping embedded plugins because "--no-embedded-plugins" flag provided',
); );

View File

@@ -7,6 +7,7 @@
* @format * @format
*/ */
const dotenv = require('dotenv').config();
const electronBinary: string = require('electron') as any; const electronBinary: string = require('electron') as any;
import codeFrame from '@babel/code-frame'; import codeFrame from '@babel/code-frame';
import socketIo from 'socket.io'; import socketIo from 'socket.io';
@@ -356,5 +357,8 @@ function checkDevServer() {
await startMetroServer(app, server); await startMetroServer(app, server);
outputScreen(socket); outputScreen(socket);
await compileMain(); await compileMain();
if (dotenv && dotenv.parsed) {
console.log('✅ Loaded env vars from .env file: ', dotenv.parsed);
}
shutdownElectron = launchElectron(port); shutdownElectron = launchElectron(port);
})(); })();

View File

@@ -283,7 +283,7 @@ function createWindow() {
}); });
win.once('ready-to-show', () => { win.once('ready-to-show', () => {
win.show(); win.show();
if (argv['open-dev-tools']) { if (argv['open-dev-tools'] || process.env.FLIPPER_OPEN_DEV_TOOLS) {
win.webContents.openDevTools(); win.webContents.openDevTools();
} }
}); });