Skip to content

Commit

Permalink
update build logs and README
Browse files Browse the repository at this point in the history
  • Loading branch information
cball committed Apr 12, 2020
1 parent 1801ed6 commit d107a36
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ For the examples above, it would use the values `DATABASE_URL_STAGING`, `DATABAS

# Usage

## Add the plugin

Add a `[[plugins]]` entry to your `netlify.toml` file:

```toml
Expand All @@ -32,3 +34,18 @@ package = 'netlify-plugin-env'
| name | description | default |
| ------ | ------------------------------------------------------------------- | -------- |
| `mode` | The way to append the context or branch name (`prefix` or `suffix`) | `prefix` |

## Update your build command

Update your build command to "source" the `.env` file that gets created for you. **Note: your `.env` should always be in `.gitignore`!** This script writes a temporary .env file for you at build time, so updated values can be used during the build process.

You can do this in `netlify.toml`:

```toml
[build]
command = ". ./.env && yarn build"
```

Or through the Netlify UI if you don't have a `build` section defined in `netlify.toml`:

![image](https://user-images.githubusercontent.com/14339/79069048-45bbd680-7c99-11ea-816b-fec8ee851672.png)
9 changes: 2 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,14 @@ module.exports = {
});

if (replaced.length) {
// Write a file
// Write an env file so we can source it during build
const file = fs.createWriteStream(".env");
replaced.forEach(function (v) {
file.write(`${v}\n`);
});
file.end();

// Call the file
exec("source .env");

// ALternatively, write .env?

console.log(`Replaced ${replaced.length} ENVs`);
console.log(`Replaced ${replaced.length} ENVs and wrote .env file`);
} else {
console.log(`Nothing found... keeping default ENVs`);
}
Expand Down

0 comments on commit d107a36

Please sign in to comment.