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

@backkit/autoconf

v0.1.1

Published

Service bootstraper / auto config helper module for backkit node microframework

Downloads

7

Readme

What ?

Service bootstraper / config generator for BackKit

Why ?

BackKit being a microframework, it is configurable and permissive by nature.

  • But do you want to write basic configuration for each module you add to your application ?
  • No you don't !

You obviously want each module to work out of the box with at least a basic configuration.

This module is used by backkit compatible modules as dev dependency to help you generate default configuration or/and customise it with interactive prompts

In early version, this prompts used to be implemented by modules them selves, but it became hard to maintain, read and created a lot of duplicated code across backkit modules, so i created this dependency to make things more maintanable, clean and avoir to repeat myself

Usage example

const nanoid = require('nanoid');
const autoconf = require("@backkit/autoconf");

autoconf('koa')
.generator(self => ([
  {
    putFileOnce: self.serviceConfigMainYML,
    contentYml: self.config
  },
  {
    putFileOnce: self.serviceCodeMainJS,
    content: `module.exports = require('${self.npmModuleName}')`
  },
  {
    putFileOnce: `${self.serviceResourceDir}/.gitkeep`
  }
]))
.default(self => ({
  keys: [nanoid()],
  session: {
    enable: true
  }
}))
.prompt(self => ([
  {
    if: {
      fileNotFound: self.serviceConfigMainYML
    },
    type: 'confirm',
    name: 'session.enable',
    message: "enable session ?",
    default: self.defaultConfig.session.enable,
    validate: function(value) {
      return true;
    }
  }
]))
.run()

Generator commands

putFileOnce

Writes a file if it does not exist, recursively creates parent directories if needed

{
	putFileOnce: "your filename",
	contentYml: "your object to serialize in yml"
},
{
  putFileOnce: "your filename",
  contentJson: "your object to serialize in json"
},
{
  putFileOnce: "your filename",
  content: "raw file content"
},

mkdirp

Recursively create directory if does not exist

{
  mkdirp: "your directory",
  contentYml: "your object to serialize in yml"
},

Prompt conditions

if.fileNotFound

Skips this prompt if condition is met

...
{
  if: {
    fileNotFound: 'your file name'
  },
  ...
  rest of the prompt code
}
...

Prompt syntax

Prompt uses https://www.npmjs.com/package/inquirer v6, check its documentation

Default

default() parameter function should return a default object to use for configuration of this module

Override configuration generation

You can override the way configuration is built. By default it merges defaultConfig with prompt answers, but you might want to implement some custom logic

default bahavior example

autoconf('yourmodule')
...
.answersToConfig((self, answers) => {
  return Object.assign({}, self.defaultConfig, answers);
})
...
run()

add conditional config example

.answersToConfig((self, answers) => {
  // session will need keys
  if (answers.session.enable === true) {
    answers.keys = [nanoid()]
  }
  return Object.assign({}, self.defaultConfig, answers);
})

Attributes of self

// id
serviceName
packageJson
npmModuleName

// root dirs
rootServiceDir
rootConfigDir
rootResourceDir

// service code paths
serviceCodeDir
serviceCodeMainJS

// serfice config paths
serviceConfigDir   // optional
serviceConfigMainYML

// resources
serviceResourceDir

// dynamic stuff
answers
defaultConfig