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

sheets_env

v1.0.16

Published

Google sheets powered env management

Downloads

83

Readme

Sheets ENV

Sheets ENV is a tool to download ENV files from google sheets.

Devs will authenticate in a web browser using oauth2 CI will authenticate with service accounts stored as CI secrets CI can also utilise the .env files created at build time

Usage instructions:

  • Create credentials here so google can show the user your company name on the oauth consent screen https://console.cloud.google.com/apis/credentials Press create credentials -> Create OAuth client ID -> Application type iOS -> Choose a random bundleID You should get a Client ID like this **********-**************************.apps.googleusercontent.com

  • From the same credentials page also create a service account. Choose a name and click done. This will allow headless environments such as heroku/github actions to fetch the env without launching a browser and doing oauth. To get the serviceAccountJson click the newly created service account and choose keys tab click add new key JSON.

  • Create a spreadsheet and share with people (keep the spreadsheetid from the url)

  • Share the sheet with the service account's email address ****@oauth-123456.iam.gserviceaccount.com

  • Enable google sheets api so google can bill you if you use the api too much https://console.cloud.google.com/apis/library/sheets.googleapis.com

  • Have an async function that runs before anything else in your program to ensure that .env is present

if (!fs.existsSync('.env')) {
    const clientId = '********-*****.apps.googleusercontent.com'
    const range = 'Sheet1!A1:B'
    const spreadsheetId = '****************'
    const serviceAccount = process.env.GOOGLE_SERVICE_ACCOUNT // for headless environments

    const envObj = await fetchSheetsEnv(range, spreadsheetId, serviceAccount, clientId)
    const envString = jsonToEnv(envObj)
    fs.writeFileSync('.env', envString)
}

require('dotenv').config()


export const jsonToEnv = (envObj) => Object.keys(envObj).map(key => `${key}=${envObj[key]}`).join('\n')
export const tryParse = (json) => {
  try {
    return JSON.parse(json)
  } catch (e) {
    return null
  }
}
  • JSON.stringify the service account json and put it in heroku env
  • heroku escapes the string so you may want to put the key in heroku as a b64. take the json object with '' around it and b64 it.
export const b64ToAscii = (b64) => {
  // First b64 it with -> const b64 = Buffer.from(str).toString('base64')
  try {
    const ascii = JSON.parse(Buffer.from(b64, 'base64').toString('ascii'))
    return ascii
  } catch (error) {
    return undefined
  }
}