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

shared-scripts

v1.6.0

Published

Shared scripts

Downloads

3,082

Readme

action-release

shared-scripts

Convenience tool to share scripts across multiple repositories.


Inspired by kcd-scripts and eslint's sharable config.


Integrating setup configurations into the codebase comes at a cost: The repositories are splattered with configuration files (eslintrc, jest.config, package.json, etc.).

While this allows to tailor the setup to the needs of the software, it usually leads to copying a bunch of configuration directives. They might be thought through at first, but often enough they end up being just there because "at some point someone considered it necessary and I don't want to change a running system" - and actually maintaining them seems just cumbersome.

We try to keep our code lean, and so we should strive for the same regarding our configurations.


react-scripts and others try to solve this with a 'one-fits-all' approach moving the necessary configuration into this package so that consuming packages end up just with the dependency for react-scripts or similiar. By updating this dependency all embedded configurations are automatically updated too.

kcd-scripts provides an interesting solution working with plugged in configurations but "it's really specific to [the authors] needs".

eslint allows to set up a shared configuration and extending it in multiple repositories of similar needs.


Taking eslint's approach of shareable configurations this package provides the command-line utility to extend/overwrite/wrap other scripts and reuse them across multiple repositories.

Installation

$ yarn add --dev shared-scripts

Usage

Set up a scripts.config.js that exports config like:

module.exports = {
    extends: [
        // reference other configs by require-resolvable names ...
    ],
    scripts: {
        // reference scripts by require-resolvable names ...
        'foo': '@myNamespace/myScriptCollection/foo',
        'echo': __dirname + '/myScript',
        // or define them inline
        'echo': require('./myScript'),
    },
}

Run one of the scripts on the command line:

$ yarn scripts foo

Options

$ yarn scripts --help prints available scripts $ yarn scripts --debug-config displays information about the resolved config $ yarn scripts foo --help prints the options for script foo

Scripts

// ./myScript.js
module.exports = {
    description: 'Example script that echoes its arguments',
    variadicArgs: {
        description: 'Lines',
    },
    run(params) {
        params.variadicArgs.forEach(l => process.stdout.write(`${l}\n`))
    },
}

Options

    options: {
        foo: {
            description: 'Available as --foo flag',
        },
        bar: {
            description: 'Available as --baz and -b flag',
            long: 'baz',
            short: 'b',
        },
        p: {
            description: 'This one is -p followed by two values',
            values: ['x', 'y'],
        },
    },

The script can access the command line options as e.g. params.options.p.x

Arguments

    requiredArgs: [
        {
            id: 'foo',
            description: 'This one is required.',
        },
    ],
    optionalArgs: [
        {
            id: 'bar',
            description: 'This one can be omitted.',
        }
    ],

The script can access the command line arguments as e.g. params.args.foo.

Variadic arguments

    variadicArgs: {
        id: 'extra',
        description: 'This allows more arguments to be passed',
    },

Variadic Arguments are available as params.variadicArgs.

Exit code

If the run function of a script throws the script will exit with either the value of that throw if it is a number - or 2 otherwise.