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

@husky-hook-creator/core

v1.0.5

Published

### The library gonna help you to configure all your husky hooks

Downloads

1

Readme

Welcome to @husky-hook-creator/core 👋

The library gonna help you to configure all your husky hooks

Version Prerequisite Documentation Maintenance

🏠 Homepage

Table of Contents

  1. Prerequisites
  2. Install
  3. Getting Started
  4. Features
    1. Commands
      1. Pre install command
      2. Install Husky command
      3. Husky hooks command
      4. Run all command
    2. Runner
      1. ShellJs Runner
      2. custom Runner
  5. Local Development
    1. Install Local Dependencies
    2. Run unit testing
    3. Run coverage unit testing

Prerequisites

  • node >=14.0.0
  • husky >=7.0.2

Install

yarn add @husky-hook-creator/core

Getting Started

This section will help you to install the library on a node project. The following steps use assume you have Node.js >= 14 and Yarn installed.

  1. Create new Node Project

  2. Inside your project run yarn add @husky-hook-creator/core [email protected]

  3. Create a new file called husky-hooks.ts and insert the following code

import { CommandHookFactory, HuskyRunnerFactory } from '@husky-hook-creator/core';

const huskyHook = HuskyRunnerFactory.createShellJsRunner();
await huskyHook
  .addPreInstallCommand('rm -rf .husky')
  .installHusky()
  .addCommand(CommandHookFactory.createHookCommand('pre-commit', 'echo this is a pre-commit hook.'))
  .addCommand(CommandHookFactory.createHookCommand('pre-push', 'echo this is a pre-push hook.'))
  .runAllCommands();

(Optional) ts-node

The library ts-node gonna help us to run the typescript code executing and installing all git hooks from the library.

  1. Install the ts-node executing the command yarn add -D [email protected]
  2. Execute the created script executing the command ts-node yourPath/your-runner.ts

For more details, please check the script named create-hooks-with-custom-executor at package.json.

Features

The husky library uses the concept of pipeline to run all commands in sequence.

Commands

All available commands are:

  1. pre-install-command - Execute all commands before install husky library
  2. install-husky - Install husky library
  3. husky-hooks - Install git hooks using husky library
  4. run-all-commands - Execute all commands

Pre install command

Execute all scripts commands before install the husky library.

Syntax

addPreInstallCommand(scriptCommand: string)

Usage

  1. From an instance of HuskyRunner use the method addPreInstallCommand(scriptCommand: string)
  2. Call runner.addPreInstallCommand('rm -rf library/.husky'); from class HuskyRunner to configure the command.

Full Example

import { CommandHookFactory, HuskyRunnerFactory } from '@husky-hook-creator/core';

const huskyHook = HuskyRunnerFactory.createShellJsRunner();
await huskyHook
  .addPreInstallCommand('rm -rf .husky')
  .addCommand(CommandHookFactory.createHookCommand('pre-push', 'echo this is a pre-push hook.'))
  .runAllCommands();

Install Husky command

Execute the script command to install husky library.

Syntax

installHusky(huskyInstallCommand?: string)

Usage

  1. From an instance of HuskyRunner use the method installHusky(huskyInstallCommand?: string)
  2. Call runner.installHusky(); from class HuskyRunner to install the library.

Full Example

import { CommandHookFactory, HuskyRunnerFactory } from '@husky-hook-creator/core';

const huskyHook = HuskyRunnerFactory.createShellJsRunner();
await huskyHook
  .installHusky()
  .addCommand(CommandHookFactory.createHookCommand('pre-push', 'echo this is a pre-push hook.'))
  .runAllCommands();

If you need to install husky library from a folder that does not contains any .git folder, please check the example in the file.

Husky hooks command

Execute all git hooks commands.

Syntax

addCommand(command: CommandHookInterface)

Usage

  1. From an instance of HuskyRunner use the method addCommand(command: CommandHookInterface)
  2. Call runner.addCommand(command); from class HuskyRunner to create new husky command.

