README.md
fx-runtime
(runtime)
Description
Wavelet runtime, manages plugins and services. It provides an easy way to find/load plugins in repository.
More about plugin, see Architect.
All plugins are defined in a config file, Wavelet runtime provides several ways to load plugins:
- from a config file
- from an array object
- from a function
- resolve config from repository
Example/Test
Run
node ./test/test.jsnode ./test/testSearchConfig.js
API
runtime.start(dir, config, help)
start application with plugins defined in config
dir [String] your application home path
config [Object] default configurations for plugins or null
help [Object] default help object or null
runtime.resolvePlugins(searchPaths, config, help, options)
resolve plugins from search paths, it returns:
searchPaths [Array of String] where to find your plugins
config [Object] default configurations for plugins or null
help [Object] default help object or null
options [Object]
options.binding bind service and its plugin implementation
options.apps the top/root level of plugins, defining this array will make the unreferenced plugin removed from plugin resolve process. Only referenced plugins will be loaded.
options.whiteList the white list of plugins
options.blackList the black list of plugins
runtime.help()
print runtime help
Usage
Load plugin config file from a config file.
var runtime = ;var dir = __dirname; // reference dir for config and pluginsvar config = 'your config file, related to your home'; runtimestartdir config { console; console; // TODO: add you options here console;};
You can also pass an array object to as the config
var runtime = ;var dir = __dirname; // reference dir for config and pluginsvar config = packagePath: "plugin A's package path" // other options here packagePath: "plugin B's package path" // other options here ; runtimestartdir config { console; console; // TODO: add you options here console;};
Config argument could be a function too:
var runtime = ;var dir = __dirname; // reference dir for config and pluginsvar { return packagePath: "plugin A's package path" // other options here packagePath: "plugin B's package path" // other options here }; runtimestartdir getConfig { console; console; // TODO: add you options here console;};
Automatically resolve config and help
var runtime = ; var defaultConfig = ; var pluginPaths = __dirname + '/node_modules'; var preDefinedHelp = "--help": "print help" // other help information; var options = "whiteList": // plugin white list, or set it to null "blackList": // plugin black list, or set it to null var plugins = runtime; runtimestart__dirname pluginsconfig { console; console; // TODO: add your options here console; for var i = 0; i < pluginshelplength; i++ console; console;};
Registered global variables
Wavelet runtime registers several global variables, you need to avoid overriding them. All global variables have a prefix underscore _
Variable: _runtimeVersion
[String] The runtime version
Variable: _home
[String] The location where wavelet is installed, _home will be used to locate the config file, the plugins and other resources
Variable: _runtime
[Object] _runtime provides runtime APIs:
_runtime.getService([string] service)
get the instance of service or null if not found. Do not use this api unless you have to. This api breaks the plugin dependencies. Best practice: Depend on a plugin that provides this service.
_runtime.resolvePlugins([array] searchPath, [object] defaultConfig, [object] defaultHelp)
search plugin configurations and help informations in the search path array. The plugin configuration is defined in package.json file as "plugin-config". The plugin arguments is defined in package.json file as "plugin-args". This API returns an object with two properties:
- config: the config of plugins
- help: the argument description of plugins
You can pass config as the second parameter of runtime.start. And print the help out in the third argument of runtime.start
Example of plugin package.json file:
Plugin
Wavelet is based on architect, and provides additional APIs and tools. An architect plugin could be directly used in Wavelet.
service
A plugin could consume services provided from other plugins, and provides services to others.
You can use the online Wavelet service registry to find services and the plugins that implement it.