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

@amazeelabs/mzx

v1.4.38

Published

Executable markdown recipes.

Downloads

129

Readme

MZX

"Markdown ZX" - A wrapper around ZX that parses and interprets code blocks in markdown files.

Usage

To make things easier, create an alias in your shell configuration:

alias mzx="npx @amazeelabs/mzx"

Now you should be able to run a script with:

mzx run my-tutorial.md

Writing scripts

Typescript blocks

MZX scripts are regular markdown files. Any code blocks in the typescript language will be concatenated to a ZX script and executed.

# Setup instructions

First run this:

```typescript
await $`rm -rf /`;
```

Then do that:

```typescript
await $`echo "goodbye"`;
```

Shell blocks

Blocks that are marked as shell get turned into sequences of ZX shell commands and executed respectively.

# Setup instructions

First run this:

```shell
rm -rf
```

Then do that:

```shell
echo "goodbye"
```

Writing files

To write arbitrary files, one can create a file block in any language and mark it with |-> [target-file] to write the blocks content to that file.

# Setup instructions

Create a configuration file:

```yaml
# |-> config.yml
foo: bar
```

Prompting for input

There is a prompt helper that allows you to ask for user input and directly store the result in an environment variable. Should the variable already exist, the prompt will be skipped, which is useful for automatically running scripts.

Under the hood, it uses the prompts package. Please refer to its documentation for all the ways to inquire for input.

Choose a project name:

```typescript
const projectNameRegex = /^[a-z][a-z\d_]+$/;
const projectNameMessage =
  'Project names must start with a letter ' +
  'and contain lower case letters, numbers and underscores only.';

await prompt('PROJECT_NAME', {
  type: 'text',
  message: 'Choose a project name:',
  validate: (name) =>
    !projectNameRegex.test(name) ? projectNameMessage : true,
});
```

Environment variable interpolation

Environment variables are inherited to scripts and can be set within scripts by writing to process.env. All variables will be inherited to sub-commands and also interpolated into file blocks.

# Project setup

Decide on a project name:

```typescript
process.env.PROJECT_NAME = 'my_project';
```

Create the directory:

```shell
mkdir $PROJECT_NAME
```

Create a config file;

```yaml
# |-> PROJECT_NAME/config.yml
title: 'PROJECT_NAME'
```

Patching files

It is possible to include inline patches as code blocks that modify a given file. To create one of these patches, prepare the old and new version of the file and use the mx diff command and paste the output into a codeblock marked with the diff language.

mx diff original.ts modified.ts | pbcopy
```diff
Index: original.ts
===================================================================
--- original.ts
+++ original.ts
@@ -1,3 +1,4 @@
 const a = 'foo';
 const b = 'bar';
+const c = 'baz';
 console.log(a,b).
```

Programmatically creating or modifying files

There is a file helper function that can create and modify files. It takes the file name as the first argument, and a processor function as the second. The processor function takes the current file content as input and return its new content as output. The shape of input and output depends on the file extension. For .json, .yml and .yaml its objects that will automatically be decoded and encoded, all other files operate on a list of files.

```typescript
file('./package.json', (json) => ({
  ...json,
  scripts: 'vite build',
});
```