Skip to content

Commit

Permalink
fix: automatically write env.json with contents from env
Browse files Browse the repository at this point in the history
closes #116
  • Loading branch information
juancarlosfarah committed Jul 2, 2019
1 parent 0dbd5e8 commit 128b276
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ REACT_APP_GRAASP_API_HOST=https://api.graasp.eu
REACT_APP_GRAASP_HOST=https://graasp.eu
REACT_APP_GOOGLE_ANALYTICS_ID=
REACT_APP_SENTRY_DSN=
SENTRY_DSN=
GOOGLE_API_KEY=
BROWSER=none
```
Expand All @@ -60,8 +61,10 @@ you can get [here](https://developers.google.com/maps/documentation/geolocation/
The `BROWSER=none` assignment simply tells Electron not to use a browser to load, but instead to
use the native OS windows.

Currently you also need to create a file in the `public/` folder called `env.json` with the
following contents.
When you first run or build the application, a file called `env.json` will be created under the
`public/` folder. If you update your `.env.local` and `.env` file with values for the variables
below, the contents of this file will also update the next time you run or build. This process is
handled by `scripts/setup.js`.

```json
{
Expand Down
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,27 @@
},
"scripts": {
"dev": "yarn react-scripts start",
"build": "env-cmd ./.env react-scripts build",
"start": "concurrently \"env-cmd ./.env.local react-scripts start\" \"wait-on http://localhost:3000 && env-cmd ./.env.local electron .\"",
"build": "env-cmd -f ./.env react-scripts build",
"start": "concurrently \"env-cmd -f ./.env.local react-scripts start\" \"wait-on http://localhost:3000 && env-cmd -f ./.env.local electron .\"",
"pack": "electron-builder --dir",
"postinstall": "electron-builder install-app-deps",
"prestart": "env-cmd -f ./.env.local node scripts/setup.js",
"prebuild": "env-cmd -f ./.env node scripts/setup.js",
"predist": "yarn build",
"lint": "eslint .",
"prettier:check": "prettier --check '{src,public}/**/*.js'",
"prettier:write": "prettier --write '{src,public}/**/*.js'",
"test": "react-scripts test",
"dist": "env-cmd ./.env electron-builder",
"dist": "env-cmd -f ./.env electron-builder",
"prerelease": "yarn test:once && yarn build",
"release": "git add CHANGELOG.md && standard-version -a && env-cmd ./.env build -mwl",
"release": "git add CHANGELOG.md && standard-version -a && env-cmd -f ./.env build -mwl",
"hooks:uninstall": "node node_modules/husky/husky.js uninstall",
"hooks:install": "node node_modules/husky/husky.js install",
"postrelease": "git push --follow-tags origin master",
"test:once": "cross-env CI=true env-cmd ./.env.test react-scripts test --env=jsdom",
"test:coverage": "cross-env CI=true env-cmd ./.env.test react-scripts test --env=jsdom --coverage",
"test:once": "cross-env CI=true env-cmd -f ./.env.test react-scripts test --env=jsdom",
"test:coverage": "cross-env CI=true env-cmd -f ./.env.test react-scripts test --env=jsdom --coverage",
"test:ci": "run-s test:coverage report",
"report": "cat ./coverage/lcov.info | env-cmd ./.env.test codacy-coverage"
"report": "cat ./coverage/lcov.info | env-cmd -f ./.env.test codacy-coverage"
},
"dependencies": {
"@material-ui/core": "4.1.1",
Expand Down Expand Up @@ -102,7 +104,7 @@
"cross-env": "5.2.0",
"electron": "5.0.3",
"electron-builder": "20.43.0",
"env-cmd": "8.0.2",
"env-cmd": "9.0.3",
"eslint-config-airbnb": "17.1.0",
"eslint-config-prettier": "4.2.0",
"husky": "2.1.0",
Expand Down
14 changes: 14 additions & 0 deletions scripts/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const fs = require('fs');
const path = require('path');

const DEFAULT_PATH = './public/';
const NAME = 'env.json';

const { SENTRY_DSN = '', GOOGLE_API_KEY = '' } = process.env;

const env = JSON.stringify({
SENTRY_DSN,
GOOGLE_API_KEY,
});

fs.writeFileSync(path.join(DEFAULT_PATH, NAME), env, { encoding: 'utf8' });
13 changes: 7 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3558,7 +3558,7 @@ commander@2.17.x:
resolved "https://registry.yarnpkg.com/commander/-/commander-2.17.1.tgz#bd77ab7de6de94205ceacc72f1716d29f20a77bf"
integrity sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg==

commander@^2.11.0, commander@^2.19.0, commander@^2.x, commander@~2.20.0:
commander@^2.0.0, commander@^2.11.0, commander@^2.19.0, commander@^2.x, commander@~2.20.0:
version "2.20.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422"
integrity sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==
Expand Down Expand Up @@ -5139,12 +5139,13 @@ entities@^1.1.1, entities@~1.1.1:
resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.2.tgz#bdfa735299664dfafd34529ed4f8522a275fea56"
integrity sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==

env-cmd@8.0.2:
version "8.0.2"
resolved "https://registry.yarnpkg.com/env-cmd/-/env-cmd-8.0.2.tgz#e3bf53b8e4676781bdc3a0b1a2f7612cbcda4da4"
integrity sha512-gHX8MnQXw1iS7dc2KeJdBdxca7spIkxkNwIuORLwm8kDg6xHh5wWnv1Yv3pc64nLZR6kufQSCmwTz16sRmd/rg==
env-cmd@9.0.3:
version "9.0.3"
resolved "https://registry.yarnpkg.com/env-cmd/-/env-cmd-9.0.3.tgz#b85265f5a9fd4c5fc7d7eff34e341dc28c3f9801"
integrity sha512-DXNeSkLMlYOmq9At+GyvqpdIDuy3gRvz2Z77kN4cAhRbAGVmeiYaqdWqgHSTJ9wCck6ZD0rtbhHVcN7cc2j7rw==
dependencies:
cross-spawn "^6.0.5"
commander "^2.0.0"
cross-spawn "^6.0.0"

env-paths@^1.0.0:
version "1.0.0"
Expand Down

0 comments on commit 128b276

Please sign in to comment.