Full Example

import { CommandHookFactory, HuskyRunnerFactory } from '@husky-hook-creator/core';

const huskyHook = HuskyRunnerFactory.createShellJsRunner();
await huskyHook
  .addCommand(CommandHookFactory.createHookCommand('pre-push', 'echo this is a pre-push hook.'))
  .runAllCommands();

Warning: You need to provide valid git hooks when creating new hooks. For more details go to https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks

Run all command

Start core Runner hooks

Usage

  1. From an instance of HuskyRunner use the method runAllCommands())
  2. Call runner.runAllCommands(); from class HuskyRunner to start husky hooks.

Full Example

import { CommandHookFactory, HuskyRunnerFactory } from '@husky-hook-creator/core';

const huskyHook = HuskyRunnerFactory.createShellJsRunner();
await huskyHook
  .addCommand(CommandHookFactory.createHookCommand('pre-push', 'echo this is a pre-push hook.'))
  .runAllCommands();

Runner

All available Runner are:

  1. ShellJsExecutor - Runner that uses shellJs to run all commands
  2. HuskyRunnerInterface - Custom interface to provide your Runner

Shell JS Runner

Default Runner to execute all husky hooks.

Usage

  1. Import all required class import { CommandHookFactory, HuskyRunnerFactory } from '@husky-hook-creator/core';
  2. Call the HuskyRunnerFactory.createShellJsRunner() to create new ShejjJSRunner

Full Example

import { CommandHookFactory, HuskyRunnerFactory } from '@husky-hook-creator/core';

const huskyHook = HuskyRunnerFactory.createShellJsRunner();
await huskyHook
  .addCommand(CommandHookFactory.createHookCommand('pre-push', 'echo this is a pre-push hook.'))
  .runAllCommands();

Custom Runner

The library provides the interface ExecutorInterface.ts that help us to create a custom Runner.

Usage

  1. Create new file that implements the interface ExecutorInterface.ts
  2. Call Runner Factory HuskyRunnerFactory.createCustomRunner(runner:ExecutorInterface);
  3. Execute your husky hooks

Full Example:

File: custom-executor.ts
import { ExecutorInterface } from '@husky-hook-creator/core';
import execa from 'execa';

export class CustomExecutor implements ExecutorInterface {
  public async exec(command: string): Promise<void> {
    const resultCommand = await execa(command, undefined, {
      shell: true,
    });
    console.log(resultCommand.stdout);
  }
}
File: husky-custom-runner.ts
import { CommandHookFactory, HuskyRunnerFactory } from '@husky-hook-creator/core';
import { CustomExecutor } from './custom-executor/execa-executor';

// For more details about git hooks go to https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
(async () => {
  const huskyHook = HuskyRunnerFactory.createCustomRunner(new CustomExecutor());
  await huskyHook
    .addPreInstallCommand('rm -rf .husky')
    .installHusky('cd .. && husky install sample/.husky')
    .addCommand(
      CommandHookFactory.createHookCommand('pre-commit', 'echo your second shell script goes here.'),
    )
    .runAllCommands();
})();

Local Development

In order to create new local features you need to follow some steps as will be shown below.

install-local-dependencies

To install all library dependencies you should execute the follow command.

cd library && yarn

Run unit testing

To execute all unit testing you should execute the follow command.

cd library && yarn test:unit-testing

Run coverage unit testing

To execute all coverage unit testing you should execute the follow command.

cd library && yarn test:unit-testing:coverage

Author

👤 thiago lopes da silva [email protected], kaio monteiro calás da costa [email protected]

Code of Conduct

Feel free to check the code of conduct guide.

Contributing

Contributions, issues and feature requests are welcome!

Feel free to check issues page. You can also take a look at the contributing guide.

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2022 thiago lopes da silva [email protected], kaio monteiro calás da costa [email protected].

This project is Apache License 2.0 licensed.


This README was generated with ❤️ by readme-md-generator