Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@gasket/plugin-metadata

Package Overview
Dependencies
Maintainers
2
Versions
177
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gasket/plugin-metadata

Adds metadata to gasket lifecycles

  • 5.0.0-canary.4
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

@gasket/plugin-metadata

Metadata is the information about the register plugins and presets, available to plugin lifecycle hooks. This data can be used in various was for plugins, most notably the @gasket/plugin-docs which uses it to collate docs for an app.

Installation

This is a default plugin in the Gasket CLI and is always available for use.

Lifecycles

metadata

Describe metadata for a plugin and optionally its supporting modules.

Example

This plugin implements the metadata lifecycle, which plugins can use to modify it's own metadata at runtime. Whatever is returned will replace the existing metadata.

// gasket-plugin-example.js
module.exports = {
  name: 'example',
  hooks: {
    /**
     * @param {Gasket} gasket - The Gasket API
     * @param {PluginData} data - This plugin's initial metadata
     * @returns {Object}
     */
    async metadata(gasket, data) {
      return {
        ...data,
        // adding extra data to this plugin's metadata
        extra: 'information',
        // add metadata for details of this plugin
        lifecycles: [{
          name: 'some-data',
          description: 'Allows plugins to do something with data',
          method: 'exec',
          parent: 'start'
        }],
        // Metadata for these modules will be loaded
        // Declare as strings or objects with additional data
        modules: [
          'left-pad',
          { name: 'right-pad', extra: 'data', link: 'DOC.md' }
        ]
      }
    },
    /**
     * An example lifecycle hook which utilizes metadata
     *
     * @param {Gasket} gasket - The Gasket API
     */
    async example(gasket) {
      const { metadata } = gasket;

      if (metadata.plugins.find(pluginData => pluginData.name === 'gasket-plugin-something')) {
        // only perform some action if a certain plugin is also registered
      }
    }
  }
}

Usage

Beside the lifeycles available to plugins, metadata can also be described for preset and modules.

Presets

Presets can describe additional metadata. This is done by defining a metadata property object on the module, which will get expanded to the PresetData.

// gasket-preset-example.js
module.exports = {
  require,
  metadata: {
    extra: 'information'
  }
}

Modules

Lastly, modules can describe metadata by defining a gasket.metadata property in the package.json which will get expanded to the ModuleData:

{
  "name": "example",
  "version": "1.2.3",
  "gasket": {
    "metadata": {
      "guides": [{
        "name": "Example Guide",
        "description": "How to do something",
        "link": "docs/example.md"
      }]
    }
  }
}

This is especially useful to surface guides with Gasket docs for supporting packages that are intended to be used with Gasket, but are not plugins.

How it works

Metadata begins with the info objects from the Loader of @gasket/resolve and builds data objects for plugins, and presets, and supporting modules. Any functions preset will be redacted, as metadata is not intended to be executed, but rather to is made available to read and inform plugins. This data can be added to, by hooking the metadata lifecycle in a plugin.

Metadata provides insights to a plugin's shape and package information. Additional detail info of plugins can added in the metadata lifecycle, such as what commands, lifecycles, or structures, a plugin provides. The metadata object be accessed in lifecycle hooks from gasket.metadata.

Additionally, ModuleData for all the top-level app's dependencies are loaded by default, and is available from gasket.metadata.app.modules. Plugins can choose to bring in metadata for more modules, or augment what has already been loaded for the app. These, along with the app's modules, will be flattened and available from gasket.metadata.modules.

License

MIT

Keywords

FAQs

Package last updated on 10 Dec 2019

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