npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gatsby-source-gsheets

v1.0.0

Published

Why go through the hassle of setting up a complicated headless CMS when Google Sheets already has user permissions, revision history, and a powerful UI?

Downloads

3

Readme

gatsby-source-gsheets

Why go through the hassle of setting up a complicated headless CMS when Google Sheets already has user permissions, revision history, and a powerful UI?

This source plugin for Gatsby JS will turn any Google Sheets worksheet into a GraphQL type for build-time consumption.

heads-up!

Until this issue in Gatsby is addressed, when this plugin fails, it will fail silently. Your build will still complete, but the data you were expecting to be available won't be there.

I'll add retry to this plugin eventually, but this is a limitation of Gatsby's build that likely affects all source plugins.

How to:

Step 1: set up sheets/permissions

Follow this tutorial: https://www.twilio.com/blog/2017/03/google-spreadsheets-and-javascriptnode-js.html

...but stop just before the part that says "Read Data from a Spreadsheet with Node.js"

Essentially this creates a Google Sheets API for your project, then shares whichever spreadsheet you're looking to Gatsby-fy with that endpoint.

Step 2: configure your gatsby project

Standard source plugin installation.

yarn add gatsby-source-gsheets


// gatsby-config.js
// ...
{
    resolve: 'gatsby-source-gsheets',
    options: {
        spreadsheetId: 'get this from the sheet url',
        credentials: require('./path-to-credentials-file.json'),
        types: [
          {
            type: 'Event',
            sheet: 'Events',
            map: sheet => ({
              ...sheet,
              venue___NODE: sheet.venue,
            }),
          },
          {
            type: 'Venue',
            sheet: 'Venues',
          },
        ],
    }
},
// ...

The plugin makes the following conversions before feeding Gatsby nodes:

  1. Numbers are converted to numbers. Sheets formats numbers as comma-delineated strings, so to determine if something is a number, the plugin tests to see if the string (a) is non-empty and (b) is composed only of commas, decimals, and digits:
if (
    "value".replace(/[,\.\d]/g, "").length === 0
      && "value" !== ""
   ) {
    ...assume value is a number and handle accordingly
}
  1. "TRUE"/"FALSE" converted to boolean true/false
  2. empty cells ("" in sheets payload) converted to null
  3. Column names are converted to camelcase via lodash _.camelCase() (see note 2 in 'A few notes')

A few notes:

  1. Not tested with cells of data type dates.
  2. Google sheets mangles column names and converts them all to lower case. This plugin will convert them to camelcase, so the best convention here is to name your columns all lowercase with dashes. e.g. instead of "Column Name 1" or "columnName1", prefer "column-name-1"--this last one will be turned into "columnName1" in your GatsbyQL graph.