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

matryoshka.js

v0.2.5

Published

Generate your file like a Matryoshka

Downloads

11

Readme

matryoshka.js

Generate your file like a Matryoshka

What is this?

matryoshka.js is your generator-watcher and generate files on ctx.fs.writeFile call.

  1. run mat to start matryoshka.js
  2. write your generator(under the generators directory) and call ctx.fs.writeFile to create file.
  3. then matryoshka.js generates your file under the dest(/src) directory.

Generator file syntax

minimum generator file will be one default exported function and put that under the generators directory.

See [generators/example.js] for working example.

export default (ctx) => {
  const { filePath, fileName, fs } = ctx
  // simply use ctx.fs.writeFile to write file
  return fs.writeFile(`${filePath}/${fileName}`, 'file content goes here')
}

How it works

matryoshka.js handles File System(fs) event by virtual-fs

virtual-fs queues fs.writeFile call and batch executes fs.writeFile at vfs.perform call.

At vfs.perform we cache writeFile results to detect each file status (created or updated or deleted) and at the end of vfs.perform call, we deletes unnecessary files for keep generated file structure clean with minimum fs operation

vfs will works like a virtual-dom of React!

How to use

# mat --help

  Usage: mat [options]

  watch your generator files and put generated files to dest on file changes :)


  Options:

    -V, --version            output the version number
    -d, --dest <value>       destination directory name `default: src`
    -g, --generator <value>  generator directory name `default: generators`
    -c, --clean <value>      force clean destination directory at first run `default: false`
    -S, --snippets <value>   the snippets to watch and transpile `default: []`
    -s, --single-run         single run (no-watch) `default: false`
    -r, --root <value>       path of root `default: process.cwd()`
    -k, --keep-console       not clear console at each run `default: false`
    -D, --debug              show debug message `default: false`
    -h, --help               output usage information
mat -D -S @subuta/snippets -r /Users/xxx/repositories

Tips

Configuration file (mat.config.js)

mat will use mat.config.js as a configuration if found at working directory. All cli options can be set at configuration file. See cosmiconfig for other configuration file formats(like .json / .yml, if you want)

File watcher

mat will watch generator files by default, If you want to use watchman as a file watcher(instead of default fs.watch) then You can set opts.watchman to true to enable watchman support. See sane for details.

[!EXPERIMENTAL!] Snippets and npm link

When you pass some module name at opts.snippets and , mat will AUTO-MAGICALLY watch(and even transpile!) these files also. You many need to set opts.root to resolve module paths.

If opts.root not works, you may also try use wml instead of npm link ;)

Recipe

  • For generating files into multiple directories you can set dest to ./ and nest your generator code to specific directories.

How to develop

npm i
npm run watch # will start generator-watcher

# run bin with your snippets.
node dist/mat.js -S @subuta/snippets

npm test # will run tests by AVA.