New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gulp-hooks

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-hooks

Execute injected hooks in the workflow of gulp.

  • 0.0.3
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

logo

Execute injected hooks in the workflow of gulp.

Install

Using pnpm to install:

pnpm add gulp-hooks

Using yarn or npm:

# with yarn
yarn add gulp-hooks

# with npm
npm i gulp-hooks

Usage

Starting from a simple example, if we need to add an updatedAt field to the json to indicate its update time, we can do it like this.

import tapHooks, { registerHooks } from 'gulp-hooks';

registerHooks('compileJSON', (file) => {
  const json = JSON.parse(file.contents.toString());
  json.updatedAt = Date.now();
  file.contents = Buffer.from(JSON.stringify(json));
});

function task() {
  return gulp
    .src('**/*.json')
    .pipe(tapHooks('compileJSON'))
    .pipe(jsonmin())
    .pipe(gulp.dest('dist'));
}

The second argument passed to tapHooks will be received by the hook, and you can pass any value you need.

registerHooks('compileJSON', (file, { version }) => {
  // ...
});

tapHooks('compileJSON', { version: 'v1.0.0' });

Sometimes, we may need to determine whether to execute the hook based on certain condition, which can be done.

registerHooks('compileJSON', {
  condition: ['**/*.json'],
  fn: (file) => {
    // ...
  },
});

registerHooks('compileJSON', {
  condition: (file) => file.extname === '.json',
  fn: (file) => {
    // ...
  },
});

Of course, you can register multiple handlers function for the same hook.

registerHooks('hookName', [
  (file) => {
    // ...
  },
  (file) => {
    // ...
  },
]);

If needed, you can also return a stream.

registerHooks('compileJSON', (file) => {
  return jsonmin();
});

Keywords

FAQs

Package last updated on 07 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc