Skip to content

Commit

Permalink
fix(build): pass team,site, addons env variables to build command (#1519
Browse files Browse the repository at this point in the history
)
  • Loading branch information
erezrokah authored Nov 4, 2020
1 parent 9292288 commit ba8a7a3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
10 changes: 4 additions & 6 deletions src/commands/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class BuildCommand extends Command {
// Run Netlify Build
async run() {
// Retrieve Netlify Build options
const options = getBuildOptions({
netlify: this.netlify,
const options = await getBuildOptions({
context: this,
token: this.getConfigToken()[0],
flags: this.parse(BuildCommand).flags,
})
Expand All @@ -28,13 +28,11 @@ class BuildCommand extends Command {
checkOptions({ cachedConfig, token }) {
const { siteInfo = {} } = JSON.parse(cachedConfig)
if (!siteInfo.id && process.env.NODE_ENV !== 'test') {
console.error('Could not find the site ID. Please run netlify link.')
this.exit(1)
this.error('Could not find the site ID. Please run netlify link.', { exit: 1 })
}

if (!token) {
console.error('Could not find the access token. Please run netlify login.')
this.exit(1)
this.error('Could not find the access token. Please run netlify login.', { exit: 1 })
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ class DeployCommand extends Command {
}

if (flags.build) {
const options = getBuildOptions({
netlify: this.netlify,
const options = await getBuildOptions({
context: this,
token: this.getConfigToken()[0],
flags,
})
Expand Down
26 changes: 23 additions & 3 deletions src/lib/build.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
const build = require('@netlify/build')

const { getSiteInformation } = require('../utils/dev')

const getBuildEnv = async ({ context }) => {
const { warn, error, netlify } = context
const { site, api } = netlify
const { teamEnv, addonsEnv, siteEnv } = await getSiteInformation({
api,
site,
warn,
error,
})
const env = { ...teamEnv, ...addonsEnv, ...siteEnv }
return env
}

// We have already resolved the configuration using `@netlify/config`
// This is stored as `netlify.cachedConfig` and can be passed to
// `@netlify/build --cachedConfig`.
const getBuildOptions = ({ netlify, token, flags }) => {
const cachedConfig = JSON.stringify(netlify.cachedConfig)
const getBuildOptions = async ({ context, token, flags }) => {
const cachedConfig = JSON.stringify(context.netlify.cachedConfig)
const { dry, debug } = flags
// buffer = true will not stream output
const buffer = flags.json || flags.silent
return { cachedConfig, token, dry, debug, mode: 'cli', telemetry: false, buffer }

const env = await getBuildEnv({
context,
})

return { cachedConfig, token, dry, debug, mode: 'cli', telemetry: false, buffer, env }
}

const runBuild = async (options) => {
Expand Down

0 comments on commit ba8a7a3

Please sign in to comment.