Alfred JS SDK - CLI Development

The Alfred sdk has been packaged before. The way to use it is to manually install the package in the specific workflow js, and then require the corresponding module. The commonly used script filter construction, screening, and quicklook have encapsulated fn, which is easy to use. But there is no CLI support yet. In order to further improve efficiency, the development of CLI can be driven out. Mark it here for a little experience.

Solve pain points

  1. Use the CLI to automatically install the Alfred SDK package
  2. Generate default or specified JS files, and module loading is also built-in at the code level, which does not need to be written manually.

In this way, you only need npx @stacker/alfred-utils init , and then open index.js to write for business.

CLI principle


  1. The commands defined in the bin field in package.json will be automatically installed in the system path environment variable during the package installation stage, and can be used directly after installation.

  2. A single shell or multiple command definitions are supported under bin.

  3. When npx directly uses the package bin, if the bin name is different, there will be differences .

    1. If the command name under bin is the same as the package name, you can use the package name directly when using npx mode, such as npx @stacker/alfred-utils --help, you can find that the command with the same name is executed
      Note that @scope is consistently excluded here, the package name is @stacker/alfred-utils, and the bin command is alfred-utils, which is consistent
    2. If the command under bin is different from the package name, you need to specify the command when using it, such as npx -p @stacker/alfred-utils alfred-utils-test --help
  4. If the package is installed globally, no matter which bin it is, simply enter the bin name to use it.


The CLI helps generate part of the code, and what it does is already scaffolding. The basic principle is the CV sample code, and part of the replacement work is done according to the input parameters.

Write at the End

  1. With this CLI, it will be more efficient to develop workflows in the future.
  2. As long as there is a code layer duplication problem in the future, you only need to continuously enrich the SDK.