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 🙏

© 2025 – Pkg Stats / Ryan Hefner

script-file

v0.12.0

Published

script-file maps a npm-script to the exports of a .js file.

Readme

script-file

script-file maps a npm-script to the exports of a .js file.

Installation

npm install script-file

Usage

Create a file scripts/foo.js in your project root

const main = (params) => console.log(`hello ${params.name}`); // Read command line arguments
const foo = 'ls -al'; // A string runs a simple command
const bar = [
    'webpack',
    'python -m SimpleHTTPServer',
]; // An array of string runs on command after another

module.exports = { main, foo, bar };

Add the following to your package.json:

    "scripts": {
        "foo": "script-file --name=script-file",
        "foo:foo": "script-file",
        "foo:bar": "script-file",
        "bar:foo": "script-file-alias foo:bar"
    }

run your scripts, npm run foo, npm run foo:foo, npm run foo:bar, npm run bar:foo

Parameter Usage

Arguments passed to script file are processed by the yargs package. Check the documentation for details on how you can specify the arguments.

API

script-file comes with some build-in utils, which make working with external commands easy.

parallel(...cmds)

Run all passed scripts in parallel.

const {parallel} = require('script-file');

const main = parallel(
    'webpack-dev-server',
    'python -m SimpleHTTPServer'
);

module.exports = { main };

env(string|object) : function

Returns a function which sets environment variables. If you pass in a string it will be set as process.env.NODE_ENV. If you pass an object it takes the key as environment variable and assigns the corresponding value to it.

const main = 'webpack';
const production = [
    env('production'),
    main,
];
const staging = [
    env({NODE_ENV: 'production', HOST: 'staging.service.com'}),
    main,
];

module.exports = { main, production, staging };

spawn(cmd, [options]) : Promise

A slightly more advanced version of child_process.spawn which returns a promise when the process exits. You can optionally pass an options object to wait until the command line prints out a specified string. E.g. {resolve: 'Server is running'}

const {spawn} = require('script-file');
const webdriverio = require('webdriverio');

const options = {
    desiredCapabilities: {
        browserName: 'safari',
        marionette: 'true',
    },
};
const browser = webdriverio.remote(options);

const SELENIUM_STARTED_SIGNIFIER = '35bf4d76-394c-4a0d-b31f-9a2ee2d51bf6';

const captureScreenshot = () => browser.init()
    .url('http://localhost:3000')
    .screenshot()
    .end();

const main = () => spawn('node dev-server.js', { resolve: 'server-running' })
    .then(() => spawn(`webdriver-manager --started-signifier=${SELENIUM_STARTED_SIGNIFIER}`, {resolve: SELENIUM_STARTED_SIGNIFIER, reject: 'run webdriver-manager update'}))
    .then(() => captureScreenshot());

module.exports = { main };

killAll() : Promise

Kills all subprocess which have been spawned. This is useful when you want to quit all running processes on a remote after you executed some commands.

const {spawn, killAll} = require('script-file');

const main () => spawn('node -e "let i = 0; setInterval(() => console.log(i++), 10);"', { resolve: '0' })
    .then(() => killall());

module.exports = { main };