Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(build): pass team,site, addons env variables to build command #1519

Merged
merged 3 commits into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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