Skip to content

Commit

Permalink
[core] Read .env files when running sanity exec
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Dec 6, 2019
1 parent b554f9e commit 4cd838d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/@sanity/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"configstore": "^3.0.0",
"debug": "^3.1.0",
"deep-sort-object": "^1.0.1",
"dotenv": "^8.2.0",
"es6-promisify": "^6.0.0",
"execa": "^1.0.0",
"filesize": "^3.5.6",
Expand Down
6 changes: 6 additions & 0 deletions packages/@sanity/core/src/actions/exec/execScript.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
const spawn = require('child_process').spawn
const path = require('path')
const dotenv = require('dotenv')
const fse = require('fs-extra')

// Try to load .env files from the current directory
// eslint-disable-next-line no-process-env
const env = process.env.NODE_ENV || 'development'
dotenv.config({path: path.join(process.cwd(), `.env.${env}`)})

module.exports = async args => {
// In case of specifying --with-user-token <file.js>, use the "token" as the script
const script = args.argsWithoutOptions[0] || args.extOptions['with-user-token']
Expand Down

0 comments on commit 4cd838d

Please sign in to comment.