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

@heypal/magnet-cli

v1.0.36

Published

Install:

Downloads

28

Readme

Magnet CLI

Install:

pnpm i -g @heypal/magnet-cli@latest

How to run:

# In your project directory
OPENAI_API_KEY=<key> magnet run

# Also reads OPENAI_API_KEY from .env file if it exists in the directory
magnet run

How to run locally:

pnpm install
pnpm build && pnpm link --global

# Reads OPENAI_API_KEY from .env file if it exists in the directory
magnet run

This creates a .magnet/magnet.json file in the current directory if it doesn't exist already.

Commands

magnet run

Runs the plugins specified in index.ts passed to the run command. So far, we have the following plugins:

  • FilePlugin, which keeps the metadata magnet.json file up to date.
  • LlmPlugin, which generates summary information about a file by passing its contents to OpenAI and whether it's an API route or Webapp Page
  • OpenApiPlugin, which matches on files where llm.isApiRoute=true, passes the file contents to OpenAI to generate an OpenAPI schema that's saved to openaiSchema.json under the file's sub-directory in .magnet

magnet clean

Cleans up the .magnet/magnet.json metadata file.

  • Removes entries for which there is no corresponding file in the root directory (the directory from which magnet clean was called
  • Removes entries which match any of the ignorePatterns
  • Deletes deprecated fields

Plugins

Plugins get passed the full metadata object, which is the entire magnet.json file. They can then choose what to operate on themselves and update the magnet.json file arbitrarily.

Most of the time, the plugin will read files, which should be a map of file paths to file metadata, generated by the built-in FilePlugin. Other plugins are expected to add their output to files[<filepath>][<pluginKey>], so it doesn't conflict with the metadata generated by other plugins.

For example, the init.ts file has the following entry. Notice the LLM Plugin saves its output inside the llm key.

{
  "files": {
    "/Users/dev/magnet-cli/commands/init.ts": {
      "notesPath": "/Users/dev/magnet-cli/.magnet/notes/magnet-cli/commands/init.ts",
      "lastChanged": "2023-08-18T16:05:55.211Z",
      "path": "/Users/dev/magnet-cli/commands/init.ts",
      "llm": {
        "lastAnalyzed": "2023-08-21T00:07:01.257Z",
        "needsAnalysis": false,
        "output": "{\n  \"summary\": \"This file is responsible for initializing the application. It has an 'init' method which is used to log the directory root of the application context.\",\n  \"keywords\": [\"import\", \"zod\", \"BaseCtx\", \"InitCtx\", \"async function\", \"console.log\"],\n  \"description\": \"This script is used to initialize an app using a provided context.\",\n  \"isApiRoute\": false,\n  \"apiRouteDescription\": null,\n  \"isWebappPage\": false,\n  \"webAppPageDescription\": null\n}",
        "summary": "This file is responsible for initializing the application. It has an 'init' method which is used to log the directory root of the application context.",
        "description": "This script is used to initialize an app using a provided context.",
        "keywords": [
          "import",
          "zod",
          "BaseCtx",
          "InitCtx",
          "async function",
          "console.log"
        ],
        "isApiRoute": false,
        "apiRouteDescription": false
      }
    }
  }
}

LLM Plugin

This only runs on files whose llm.lastAnalyzed is null, or llm.needsAnalysis is explicitly set to true, or llm.lastAnalyzed is further in the past than lastChanged.

OpenAI Plugin

This only runs on files whose llm.isApiRoute=true.

Development

New Github releases are published in the publish.yaml workflow. These releases are created when new semver tags are pushed. See the release.yaml workflow.

To bump the version and push a release, run pnpm release:patch.

This builds the project, runs tests, bumps the version number and creates a new commit for the new version, and creates then pushes a new tag for the version number to Github.

It is suggested to title commits according to Conventional Commits, so the release workflow will pick up changes and put them in the changelog.

This means prefixing titles with feat: or fix:, e.g. fix: properly handle timeout errors.

See the full list of prefixes in the changelogithub.js file.

If a commit title isn't prefixed, it will not be picked up.

Example OpenAPI schemas

  • https://apis.guru/

Additional notes

See DEVELOPMENT.md