Boost Your Serverless Development with Midway FaaS’s Lightweight Plugin‑Based CLI
Midway FaaS introduces a compact, plugin‑driven CLI that reduces core size by 92%, speeds up execution by 74%, and offers extensible commands, lifecycle hooks, data sharing, and multi‑platform support, all demonstrated with clear code examples and performance benchmarks.
Recently, after validating massive traffic during Double Eleven, we open‑sourced the Serverless framework serving Taobao, Fliggy and other guide‑businesses—Midway FaaS. A crucial part of its development process is the local CLI tool.
Convenient Plugin Mechanism
The CLI maps user commands and parameters to handling logic. Traditionally, developers manually modify the CLI for each new command; with automatic kernel handling, development efficiency improves dramatically.
Below is a simple deploy plugin:
class DeployPlugin {
commands = {
deploy: {
lifecycleEvents: ['copyFiles', 'installDep', 'package', 'deploy'],
options: {
platform: { shortcut: 'p' }
}
}
};
hooks = {
'after:deploy:deploy': () => {}
};
}When a user runs f deploy --platform=fc, the CLI reads the lifecycleEvents from the plugin, executes them in order, and provides options via this.options.p, allowing developers to focus solely on plugin logic.
Lifecycle
The kernel automatically processes user input and locates the corresponding logic. By using lifecycle hooks, developers can extend or modify command behavior for specific platforms.
As illustrated, FC and SCF plugins extend the deploy command:
Hooks are searched across all plugins, enabling multiple plugins to contribute to a single command. This modularity underpins Midway FaaS’s ability to support deployments on Aliyun, Tencent, and other platforms.
Data Sharing
Since each feature is provided by a plugin, a global Core Instance is passed to plugins during mounting, offering getStore and setStore methods for shared data storage and retrieval.
Plugins receive a unique, immutable name; stored data is automatically bound to that name, preventing key collisions. Retrieval via getStore can target specific plugin data, enabling seamless inter‑plugin data sharing.
Extension
Similar to the Serverless framework, the kernel supports custom plugins defined in a YAML file, with a slightly different syntax:
plugins:
- npm::faas-cli-plugin-dashboard
- npm:fc:faas-cli-plugin-debug
- local::./plugin-testPlugins are described using a colon‑separated format type:provider?:path. Two types are supported: npm packages and local files. The optional provider attribute allows platform‑specific loading, e.g., a plugin with provider fc loads only in an Aliyun FC environment.
Performance
Both the core execution and the help command (which loads all plugins) exhibit high performance. Benchmark results are shown below:
This lightweight, easily extensible plugin kernel is open‑source; contributions and stars are welcome.
Repository: https://github.com/midwayjs/midway-faas/
Node Underground
No language is immortal—Node.js isn’t either—but thoughtful reflection is priceless. This underground community for Node.js enthusiasts was started by Taobao’s Front‑End Team (FED) to share our original insights and viewpoints from working with Node.js. Follow us. BTW, we’re hiring.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
