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

vite-plugin-ssam-git

v0.1.2

Published

Create a Git commit through Vite dev server

Downloads

17

Readme

vite-plugin-ssam-git

The purpose of vite-plugin-ssam-git is to help Ssam canvas wrapper and helper create a code and image snapshot at the same time when working on creative coding sketches. Having both snapshots makes it easy to archive and retrieve the work from a particular moment. It may also be used more generally by leveraging the server-client communication.

⚠️ This module is early in its development. Expect breaking changes to come.

Install

npm i -D vite-plugin-ssam-git

How it works

When the plugin is run, it first checks whether git is available on the machine and then checks for whether the project directory is already a git repo or not. If it's not, it will run git init to create a new one.

When ssam:git message is sent to the plugin from a client, the plugin commits to the Git and sends back ssam:git-success message to the client with the commit hash. Ssam then uses this info to export an image with the hash. The plugin sends ssam:log message when git commit is successful, and it sends ssam:warn for errors.

How to use

If you're using Ssam with npm create ssam, this plugin is already set up for you. No need to do anything below.

In your code:

// attach it to a keyboard listener or button, etc.
if (import.meta.hot) {
  import.meta.hot.send("ssam:git", {
    // you can include extra data
    id: 1234,
  });
}

if (import.meta.hot) {
  import.meta.hot.on("ssam:git-success", (data) => {
    // do something with the git commit hash
    saveFile(`${data.hash}.png`);
    // you get back extra data you sent earlier
    console.log(data.id);
  });

  import.meta.hot.on("ssam:log", (data) => {
    console.log(data.msg);
  });

  import.meta.hot.on("ssam:warn", (data) => {
    console.warn(data.msg);
  });
}

Minimum Example

If you want to use this plugin in your own setup, here is a bare minimum example:

In vite.config.js:

import { defineConfig } from "vite";
import { ssamGit } from "vite-plugin-ssam-git";

export default defineConfig({
  plugins: [ssamGit()],
  // ..
});

In your module code:

const canvas = document.createElement("canvas");
canvas.width = canvas.height = 200;
document.body.appendChild(canvas);
const ctx = canvas.getContext("2d");

ctx.fillStyle = `gray`;
ctx.fillRect(0, 0, 200, 200);

window.addEventListener("keydown", (ev) => {
  if (ev.key === "k") {
    if (import.meta.hot) {
      import.meta.hot.send("ssam:git");
    }
  }
});

if (import.meta.hot) {
  import.meta.hot.on("ssam:git-success", (data) =>
    // do something with hash
    console.log(`commit hash:${data.hash}`)
    // if you have some function to save a canvas...
    saveCanvas(canvas, { filename: `${data.hash}.png` })
  );
  import.meta.hot.on("ssam:log", (data) => console.log(data.msg));
  import.meta.hot.on("ssam:warn", (data) => console.warn(data.msg));
}

export {};

Default Options

ssamGit({
  // console logging in browser
  log: true,
});

License

MIT