How to use @netlify/config - 8 common examples

To help you get started, we’ve selected a few @netlify/config examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github netlify / cli / src / commands / build / index.js View on Github external
async getConfig() {
    try {
      return await getConfigPath()
    } catch (error) {
      try {
        return await getConfigPath(undefined, this.netlify.site.root)
      } catch (error) {
        console.error(error.message)
        this.exit(1)
      }
    }
  }
}
github netlify / cli / src / commands / build / index.js View on Github external
async getConfig() {
    try {
      return await getConfigPath()
    } catch (error) {
      try {
        return await getConfigPath(undefined, this.netlify.site.root)
      } catch (error) {
        console.error(error.message)
        this.exit(1)
      }
    }
  }
}
github netlify / build / packages / redirects-utils / src / index.js View on Github external
async function getAll(projectPath) {
  const rulesUnique = new Set()

  const configPath = await getConfigPath(undefined, projectPath)
  const redirectsFilePath = path.resolve(projectPath, '_redirects')

  if (fs.existsSync(redirectsFilePath)) {
    const fileName = redirectsFilePath
      .split(path.sep)
      .pop();

    (await parseFile(parseRedirectsFormat, fileName, redirectsFilePath))
      .forEach(r => rulesUnique.add(JSON.stringify(r)))
  }
  if (fs.existsSync(configPath)) {
    const fileName = configPath
      .split(path.sep)
      .pop();

    (await parseFile(parseNetlifyConfig, fileName, configPath))
github netlify / build / packages / build / src / core / config.js View on Github external
const loadConfig = async function({ flags: { config, cwd }, flags: { token = NETLIFY_TOKEN, ...flags } }) {
  logFlags(flags)

  const flagsA = { ...DEFAULT_FLAGS, ...flags }

  const configPath = await getConfigPath(config, cwd)
  logConfigPath(configPath)
  const baseDir = await getBaseDir(configPath)

  try {
    const netlifyConfig = await resolveConfig(configPath, flagsA)
    return { netlifyConfig, configPath, token, baseDir }
  } catch (error) {
    error.message = `Netlify configuration error:\n${error.message}`
    throw error
  }
}
github netlify / build / packages / build / src / core / commands.js View on Github external
const getCommands = function({ pluginsCommands, netlifyConfig }) {
  const commands = EVENTS.flatMap(event => getEventCommands({ event, pluginsCommands, netlifyConfig }))

  const buildCommands = commands.filter(command => !isEndCommand(command) && !isErrorCommand(command))
  const endCommands = commands.filter(isEndCommand)
  const errorCommands = commands.filter(isErrorCommand)

  const mainCommands = [...buildCommands, ...endCommands]
  const commandsCount = mainCommands.length
  return { mainCommands, buildCommands, endCommands, errorCommands, commandsCount }
}
github netlify / build / packages / build / src / core / instructions.js View on Github external
const getInstructions = function({ pluginsHooks, config }) {
  const instructions = LIFECYCLE.flatMap(hook => getHookInstructions({ hook, pluginsHooks, config }))

  const buildInstructions = instructions.filter(
    instruction => !isEndInstruction(instruction) && !isErrorInstruction(instruction),
  )
  const endInstructions = instructions.filter(isEndInstruction)
  const errorInstructions = instructions.filter(isErrorInstruction)

  const mainInstructions = [...buildInstructions, ...endInstructions]
  const instructionsCount = mainInstructions.length
  return { mainInstructions, buildInstructions, endInstructions, errorInstructions, instructionsCount }
}
github netlify / build / packages / build / src / plugins / child / validate.js View on Github external
const validateMethod = function(propName) {
  const propNameA = propName.replace(OVERRIDE_REGEXP, '')

  if (!LIFECYCLE.includes(propNameA) && LEGACY_LIFECYCLE[propNameA] === undefined) {
    throw new Error(`Invalid event '${propNameA}'.
Please use a valid event name. One of:
${serializeList(LIFECYCLE)}`)
  }
}
github netlify / build / packages / build / src / core / config.js View on Github external
const loadConfig = async function({ flags: { config, cwd }, flags: { token = NETLIFY_TOKEN, ...flags } }) {
  logFlags(flags)

  const flagsA = { ...DEFAULT_FLAGS, ...flags }

  const configPath = await getConfigPath(config, cwd)
  logConfigPath(configPath)
  const baseDir = await getBaseDir(configPath)

  try {
    const netlifyConfig = await resolveConfig(configPath, flagsA)
    return { netlifyConfig, configPath, token, baseDir }
  } catch (error) {
    error.message = `Netlify configuration error:\n${error.message}`
    throw error
  }
}