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

sf-extend

v1.5.2

Published

Extend core salesforce cli commands

Downloads

811

Readme

Extend core salesforce cli commands

sf-extend provides a lightweight means of extending the capabilities of core salesforce cli commands. Configure extensions to run before or after any command. Installable to both the sf and sfdx cli applications.

Installation

Add sf-extend to your cli as you would any sfdx or sf plugin:

# sfdx
sfdx plugins:install sf-extend
# sf
sf plugins install sf-extend

Usage

Extending an sfdx or sf (hereafter, "sf", collectively) command is a simple process. You can define which commands to extend (explicit extension) or you can rely on the extension itself to define the commands (implicit extension, see Configuration below). In the latter case you will be prompted to allow/disallow each command the extension is requesting to extend.

# syntax - explicit extension
sfdx <command> --extend <localPathOrNpmPackage> [-g, --global]
# example
sfdx force:source:deploy --extend sf-extend-my-awesome-extension

# syntax - implicit extension
sf extend add <localPathOrNpmPackage> [-g, --global]
# example 
sf extend add sf-extend-my-awesome-extension

where...

  • command is any sf command
  • localPathOrNpmPackage is a relative path to your extension module or the name of a package published to the default npm registry
  • -g, --global declares that the extension will be executed every time the command is run; when this flag is omitted the scope will default to project-level extension

Scope

As shown above, the -g, --global flag adds a global configuration so that the extension will run every time the command(s) are executed. The config file resides in your machine's default XDG config directory (e.g. ~/.config/) as provided by the oclif framework.

When the global option is not provided sf-extend will attempt to locate a package.json file in the current working directory and append the config to it. If the directory is not a valid sfdx project structure, either becuase it has no sfdx-project.json or no package.json file, an error will be thrown.

Building Extensions

An extension is any local module or npm package whose default export is a class extending the SfExtension base class, as such:

// <projectRoot>/generators/app/index.js
const SfExtension = require('sf-extension');
class MyExtension extends SfExtension{
    // your code...
}
module.exports = SfExtension;

Package.json:

"main": "generators/app/index.js"

To get you started quickly, sf-extend includes a generator command that which will scaffold a new extension for you. Run the following from the directory where you want to begin building:

sfdx extend:generate
# or
sf extend generate

The command will ask you a few questions (similar to running force:project:create) to get you started, including which commands and lifecycles (if any) you'd like to configured your extension to attach to.

Extension Architecture

Under the hood sf-extend utilizes the popular Yeomanjs scaffolding library. Salesforce utilizes this as well when you run commands such as sfdx force:project:create and sfdx plugins:generate.

The extension classes you'll create extend the SfExtension class which itself extends the Yeoman Generator class, so all of the outstanding functionality available to you therein is accessible in your class by default.

Make sure to peruse the Yeoman authoring documentation as you begin building your first extension.

Configuration

Extensions can define the commands they wish to extend and whether they should run before or after. Users installing these extensions will be prompted to approve each command requested and the extension will only be configured within the scope provided by the user, i.e. "global" or "project" (default).

The configuration will be append to the user's global config file or project package.json file as such:

{
    //...
    "sf-extend": {
        "before": [ "command:id:0", "...", "command:id:n" ],
        "after": [ "command:id:0", "...", "command:id:n" ]
    }//...
}

Sharing and Finding Extensions

If you'd like to share your awesome creations with the rest of the world simply publish your package to npm using the format sf-extend-<yourExtensionName>.

FAQ

How is an extension different than a plugin?
An sfdx plugin adds additional commands to the base cli that a user must call manually. An sf-extend extension, on the other hand, allows you to automatically execute logic before/after core commands without the need for manual user invocation.

Can I extend custom plugin commands? Absolutely, though the prompts offered by extend:generate command will only list the core and plugin commands of the cli instance on the machine where it is run.