Skip to content

Commit

Permalink
fix: properly load env vars in create-fuels template, and add docs …
Browse files Browse the repository at this point in the history
…for fuels CLI (#2051)

* try using dotenv to load env

* try removing dotenv

* fix: properly load env vars in `create-fuels` template, and add docs for fuels CLI

* add fallback values for CI

* also include `.env.local`
  • Loading branch information
Dhaiwat10 committed Apr 15, 2024
1 parent 2ae1f8b commit 40622a5
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-lamps-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fuels": patch
---

fix: properly load env vars in `create-fuels` template, and add docs for fuels CLI
13 changes: 8 additions & 5 deletions apps/create-fuels-counter-guide/fuels.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// #region fuels-config-file-env
import { createConfig } from 'fuels';
import dotenv from 'dotenv';

dotenv.config({
path: ['.env.local', '.env'],
});

export default createConfig({
workspace: './sway-programs',
output: './src/sway-api',
/*
This is the same value as the port specified in the `.env.local` file.
Please keep these values in sync.
*/
fuelCorePort: 4000,
fuelCorePort: +(process.env.NEXT_PUBLIC_FUEL_NODE_PORT as string) || 4000,
});
// #endregion fuels-config-file-env
1 change: 1 addition & 0 deletions apps/create-fuels-counter-guide/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"dependencies": {
"@fuel-wallet/react": "0.15.2",
"dotenv": "^16.4.5",
"fuels": "workspace:*",
"next": "14.0.1",
"react": "^18.2",
Expand Down
22 changes: 22 additions & 0 deletions apps/docs/src/guide/fuels/config-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,25 @@ If `system` binaries are absent, print a warning and use `built-in` ones instead
Check also:

- [Built-in Binaries](./binaries.md)

## Loading environment variables

If you want to load environment variables from a `.env` file, you can use the `dotenv` package.

First, install it:

::: code-group

```sh [pnpm]
pnpm install dotenv
```

```sh [npm]
npm install dotenv
```

:::

Then, you can use it in your `fuels.config.ts` file:

<<< @../../../create-fuels-counter-guide/fuels.config.ts#fuels-config-file-env{ts:line-numbers}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
"compare-versions": "^6.1.0",
"conventional-changelog-angular": "^5.0.13",
"coverage-diff": "^3.2.0",
"dotenv": "^9.0.2",
"eslint": "^8.52.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/fuels/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"dependencies": {
"@fuel-ts/abi-coder": "workspace:*",
"@fuel-ts/abi-typegen": "workspace:*",
"@fuel-ts/account": "workspace:*",
"@fuel-ts/address": "workspace:*",
"@fuel-ts/contract": "workspace:*",
"@fuel-ts/crypto": "workspace:*",
Expand All @@ -58,7 +59,6 @@
"@fuel-ts/transactions": "workspace:*",
"@fuel-ts/utils": "workspace:*",
"@fuel-ts/versions": "workspace:*",
"@fuel-ts/account": "workspace:*",
"bundle-require": "^4.0.1",
"chalk": "4",
"chokidar": "^3.5.3",
Expand Down
21 changes: 9 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions templates/nextjs/fuels.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { createConfig } from 'fuels';
import dotenv from 'dotenv';

dotenv.config({
path: ['.env.local', '.env'],
});

export default createConfig({
workspace: './sway-programs',
output: './src/sway-api',
/*
This is the same value as the port specified in the `.env.local` file.
Please keep these values in sync.
*/
fuelCorePort: 4000,
fuelCorePort: +(process.env.NEXT_PUBLIC_FUEL_NODE_PORT as string) || 4000,
});
1 change: 1 addition & 0 deletions templates/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"dependencies": {
"@fuel-wallet/react": "0.15.2",
"dotenv": "^16.4.5",
"fuels": "workspace:*",
"next": "14.0.1",
"react": "^18.2",
Expand Down

0 comments on commit 40622a5

Please sign in to comment.