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

makhulu

v1.4.0

Published

Simple and parallel Node.js task runner

Downloads

56

Readme

makhulu

Build Status MEAN Module npm version Node.js Version

🦁 Simple and parallel Node.js task runner

  • Parallel, all functions are async
  • Simple, no need to write plugins/wrappers, do everything in plain TypeScript / JavaScript
  • Strongly typed, supports TypeScript out of the box

Installation

yarn add makhulu

A step-by-step example with comments

More examples at https://github.com/mgenware/makhulu-examples

Use terserjs to uglify all .js files in files folder, and merge the results into one file and write it to dist/bundle.js:

/**
 * Prerequisites:
 * Please install the required packages first:
 * `yarn add makhulu terser`
 */
import * as mk from 'makhulu';
import { minify } from 'terser';

(async () => {
  // Select all .js files as initial data list.
  const srcDir = './files/';
  const files = await mk.fs.src(srcDir, '**/*.js');

  // Enable debug output.
  files.verbose = true;

  /**
   * Now the data list is something like:
   * [
   *   {
   *      SrcDir: './files/',
   *      FilePath: 'a.js',
   *    },
   *    {
   *      SrcDir: './files/',
   *      FilePath: 'sub/b/js',
   *    },
   *    ...
   * ]
   */

  // Print out data list file paths using `printsRelativeFile`.
  await files.forEach('Source files', mk.fs.printsRelativeFile);

  // Read file contents, now each data entry contains file contents.
  await files.map('Read files', mk.fs.readToString);
  /**
   * Now the data list is like (note that "Read file" only adds attributes to the data list, all previous attributes are preserved):
   * [
   *   {
   *      SrcDir: './files/',
   *      FilePath: 'a.js',
   *      Content: 'blabla',
   *    },
   *    {
   *      SrcDir: './files/',
   *      FilePath: 'sub/b/js',
   *      Content: 'blabla',
   *    },
   *    ...
   * ]
   */

  // You can change the content to whatever you want, e.g. uglify the content.
  await files.map('Uglify', async (data) => {
    const content = data[mk.fs.FileContent] as string;
    const uglifyRes = await minify(content);
    data[mk.fs.FileContent] = uglifyRes.code;
    return data;
  });
  /**
   * Now the data list is like:
   * [
   *   {
   *      SrcDir: './files/',
   *      FilePath: 'a.js',
   *      Content: 'Uglified content ...',
   *    },
   *    {
   *      SrcDir: './files/',
   *      FilePath: 'sub/b/js',
   *      Content: 'Uglified content ...',
   *    },
   *    ...
   * ]
   */

  // Now let's merge these files into one file.
  // We need to create a new data list.
  await files.reset('Merge files', async (dataList) => {
    // The name of the merged file.
    const destPath = 'bundle.js';
    // Merge contents of all files into a single string.
    let contents = '';
    dataList.forEach((d) => {
      contents += d[mk.fs.FileContent] as string;
    });
    // Create a new `DataObject`.
    const bundleFileObject = {
      [mk.fs.SrcDir]: srcDir,
      [mk.fs.RelativeFile]: destPath,
      [mk.fs.FileContent]: contents,
    };
    return [bundleFileObject];
  });
  /**
   * Now the data list is like:
   * [
   *   {
   *      SrcDir: './files/',
   *      FilePath: 'bundle.js',
   *      Content: 'Merged content',
   *    },
   * ]
   */

  // Call `writeToDirectory` to save the data list to disk, in this case, the `dist/bundle.js` we just created.
  await files.map('Write files', mk.fs.writeToDirectory(`./dist/`));
  await files.forEach('Dest files', mk.fs.printsDestFile);
  /**
   * Now the data list is like:
   * [
   *   {
   *      SrcDir: './dist/',
   *      FilePath: 'bundle.js',
   *      Content: 'Merged content',
   *      DestFilePath: './dist/bundle.js',
   *    },
   * ]
   */
})();

Sample output:

🦁 Job started
> 2 item(s)
[
  { 'file.relative_file': 'a.js', 'file.src_dir': './files/' },
  { 'file.relative_file': 'sub/b.js', 'file.src_dir': './files/' }
]
> Done in 2ms
🦁 Source files
a.js
sub/b.js
[
  { 'file.relative_file': 'a.js', 'file.src_dir': './files/' },
  { 'file.relative_file': 'sub/b.js', 'file.src_dir': './files/' }
]
> Done in 2ms
🦁 Read files
[
  {
    'file.relative_file': 'a.js',
    'file.src_dir': './files/',
    'file.content': '<file contents>'
  },
  {
    'file.relative_file': 'sub/b.js',
    'file.src_dir': './files/',
    'file.content': '<file contents>'
  }
]
> Done in 3ms
🦁 Uglify
[
  {
    'file.relative_file': 'a.js',
    'file.src_dir': './files/',
    'file.content': '<file contents>'
  },
  {
    'file.relative_file': 'sub/b.js',
    'file.src_dir': './files/',
    'file.content': '<file contents>'
  }
]
> Done in 16ms
🦁 Merge files
> 2 --> 1 item(s)
[
  {
    'file.src_dir': './files/',
    'file.relative_file': 'bundle.js',
    'file.content': '<file contents>'
  }
]
> Done in 1ms
🦁 Write files
[
  {
    'file.src_dir': './files/',
    'file.relative_file': 'bundle.js',
    'file.content': '<file contents>',
    'file.dest_file': 'dist/bundle.js'
  }
]
> Done in 4ms
🦁 Dest files
dist\bundle.js
[
  {
    'file.src_dir': './files/',
    'file.relative_file': 'bundle.js',
    'file.content': '<file contents>',
    'file.dest_file': 'dist/bundle.js'
  }
]
> Done in 7ms

Common Errors

File content not found on data object

This happens in writeToDirectory when it gets a null or undefined when calling DataObject.get(FS.FileContent). Possible reasons:

  • You forgot to call readToString, or called readToString without the await keyword before calling writeToDirectory.
  • You accidentally set the data entry value to null or undefined, if you want to write to an empty file, set it to an empty string (''), or if you want to remove this file, use DataList.filter or DataList.reset instead.

Relative path not found on data object

writeToDirectory cannot locate the source path of a file, you forgot to call fs.src before writeToDirectory?