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

basisjs-tools-config

v1.1.0

Published

Fetch config for basis.js tools

Downloads

605

Readme

NPM version

Adds basis.config support for basisjs-tools commands.

Usage

Module provide single function that extends clap command with basis.config support.

var clap = require('clap');
var configSupport = require('basisjs-tools-config');

var command = clap.create('example');

// extend command
configSupport(command);
// or
command.extend(configSupport);

It adds two options to command:

  • -n, --no-config – to prevent config using
  • -c, --config-file <filename> - to specify path to config file

Also it adds getConfig(options) method to command that search and fetch config content if needed and globalConfig property to get global config content.

getConfig(options) usualy uses in command's init method and could accepts command options to decide is config should be fetched or not.

// this call will search and fetch config content
var config = command.getConfig();

// but this call doesn't
var config = command.getConfig({ config: false });

// specify config location
var config = command.getConfig({ config: 'path/to/my.config' });

If config file doesn't found or could be parsed error outputs in console and exit process.

Searching for config file

Extended command tries to find and use basis.config file by default. It attempts to find basis.config at the current working directory. If it's not found, then it moves to the parent directory, and so on, until the file system root is reached.

Besides basis.config module also check for package.json. Config may be stored with basisjsConfig key. If no basisjsConfig found then package.json ignores and searching is continue.

basis.config

If basis.config found, it's content parses as json. Usualy properties treats as corresponding command options, and could be overridden by options in command line.

Any command's option could be declared in config, as it's long name. All option names should be camelize, i.e. --css-pack becomes cssPack. If flag contains -no-, it should be omited, i.e. --no-color becomes color.

You can disable basis.config usage by --no-config option or specify your own file with -c or --config-file option.

Config file useful to set up command's defaults option values.

Example of basis.config at /path/to/config:

{
  "build": {
    "file": "app.html",
    "output": "build"
  },
  "server": {
    "port": 8123
  }
}

Config also can be stored in package.json:

{
  "basisjsConfig": {
    "build": {
      "file": "app.html",
      "output": "build"
    },
    "server": {
      "port": 8123
    }
  }
}

basis.config has higher priority. Config in package.json ignores if basis.config file exists.

In both cases doesn't matter at what directory you run basis build command, for example. File /path/to/config/app.html will be used for built and result will be put at /path/to/config/output directory. But you still able to override settings in config but using option with command, for example, if you run basis build -o temp at /path/to/config/foo/bar than result will be put at /path/to/config/foo/bar/temp.

Relative path resolving

Basis works with many various paths, and often it is relative paths. There are two general rules for relative path resolving.

  • path defined in config file (basis.config) resolves to config file location
  • path defined in command line resolves to current working directory