How to use netlify - 10 common examples

To help you get started, we’ve selected a few netlify 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 / addons / auth.js View on Github external
async run() {
    let accessToken = await this.authenticate()
    const { args } = this.parse(AddonsAuthCommand)

    const addonName = args.name

    const siteId = this.netlify.site.id

    if (!siteId) {
      this.log('No site id found, please run inside a site folder or `netlify link`')
      return false
    }

    const site = await this.netlify.api.getSite({ siteId })
    const addons = await getAddons(siteId, accessToken)

    if (typeof addons === 'object' && addons.error) {
      this.log('API Error', addons)
      return false
    }

    // Filter down addons to current args.name
    const currentAddon = addons.find(addon => addon.service_path === `/.netlify/${addonName}`)

    if (!currentAddon || !currentAddon.id) {
      this.log(`Addon ${addonName} doesn't exist for ${site.name}`)
      return false
    }

    if (!currentAddon.auth_url) {
      console.log(`No Admin URL found for the "${addonName} add-on"`)
github netlify / cli / src / commands / addons / create.js View on Github external
const addonName = args.name

    if (!addonName) {
      this.log('Please provide an add-on name to provision')
      this.exit()
    }

    const siteId = site.id

    if (!siteId) {
      this.log('No site id found, please run inside a site folder or `netlify link`')
      return false
    }

    const siteData = await api.getSite({ siteId })
    const addons = await getAddons(siteId, accessToken)

    if (typeof addons === 'object' && addons.error) {
      this.log('API Error', addons)
      return false
    }

    // Filter down addons to current args.name
    const currentAddon = addons.find(addon => addon.service_path === `/.netlify/${addonName}`)

    // GET flags from `raw` data
    const rawFlags = parseRawFlags(raw)

    if (currentAddon && currentAddon.id) {
      this.log(`The "${addonName} add-on" already exists for ${siteData.name}`)
      this.log()
      const cmd = chalk.cyan(`\`netlify addons:config ${addonName}\``)
github netlify / cli / src / commands / addons / update.js View on Github external
async run() {
    const accessToken = await this.authenticate()
    const { args, raw } = this.parse(addonsUpdateCommand)

    const addonName = args.name

    const siteId = this.netlify.site.id

    if (!siteId) {
      this.log('No site id found, please run inside a site folder or `netlify link`')
      return false
    }

    const site = await this.netlify.api.getSite({ siteId })
    // this.log(site)
    const addons = await getAddons(siteId, accessToken)

    if (typeof addons === 'object' && addons.error) {
      this.log('API Error', addons)
      return false
    }

    // Filter down addons to current args.name
    const currentAddon = addons.reduce((acc, current) => {
      if (current.service_path && current.service_path.replace('/.netlify/', '') === addonName) {
        return current
      }
      return {}
    }, addons)

    if (!currentAddon || !currentAddon.id) {
      this.log(`Addon ${addonName} doesnt exist for ${site.name}`)
github netlify / netlify-dev-plugin / src / utils / addons.js View on Github external
module.exports.createSiteAddon = async function(
  accessToken,
  addonName,
  siteId,
  siteData,
  log
) {
  const addons = await getAddons(siteId, accessToken);
  if (typeof addons === "object" && addons.error) {
    log("API Error", addons);
    return false;
  }
  // Filter down addons to current args.name
  const currentAddon = addons.find(
    addon => addon.service_path === `/.netlify/${addonName}`
  );
  const rawFlags = {};

  if (currentAddon && currentAddon.id) {
    log(`The "${addonName} add-on" already exists for ${siteData.name}`);
    // // just exit
    // log()
    // const cmd = chalk.cyan(`\`netlify addons:config ${addonName}\``)
    // log(`- To update this add-on run: ${cmd}`)
github netlify / cli / src / commands / addons / delete.js View on Github external
async run() {
    const accessToken = await this.authenticate()
    const { args, raw } = this.parse(AddonsDeleteCommand)
    const { site } = this.netlify

    const addonName = args.name

    const siteId = site.id

    if (!siteId) {
      this.log('No site id found, please run inside a site folder or `netlify link`')
      return false
    }

    const addons = await getAddons(siteId, accessToken)

    if (typeof addons === 'object' && addons.error) {
      this.log('API Error', addons)
      return false
    }

    // Filter down addons to current args.name
    const currentAddon =
      addons.find(current => current.service_path && current.service_path.replace('/.netlify/', '') === addonName) || {}

    const { force, f } = parseRawFlags(raw)
    if (!force && !f) {
      const { wantsToDelete } = await inquirer.prompt({
        type: 'confirm',
        name: 'wantsToDelete',
        message: `Are you sure you want to delete the ${addonName} add-on? (to skip this prompt, pass a --force flag)`,
github netlify / cli / src / commands / addons / config.js View on Github external
async run() {
    const accessToken = await this.authenticate()
    const { args, raw } = this.parse(AddonsConfigCommand)
    const addonName = args.name
    const siteId = this.netlify.site.id

    if (!siteId) {
      this.log('No site id found, please run inside a site folder or `netlify link`')
      return false
    }

    const site = await this.netlify.api.getSite({ siteId })
    const addons = await getAddons(siteId, accessToken)

    if (typeof addons === 'object' && addons.error) {
      this.log('API Error', addons)
      return false
    }

    // Filter down addons to current args.name
    const currentAddon = addons.find(addon => addon.service_path === `/.netlify/${addonName}`)

    if (!currentAddon || !currentAddon.id) {
      this.log(`Add-on ${addonName} doesn't exist for ${site.name}`)
      this.log(`> Run \`netlify addons:create ${addonName}\` to create an instance for this site`)
      return false
    }

    // TODO update getAddonManifest to https://open-api.netlify.com/#/default/showServiceManifest
github netlify / cli / src / utils / addons.js View on Github external
module.exports.createSiteAddon = async function(accessToken, addonName, siteId, siteData, log) {
  const addons = await getAddons(siteId, accessToken)
  if (typeof addons === 'object' && addons.error) {
    log('API Error', addons)
    return false
  }
  // Filter down addons to current args.name
  const currentAddon = addons.find(addon => addon.service_path === `/.netlify/${addonName}`)
  const rawFlags = {}

  if (currentAddon && currentAddon.id) {
    log(`The "${addonName} add-on" already exists for ${siteData.name}`)
    // // just exit
    // log()
    // const cmd = chalk.cyan(`\`netlify addons:config ${addonName}\``)
    // log(`- To update this add-on run: ${cmd}`)
    // const deleteCmd = chalk.cyan(`\`netlify addons:delete ${addonName}\``)
    // log(`- To remove this add-on run: ${deleteCmd}`)
github netlify / cli / src / commands / addons / list.js View on Github external
async run() {
    const { flags } = this.parse(AddonsListCommand)
    const { api, site } = this.netlify
    const accessToken = await this.authenticate()
    const siteId = site.id

    if (!siteId) {
      this.log('No site id found, please run inside a site folder or `netlify link`')
      return false
    }

    const siteData = await api.getSite({ siteId })

    // TODO update getAddons to https://open-api.netlify.com/#/default/getServices
    const addons = await getAddons(siteId, accessToken)

    // Return json response for piping commands
    if (flags.json) {
      this.logJson(addons)
      return false
    }

    if (!addons || !addons.length) {
      this.log(`No addons currently installed for ${siteData.name}`)
      this.log(`> Run \`netlify addons:create addon-namespace\` to install an addon`)
      return false
    }

    await this.config.runHook('analytics', {
      eventName: 'command',
      payload: {
github netlify / cli / src / commands / addons / create.js View on Github external
async function createSiteAddon({ addonName, settings, accessToken, siteData, error }, logger) {
  let addonResponse
  try {
    // TODO update to https://open-api.netlify.com/#/default/createServiceInstance
    addonResponse = await createAddon(settings, accessToken)
  } catch (e) {
    error(e.message)
  }

  if (addonResponse.code === 404) {
    logger(`No add-on "${addonName}" found. Please double check your add-on name and try again`)
    return false
  }
  logger(`Add-on "${addonName}" created for ${siteData.name}`)
  if (addonResponse.config && addonResponse.config.message) {
    logger()
    logger(`${addonResponse.config.message}`)
  }
  return addonResponse
}
github bukinoshita / netlify-docs / lib / deploy.js View on Github external
return new Promise(async resolve => {
    const access_token = await getToken() // eslint-disable-line camelcase
    const { name } = await getCfg()
    const client = netlify.createClient({ access_token }) // eslint-disable-line camelcase
    const sites = await client.sites()
    const dir = join(process.cwd(), '.netlify-docs/build')
    let pkg = {}
    let newSite = true

    try {
      pkg = await readPackage()
    } catch (err) {}

    const siteName = name || `${pkg.name}-docs`

    await execa.shell(
      'cd .netlify-docs && yarn add react-scripts && yarn build'
    )

    sites.forEach(async site => {