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

gpcl

v1.0.1

Published

personal utility for loading project configuration

Downloads

7

Readme

npm Dependency Status Coverage Status Build Status MIT Licence

gpcl

A generic project configuration loader.

There's probably hundreds out there, but the main appeal of this particular one is the ability to invoke it anywhere in your codebase, without needing to specify anything else (like the config file path itself), with certain prerequisites of course.

Installation:

$ yarn add gpcl

Usage:

  1. Add a YAML file to your project directory (see here for default supported locations).
  2. Call loadConfigSync() in your script to access your config object.

Example:

src/backend/web/app/setup.js

import { loadConfigSync } from "gpcl";

const config = loadConfigSync();
// ...

.config/config.yml

IAC:
  Region: !env AWS_REGION
  Stage: !env APP_ENV

  Templates:
    Local: !path lib/blueprints
    BucketKey: infrastructure/blueprints

Development:
  ServerAddr: '0.0.0.0:4200'
  Hateoas: !path .meta/dev/docker_endpoints.json

Output:

{
  "IAC": {
    "Region": "ap-southeast-2",
    "Stage": "staging",
    "Templates": {
      "Local": "/Users/x/DevProjects/xo/lib/blueprints",
      "BucketKey": "infrastructure/blueprints"
    }
  },
  "Development": {
    "ServerAddr": "0.0.0.0:4200",
    "Hateoas": "/Users/x/DevProjects/xo/.meta/dev/docker_endpoints.json"
  }
}

API:

loadConfigSync(configPath?: string, rootDir?: string)

rootDir:

  • absolute path of your root project directory. If not specified, it will walk up the directory tree to find it. Indicators are:
    • package.json
    • node_modules

configPath:

  • absolute path of your config file. If not specified, it will look for your config file in this order (first in <rootDir>, then in <rootDir>/config and vice versa):

    • <rootDir[/.config, /config]>/config.yml
    • <rootDir[/.config, /config]>/project.yml
    • <rootDir[/.config, /config]>/settings.yml

Both params are optional. If you'd like to specify rootDir without specifying configPath, just pass in undefined as the first parameter.

Note: an error will be thrown if both values are not specified AND cannot be inferred.

Supported YAML Types:

Supports anything that is parsable by js-yaml, plus 2 additional custom types:

  1. !env type
    • for referencing an environment variable
    • I.E. process.env[!env]
    • E.G. !env NODE_ENV => 'production'
  2. !path type
    • for referencing a path relative from the root directory
    • I.E. <rootDir>/<!path>
    • E.G. !path src/app.js => /Users/xo/web/src/app.js

Type Definitions:

This comes bundled with its own type definitions for TypeScript, so you'll get auto-complete and hints if you're using the Visual Studio Code IDE.

Todos:

  • [x] complete all tests
  • [x] bump npm package to v1
  • [ ] write and test for Go
  • [ ] generate godocs
  • [ ] set go package version

Remarks

I created this after repetitively copy-pasting the same code across various private side-projects for loading configuration, and it became tedious to use path.resolve(__dirname, '..', '..', '..' /* etc */) on the same config file when calling it from multiple places in the codebase.

If this does not fit your needs, feel free to fork or contribute!