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

jmake

v2.4.1

Published

A simple tool made to easily create and run custom commands for your projects.

Downloads

2,185

Readme

jmake

Purpose

jmake is a simple tool meant to run custom JavaScript functions in an easy way.
By simply providing a Makefile.js file, you will be able to do everything you want.

Installation

Simply run npm i jmake -g to make the jmake command available globally.
Alternatively, you can use npx which is shipped with npm: npx jmake.
This allows you to add jmake as a devDependency and to use npx jmake where you would have used jmake directly.

Usage

The most basic usage is to have a file Makefile.js at the root of your project.
This Makefile.js have to export commands that will be available to jmake.

// Can be executed with `jmake hello`
exports.hello = () => {
    console.log("Hello, World!");
};

You can also return a promise if you need to do asynchronous stuff.

// Can be executed with `jmake asynchronous`
exports.asynchronous = () =>
    new Promise(resolve => resolve("Hello, World!")).then(hello => console.log(hello));

Of course, it works with async/await as well.

const delay = ms =>
    new Promise(resolve => {
        setTimeout(() => {
            resolve();
        }, ms);
    });

// Can be executed with `jmake await`
exports.await = async () => {
    await delay(1000);
    console.log("1s has passed!");
};

You can even get arguments from the command line.

exports.args = (arg1, arg2) => {
    console.log("arg1 -->", arg1);
    console.log("arg2 -->", arg2);
};
// $ jmake args hello world
// > arg1 --> hello
// > arg2 --> world

You can see and try those examples using the demo Makefile example/Makefile.js.

Recursion

jmake allows the user to reuse Makefile.js files.
You can have two Makefile.js with the first extending the second. This means that every command defined in the second will be available as if it were defined in the first.

To do so, the child Makefile.js must export a config object using the JMAKE_CONFIG symbol like so:

const { JMAKE_CONFIG } = require("jmake");

exports[JMAKE_CONFIG] = {
    extends: ["./Makefile_parent.js"],
};

The paths for the extended Makefiles is relative to the Makefile extending it. It can be absolute.

Command resolution

The resolution is a depth-first search meaning that it goes as deep as possible before considering siblings. (Using --help will show you the priority order)

Example

The example/Makefile.js extends example/Makefile_parent.js.

# Show all available commands when executing the child Makefile
$ jmake -f example/Makefile.js --help
info: Available commands (In priority order):
info:
info: /home/telokis/jmake/packages/jmake/example/Makefile.js:
info:  - hello
info:  - await
info:  - error
info:  - args
info:
info:   /home/telokis/jmake/packages/jmake/example/Makefile_parent.js:
info:    - hello
info:    - new
# The "hello" command is defined in both the child and parent but the child takes precedence.
$ jmake -f example/Makefile.js hello
Hello, World!
# The "new" command doesn't exist in the child but is available in the parent.
$ jmake -f example/Makefile.js new
The new command is defined in the parent!
# The parent Makefile can still be used without issue.
$ jmake -f example/Makefile_parent.js hello
This command is overriden by Makefile.js!

Help

Not specifying any command will attempt to find a command named all.

$ jmake
> error: The command 'all' does not exist in your Makefile.

You can recursively list all available commands by passing -h of --help as the command name:

$ jmake -h
info: Available commands (In priority order):
info:
info: /home/telokis/jmake/packages/jmake/example/Makefile.js:
info:  - hello
info:  - await
info:  - error
info:  - args
info:
info:   /home/telokis/jmake/packages/jmake/example/Makefile_parent.js:
info:    - hello
info:    - new

Configuration

If you don't like the default name, you can provide a custom name to replace Makefile.js.
To do so, you just have to add a jmake entry to your package.json:

{
    "jmake": {
        "file": "custom-makefile.js"
    }
}

The package.json must be in the directory in which you run jmake or the script won't be able to find it.

Directly specifying a string for jmake is now deprecated. Use an object with a file property instead.

The path is relative to your package.json.
You can specify an absolute path.

Using the command line

You can also override the file used with the -f <file> or --file <file> argument.
This will take precedence over the entry within your package.json file.

$ jmake hello -f ./subdir/custom-makefile.js
$ jmake --file ./subdir/custom-makefile.js hello

The argument parsing uses minimist meaning you need to use the -- delimiter if you want to pass named arguments to you command.
For example, if you do:

$ jmake hello -- -u --my-arg hello.js

Your hello command will be called with "-u", "--my-arg", "hello.js".

Using as a library

You can use jmake as a library by require-ing it directly.

const jmake = require('jmake');

await jmake({
    command: "hello",
    args: ["arg1", "arg2"],
    file: "./example/Makefile.js"
});

License

MIT License