-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
frontend: Generate the .env file with versions automatically
- Loading branch information
1 parent
5395e3c
commit fa4a142
Showing
7 changed files
with
77 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
**/node_modules | ||
.git | ||
app | ||
backend/tools/ | ||
docs/ | ||
**/*.stories.* | ||
|
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ on: | |
- 'frontend/**' | ||
- Makefile | ||
- '.github/**' | ||
- Dockerfile | ||
|
||
jobs: | ||
build: | ||
|
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 |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
|
||
# misc | ||
.DS_Store | ||
.env | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
|
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,28 @@ | ||
'use strict'; | ||
|
||
// Creates the .env file | ||
|
||
const fs = require('fs'); | ||
const {execSync} = require('child_process'); | ||
const appInfo = require('../app/package.json'); | ||
|
||
const gitVersion = execSync('git rev-parse HEAD').toString().trim(); | ||
|
||
const envContents = { | ||
REACT_APP_HEADLAMP_VERSION: appInfo.version, | ||
REACT_APP_HEADLAMP_GIT_VERSION: gitVersion, | ||
REACT_APP_HEADLAMP_PRODUCT_NAME: appInfo.productName, | ||
}; | ||
|
||
function createEnvText() { | ||
let text = ''; | ||
Object.entries(envContents).forEach(([key, value]) => { | ||
text += `${key}=${value}\n` | ||
}) | ||
|
||
return text; | ||
} | ||
|
||
const fileName = process.argv[2] || '.env'; | ||
|
||
fs.writeFileSync(fileName, createEnvText()); |
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,35 @@ | ||
const os = require('os'); | ||
const path = require('path'); | ||
const { execSync } = require('child_process'); | ||
const { readFileSync } = require('fs'); | ||
|
||
const envFile = path.join(os.tmpdir(), 'tmpEnv'); | ||
|
||
test('Create & verify', () => { | ||
const execFile = path.resolve(path.join(__dirname, '..', 'make-env.js')); | ||
execSync(`node ${execFile} ${envFile}`); | ||
|
||
const envContents = readFileSync(envFile).toString(); | ||
|
||
const lines = envContents.split(/\r?\n/); | ||
const envObj = {}; | ||
|
||
lines.forEach(line => { | ||
// Skip empty lines | ||
if (!line) { | ||
return; | ||
} | ||
|
||
const [key, val] = line.trim().split('='); | ||
|
||
expect(key.trim()).toBeDefined(); | ||
expect(val.trim()).toBeDefined(); | ||
|
||
envObj[key] = val; | ||
}); | ||
|
||
const keys = Object.keys(envObj); | ||
expect(keys).toContain('REACT_APP_HEADLAMP_VERSION'); | ||
expect(keys).toContain('REACT_APP_HEADLAMP_GIT_VERSION'); | ||
expect(keys).toContain('REACT_APP_HEADLAMP_PRODUCT_NAME'); | ||
}); |