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

@jtbnntt/xmd

v1.6.0

Published

`xmd` (execute Markdown) extracts code snippets from a Markdown document and executes them. In effect, it can be viewed as a tool to run a README file.

Downloads

2

Readme

xmd

xmd (execute Markdown) extracts code snippets from a Markdown document and executes them. In effect, it can be viewed as a tool to run a README file.

The initial use case was automation of a complex project setup. Instead of creating a separate script to execute the steps, the necessary commands were included in the documentation. This made it easy to see the context of each step.

Installation

xmd can be installed globally with npm install -g @jtbnntt/xmd.

Running

To run xmd, just supply the path to the executable Markdown file, e.g.,

xmd README.md

To read from stdin, provide - in place of the filename:

xmd - < README.md

How prepare the Markdown document

The document must contain two types of information:

  1. An execution tree
  2. Named code snippets

The execution tree

The execution tree describe the hierarchy of steps that must run in order to complete the process. Children are considered to be dependencies of their parents, so all child nodes must complete before the parent runs.

The execution tree is created by writing a code block with a language of xmd, like so:

```xmd
parent
  child1
    grandchild1
  child2
  child3
```

Levels of indentation are used to create the hierarchy.

A node may exist for organizational purposes only (that is, not refer to code that should be run) or may refer to a snippet. In the example above, parent might not have its own code, but will not be considered complete until all the children have run.

The longest form for a node uses this format:

<name>: <code-reference> (<command>)

For an organizational node, only the name is necessary. If the name matches a code snippet's name, it will also be considered a code reference. The optional command can be used to control the command used to execute a snippet. Here are some examples of legal lines:

Some node

Some node: some-node

Some Node (/bin/bash)

Some Node: some-node (/bin/bash)

some-node

some-node (/bin/bash)

Environment variables to be supplied to each script may be specified in the form KEY=VALUE.

Code snippets

Code snippets are the blocks of code that should be executed. If a language is specified using the standard Markdown style, it will be used to find the appropriate executor (unless overridden by the command in the execution tree).

Here's an example of a code snippet:

```sh (write-date)
date > date-file
```

Imagine the execution tree looks like this:

```xmd
Write date to file date.txt: write-date
```

When run, an executor registered as sh will be looked up and used to run the script. The sh executor runs /bin/sh.

When running xmd, snippets may be skipped by specifying them with the -s/--skip option. The execution tree below them will be skipped as well.

Executors

Currently, the following type to command mappings exist:

  • sh => /bin/sh
  • js => node

Other commands, if they do not match the type, will need to be specified in the execution tree.

Envisioned improvements

  • Allow a node to reference another part of the tree as a dependency
  • Improve error handling
  • Improve documentation
  • Allow executor mappings to be specified as command line arguments
  • Allow specified nodes to be run

Example

To see the output of this example, run

xmd ./README.md

HEADING_START=This is

This node must wait for its children to complete
  Node using /bin/sh: child1
  Node run as executable file: child2
  Node running file with node: child3 (node)
  Nothing to see here...
    Or here...
      Or here...
echo ==============================================================================
echo $HEADING_START child1 "(sh)"
echo
echo The type sh is mapped to /bin/sh, which is used to run this node.
echo ==============================================================================
#!/usr/bin/env python

import os

print('==============================================================================')
print(os.environ['HEADING_START'] + ' child2 (python)')
print('')
print('This node runs as an executable file and therefore relies on the shebang to')
print('specify the command.')
print('==============================================================================')
console.log('==============================================================================')
console.log(process.env.HEADING_START + ' child3 (node)');
console.log('');
console.log('This node runs with the command set explicitly in the execution tree');
console.log('definition.');
console.log('==============================================================================');