Split up into multiple packages with Lerna

Split up codebase into the packages @clsterio/lib, @clusterio/master,
@clusterio/slave, and @clusterio/ctl using lerna to manage them.  This
will allow deployment to use only the parts needed reducing install
size, and better separate the code into shared library, master, slave
and control.
This commit is contained in:
Hornwitser committed 2020-09-21 18:00:07 +02:00
1 parent 198d5c344b
commit bf5a4a8a9c
133 files changed
+367 -259

No files matched your search

+4 -3
View File
@@ -49,9 +49,10 @@ Message
There's two types of messages currently implemented apart from the
Link builtin close message and that's Request and Event. The builtin
messages are defined in [lib/link/messages.js](../lib/link/messages.js)
and are attached to links via the attachAllMessages function, which is
usally called in the Link subclass constructor.
messages are defined in
[lib/link/messages.js](/package/lib/link/messages.js) and are attached
to links via the attachAllMessages function, which is usally called in
the Link subclass constructor.
The messages define which links they are valid on and only attaches
handlers for those links. There's also a forwarding mechanism for when
+2 -2
View File
@@ -13,8 +13,8 @@ the startup, and the groups and their fields for disabled plugins will
still be created.
The built-in config groups and their fields are defined in
[/lib/config/definitions.js](lib/config/definitions.js) while plugins
can add their own config groups to the `MasterConfigGroup` and
[lib/config/definitions.js](/packages/lib/config/definitions.js) while
plugins can add their own config groups to the `MasterConfigGroup` and
`InstanceConfigGroup` properties of the `info.js` export using
subclasses of `PluginConfigGroup`. The plugin group has the enabled
field pre-defined on it, and it's used to enable/disable plugins.
+14
View File
@@ -11,6 +11,7 @@ Contents
- [Workflow](#workflow)
- [Starting a Feature Branch](#starting-a-feature-branch)
- [Setting up the Development Environment](#setting-up-the-development-environment)
- [Checking your code for errors](#checking-your-code-for-errors)
- [Submitting a Pull Request](#submitting-a-pull-request)
- [Editing your Feature Branch](#editing-your-feature-branch)
@@ -56,6 +57,19 @@ from the main repository. Do not run `git pull upstream` it will mess
thing up!
### Setting up the Development Environment
The project is organized into several packages that are all managed
through Lerna. In order to get the development environment up and
running you will need to run the following commands:
npm install
npx lerna bootstrap
This installs dependencies needed by tests and links the packages up so
they work from the git work tree.
### Starting a Feature Branch
Development is done exclusively in feature branches. This means the
+6 -6
View File
@@ -11,12 +11,12 @@
},
"source": {
"include": [
"master.js",
"slave.js",
"clusterctl.js",
"lib/",
"plugins/",
"routes.js"
"packages/master/src/",
"packages/master/master.js",
"packages/slave/slave.js",
"packages/ctl/clusterctl.js",
"packages/lib/",
"plugins/"
],
"excludePattern": "node_modules"
}
+5 -5
View File
@@ -3,16 +3,16 @@ Managing a Cluster
Clusterio clusers are managed through the master server by using the
`clusterctl` command line interface which is invoked by running
`node clusterctl <command>` in the clusterio directory. This document
uses the shorthand `ctl> foo` to indicate `node clusterctl foo` should
`npx clusterctl <command>` in the clusterio directory. This document
uses the shorthand `ctl> foo` to indicate `npx clusterctl foo` should
be executed. Mandatory parameters are shown in `<angles bracket>` and
optional pameters are in `[square brackets]`.
Before `clusterctl` can be used it needs to be configured for the
cluster it will connect to. The easiest way to do this is to run
`node master bootstrap create-ctl-config <username>` on the master
server, which creates the necessary `config-control.json` for managing
the cluster as the given user.
`npx clusteriomaster bootstrap create-ctl-config <username>` on the
master server, which creates the necessary `config-control.json` for
managing the cluster as the given user.
Slaves
+4 -4
View File
@@ -230,8 +230,8 @@ there's [Requests](#requests). By convention message types ending in
`*_event` are events. The data payload of an event consists solely of
event specific properties.
See [lib/link/messages.js](/lib/link/messages.js) for the recognized
events and their contents.
See [lib/link/messages.js](/packages/lib/link/messages.js) for the
recognized events and their contents.
Requests
@@ -245,8 +245,8 @@ replied to with a corresponding `*_response` message. If an error
occured while processing the request an error response containing an
error property in the data payload is sent instead.
See [lib/link/messages.js](/lib/link/messages.js) for the recognized
requests and their contents.
See [lib/link/messages.js](/packages/lib/link/messages.js) for the
recognized requests and their contents.
### `*_response`
+8 -8
View File
@@ -42,7 +42,7 @@ The basic file structure of a plugin is the following.
The most important file is the `info.js` file. Without it the plugin
will not recognized by Clusterio. Here's an example of it:
const link = require('lib/link'); // For messages
const link = require('@clusterio/lib/link'); // For messages
module.exports = {
name: "foo_frobber",
@@ -129,7 +129,7 @@ The plugin class should derive from its respective base class defined in
`lib/plugin`. For example, to define a MasterPlugin class the following
code can be used:
const plugin = require('lib/plugin');
const plugin = require('@clusterio/lib/plugin');
class MasterPlugin extends plugin.BaseMasterPlugin {
async init() {
@@ -147,7 +147,7 @@ code can be used:
For the instance plugin it's exactly the same except "Master" is
replaced with "Instance", and for the clusterctl plugin "Control" is
used. The available hooks that you can override are documented in the
base class [in lib/plugin.js](../lib/plugin.js).
base class [in lib/plugin.js](/packages/lib/plugin.js).
It's best to avoid defining a constructor, but if you insist on defining
one, forward all arguments to the base class. E.g.:
@@ -173,7 +173,7 @@ take advantage of it by subclassing `PluginConfigGroup`, setting the
and passing it as either `MasterConfigGroup` or `InstanceConfigGroup` in
the `info.js` export. For example in info.js:
const config = require("lib/config");
const config = require("@clusterio/lib/config");
class MasterConfigGroup extends config.PluginConfigGroup { }
MasterConfigGroup.groupName = "foo_frobber";
@@ -550,7 +550,7 @@ from plugins optionally loaded at runtime on different computers.
In its simplest form collecting data from plugins consists of defining
the metric and updating it somewhere in the plugin code. For example:
const { Counter } = require('lib/prometheus');
const { Counter } = require('@clusterio/lib/prometheus');
const fooMetric = new Counter(
'clusterio_foo_frobber_foo_metric', "Measures the level of foo",
@@ -567,7 +567,7 @@ naming scheme.
For metrics that are per-instance, you must define an `instance_id` label and
set it accordingly, for example:
const { Counter } = require('lib/prometheus');
const { Counter } = require('@clusterio/lib/prometheus');
const barMetric = new Gauge(
'clusterio_foo_frobber_bar_metric', "Bar instance level",
@@ -598,7 +598,7 @@ The control entrypoint for plugins allows you to extend clustectl with
your own commands. The creation of custom commands typically starts
with defining a command tree for the plugin:
const { Command, CommandTree } = require("lib/command");
const { Command, CommandTree } = require("@clusterio/lib/command");
const fooFrobberCommands = new CommandTree({
name: "foo-frobber", description: "Foo Frobber Plugin commands"
});
@@ -641,7 +641,7 @@ for how to define the messages that can be sent to the master.
To have the command tree become part of clusterctl it needs to be added
to the rootCommand tree in `addCommands` callback of the Control plugin:
const plugin = require("lib/plugin");
const plugin = require("@clusterio/lib/plugin");
class ControlPlugin extends plugin.BaseControlPlugin {
async addCommands(rootCommand) {