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/recipes

v1.15.26

Published

Executable recipes to setup and extend Amazee Labs projects.

Downloads

153

Readme

Amazee Recipes

Automated recipes for recurring tasks.

Installation

NPM: npm install -g @amazeelabs/recipes

Upgrade

If installed with NPM: npm update -g @amazeelabs/recipes

Usage

If installed with NPM: amazee-recipes

Contributing recipes

Recipes are stored in the recipes directory. Simply add your recipe and create a pull request against silverback-mono.

How to write a recipe

Executing commands

A recipe is a markdown file with typescript codeblocks that are executed when running the recipe. Technically you can import any other library and execute arbitrary Typescript code. To ease things a little, there is a global $$ helper object that gives the recipe access to common tasks like logging, prompts and file management.

Generating files

When a codeblock contains a line that has |-> [filename] in it, it will not execute, but render the content into that file.

This ...

// |-> test.js
console.log('test');

... will write a file called test.js with this content:

console.log('test');

>-> [filename] does the same, but appends the contents to the file instead of overriding it.

Files run through Nunjucks, and it is possible to provide variables and dynamically replace them.

$$.vars({
  file: 'test.js',
  message: 'Hello world!',
});
// |-> {{file}}
console.log('{{message}}');

Outcome in test.js:

console.log('Hello world!');

Helpers API

Run bash commands with $$

Simple shell commands can be run using the $$ function. The recipe will fail if the command returns with a non-zero exit code.

$$('mkdir test');

It is also possible to test for specific exit codes instead. In this case, the recipe will fail if the command does not return exit code 1.

$$('command-that-does-not-exist', {
  code: 1,
});

It is also possible to run assertions against stdout or stderr of a command. The API expects either a regular expression, or a validation function.

$$('echo "foo"', {
  stdout: /foo/,
});

$$('echo "bar"', {
  stdout: (output) => output.length > 2,
});

$$('command-that-does-not-exist', {
  stderr: /not found/,
});

Check versions with $$.minimalVersion

The $$.minimalVersion helper can be combined with $$ to check for minimal versions of the execution environment. It uses the semver package to parse and compare version numbers.

This for example will fail, if no PHP < 7.4 or no PHP at all is available.

$$('php -v', {
  stdout: $$.minimalVersion('7.4'),
});

Working with $$.file

The $$.file helper function provides read, write and modify operations for files. It accepts a file path, and an optional processing function. If the file exists, its content is parsed (depending on the filetype), passed into the processing function, and the output will be written back into the file. If the file does not exist, the input for the processor will be empty, and the file will be created.

*.json, *.yml and *.yaml files are parsed, and the content is passed in as a javascript object. This allows for simple declarative modification of files using spread operators:

$$.file('package.json', (content) => ({
  ...content,
  author: 'AmazeeLabs <[email protected]>',
  scripts: {
    ...content.scripts,
    test: 'jest',
  },
}));

All other files are processed as array of lines.

$$.file('.gitignore', (content) => [...content, 'node_modules']);

Logging

$$.log gives you access to an instance of tslog for pretty logging.

Getting information from the user

$$.prompts is essentially promps, but all promises are resolved synchronously, so you can directly use the users input in the recipe.

// Choose a project name.
const { message } = $$.prompts({
  type: 'text',
  name: 'message',
  message: 'Enter a message:',
});

How to test recipes

Manual testing is possible with pnpm build && LOG=silly node ./dist/index.js my-recipe.