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

@lpha/core

v0.4.12

Published

A simple utility for running tasks in JS projects.

Downloads

35

Readme

@lpha

Purpose

@lpha is a simple utility for running tasks in JS projects. It lets you extract bits of code that are usually part of automation or CI scripting. Possible use cases:

  • SPA app deployment to AWS S3/CloudFront
  • App packaging with Webpack (automatic, without need to create your own Webpack configuration) (see pack-alpha-plugin)

Installation

npm install @lpha/core -D
# or
yarn add @lpha/core -D

Plugins

@lpha itself doesn't do much, as it is just a runner of commands that have to be defined as separate entities. It provides input validation mechanisms (using well-typed io-ts) and utilities for logging and file handling (see below).

Usage

To use an external plugin, install it using yarn or npm. Plugins should have -alpha-plugin package name suffix and they are detected automatically. Follow below syntax to run commands.

# if you installed @lpha globally, you can launch "@" directly:
@ [command-name] [--command-option=...]
# or if you installed locally use npm or yarn:
yarn @ [command-name] [--command-option=...]

All parameters of a command can be set using one of three methods:

  • configuration file (a primary, always available)
  • environmental variables (overrides configuration file, available if variable name has been set by plugin author)
  • command line parameters (overrides env vars, available if variable name has been set by plugin author)

Development

If you'd like to automate a task and create a plugin for that, just use CommandBuilder and ParameterBuilder:

import { CommandBuilder, ParametersBuilder, Types, Logger } from '@lpha/core';

const TAG = 'My Command';

const command = new CommandBuilder()
  .name('my-command')
  .description('command-description')
  .parameters(
    new ParametersBuilder()
      .add('parameterName', {
        type: Types.string(), // Types equals to `T` from `io-ts`
        description: 'Your package type',
        required: true,
        cli: 'parameter-name',
        env: 'PARAMETER_NAME'
      })
      .build(),
  )
  .execute(async ({
    parameterName,
  }) => {
    Logger.log(TAG, 'Executing a task...');
    return await doSomething(parameterName);
  })
  .build();

// You can export the command(s) in many different ways:
export const cmd = command;
module.exports = command;
export default command;
export const commandsArray = [
  command,
];
export default [
  command,
];

@lpha/core package provides promisified utilities for file management:

  • makeDir
  • readFile
  • writeFile
  • copyFile
  • access
  • rename

Documentation of all available commands can be generated automatically to ./docs/commands/ directory after running @ docs or @ self docs. Remember to define the "main" field in your package.json, so that @lpha could pick it up. To run such defined commands, run @ self exported-command-name.

If you'd like to run custom, per-project commands defined i.e. in ./commands/index.js run @ self:commands exported-command-name.

Configuration file

Configuration can be placed directly in package.json, like below:

{
  "@": {
    "command-name": {
      "option": "value",
      "option2": 10
    }
  }
}

You can also place your configuration in a separate js or json file named: @, a, @lpha or alpha. Configuration file name can begin with a dot.