Skip to content

Commit 74867d3

Browse files
committed
feat: load credentials from env file
1 parent e0d99e5 commit 74867d3

File tree

7 files changed

+101
-3
lines changed

7 files changed

+101
-3
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ Cargo.lock
2323
# MSVC Windows builds of rustc generate these, which store debugging information
2424
*.pdb
2525

26-
.vscode
26+
.vscode
27+
.env
28+
*.local

samples/gauge/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
NG_CLIENT_ID=<YOUR_NAVIGRAPH_CLIENT_ID>
2+
NG_CLIENT_SECRET=<YOUR_NAVIGRAPH_CLIENT_SECRET>

samples/gauge/env.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Add secret to global env
2+
3+
declare namespace NodeJS {
4+
interface ProcessEnv {
5+
CLIENT_ID: string
6+
CLIENT_SECRET: string
7+
}
8+
}

samples/gauge/lib/navigraph.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ import { getChartsAPI } from "@navigraph/charts"
55
import { getPackagesAPI } from "@navigraph/packages"
66

77
const config: NavigraphApp = {
8-
clientId: "YOUR_CLIENT_ID",
9-
clientSecret: "YOUR_CLIENT_SECRET",
8+
clientId: process.env.CLIENT_ID,
9+
clientSecret: process.env.CLIENT_SECRET,
1010
scopes: [Scope.FMSDATA],
1111
}
1212

13+
if (!config.clientId || config.clientId.includes("<")) {
14+
alert("Please add your client credentials in lib/navigraph.ts.")
15+
}
16+
1317
initializeApp(config)
1418

1519
// Wait 1s before accessing datastorage

samples/gauge/package-lock.json

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/gauge/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
"@microsoft/msfs-sdk": "^0.6.0",
1818
"@microsoft/msfs-types": "^1.14.6",
1919
"@rollup/plugin-node-resolve": "^15.2.3",
20+
"@rollup/plugin-replace": "^5.0.5",
2021
"@typescript-eslint/eslint-plugin": "^6.9.0",
2122
"@typescript-eslint/parser": "^6.9.0",
2223
"cross-env": "^7.0.3",
24+
"dotenv": "^16.3.1",
2325
"esbuild": "^0.19.5",
2426
"eslint": "^8.52.0",
2527
"eslint-config-prettier": "^9.0.0",

samples/gauge/rollup.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import resolve from "@rollup/plugin-node-resolve"
2+
import replace from "@rollup/plugin-replace"
3+
import dotenv from "dotenv"
24
import copy from "rollup-plugin-copy"
35
import esbuild from "rollup-plugin-esbuild"
46
import css from "rollup-plugin-import-css"
57

8+
dotenv.config()
9+
610
const DEBUG = process.env.DEBUG === "true"
711

812
let outputDest = "../aircraft/PackageSources"
@@ -20,6 +24,10 @@ export default {
2024
css({ output: "MyInstrument.css" }),
2125
resolve(),
2226
esbuild({ target: "es2017" }),
27+
replace({
28+
"process.env.CLIENT_ID": JSON.stringify(process.env.CLIENT_ID),
29+
"process.env.CLIENT_SECRET": JSON.stringify(process.env.CLIENT_SECRET),
30+
}),
2331
copy({
2432
targets: [
2533
{

0 commit comments

Comments
 (0)