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

package-script-manager

v1.0.1

Published

package.json scripts with Javascript -- because dynamic configs are better.

Downloads

5

Readme

Package Script Manager

Like package scripts? Dislike that they're in JSON?

psm adds Javascript to your package.json scripts.

Installation

npm install --devDependencies package-script-manager (npm i -D package-script-manager)

Usage

  • Create psm.js as a sibling to package.json. Inside of psm.js, module.exports an object.
  • Migrate all your scripts from package.json to that object in psm.js
  • Warning: psm is destructive. It will replace whatever scripts you have in package.json with the scripts from psm.js. Copy your package.json "scripts" over somewhere safe before proceeding.
  • Run node_modules/.bin/psm
  • psm will copy the scripts from psm.js to package.json, as well as create a couple helper scripts (psm, psm:watch)
  • Do whatever JS stuff you wanted to do in psm.js
  • npm run psm or npm run psm:watch

Contrived Example

Note: static-minifier isn't referencing a real npm package.

// psm.js
const src = 'source'
const minifyable = [
  `${src}/css`,
  `${src}/js`,
  `${src}/img`
]

module.exports = {
  minify: `static-minifier --watch --input-dirs=${minifyable.join(',')} --output-dir=dist`,
  start: `npm-run-all -p minify psm:watch`
}
// package.json
{
  // ...
  "scripts": {
    "minify": "static-minifier --watch --input-dirs=source/css,source/js,source/img --output-dir=dist",
    "start": "npm-run-all -p minify psm:watch",
    "psm": "psm psm.js package.json",
    "psm:watch": "chokidar psm.js -c 'npm run psm'"
  }
  // ...
}

CLI API

For initialization, you'll need to explicitly use node_modules/.bin/psm. This will run psm; migrate scripts from the [input] (psm.js by default) to the [target] (package.json by default); and create a few helper scripts (psm, psm:watch) configured with the same [input] and [target].

  • $ node_modules/.bin/psm [input] [target]
  • $ node_modules/.bin/psm my-cool-scripts.js package.dry-run.json

After psm has been initialized, you can use npm run psm to manually run psm, or npm run psm:watch to migrate scripts on [input] changes.

Why?

I saw a bunch of people saying other task runners were more configurable because they allowed for things like variables. I've ran across this dilemma a few times, but I 💗 CLI, so this plugin quashes those issues.

To be quite honest, I've forgotten what those situations were, but now I can turn to this tool when they rear their ugly heads, and since it's so low-level, it's very extendable with plain Node as well (without needing a plugin-specific API layer like other task runners).

I'm excited to see if the community can come up with good uses for psm. I feel like this might be a cool thing. I'll probably create an org for this and collect plugins there.

Sorry if it's silly and I'm just further polluting the ecosystem. 😐