From bf5a4a8a9ca73a6bef31b022750692fc88570052 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Mon, 21 Sep 2020 16:25:48 +0200 Subject: [PATCH] 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. --- .eslintignore | 1 + .gitignore | 4 +- .travis.yml | 3 +- README.md | 56 +++++++----------- docs/communication.md | 7 ++- docs/config-system.md | 4 +- docs/contributing.md | 14 +++++ docs/jsdoc.json | 12 ++-- docs/maniging-a-cluster.md | 10 ++-- docs/socket.md | 8 +-- docs/writing-plugins.md | 16 ++--- lerna.json | 6 ++ lib/package.json | 5 -- package.json | 55 ++++------------- clusterctl.js => packages/ctl/clusterctl.js | 18 +++--- packages/ctl/package.json | 27 +++++++++ build-mod.js => packages/lib/build_mod.js | 0 {lib => packages/lib}/command.js | 4 +- {lib => packages/lib}/config/classes.js | 2 +- {lib => packages/lib}/config/definitions.js | 0 {lib => packages/lib}/config/index.js | 0 {lib => packages/lib}/database.js | 2 +- {lib => packages/lib}/errors.js | 0 {lib => packages/lib}/factorio/export.js | 2 +- {lib => packages/lib}/factorio/index.js | 6 +- {lib => packages/lib}/factorio/patch.js | 2 +- {lib => packages/lib}/factorio/server.js | 2 +- {lib => packages/lib}/fileOps/fileOps.js | 0 {lib => packages/lib}/fileOps/index.js | 0 {lib => packages/lib}/hash.js | 0 {lib => packages/lib}/helpers.js | 0 {lib => packages/lib}/link/connectors.js | 4 +- {lib => packages/lib}/link/index.js | 6 +- {lib => packages/lib}/link/link.js | 6 +- {lib => packages/lib}/link/messages.js | 4 +- {lib => packages/lib}/luaTools.js | 0 {lib => packages/lib}/objectOps.js | 0 packages/lib/package.json | 26 ++++++++ {lib => packages/lib}/plugin.js | 6 +- {lib => packages/lib}/prometheus.js | 0 {lib => packages/lib}/schema.js | 0 {lib => packages/lib}/users.js | 0 master.js => packages/master/master.js | 31 ++++++---- .../master/npm_post_install.js | 0 packages/master/package.json | 40 +++++++++++++ .../master/src/generate_ssl_cert.js | 2 +- routes.js => packages/master/src/routes.js | 0 .../master/static}/bootstrap.min.css | 0 .../master/static}/browserconfig.xml | 0 .../master/static}/favicon.ico | Bin .../static}/favicon/android-icon-144x144.png | Bin .../static}/favicon/android-icon-192x192.png | Bin .../static}/favicon/android-icon-36x36.png | Bin .../static}/favicon/android-icon-48x48.png | Bin .../static}/favicon/android-icon-72x72.png | Bin .../static}/favicon/android-icon-96x96.png | Bin .../static}/favicon/apple-icon-114x114.png | Bin .../static}/favicon/apple-icon-120x120.png | Bin .../static}/favicon/apple-icon-144x144.png | Bin .../static}/favicon/apple-icon-152x152.png | Bin .../static}/favicon/apple-icon-180x180.png | Bin .../static}/favicon/apple-icon-57x57.png | Bin .../static}/favicon/apple-icon-60x60.png | Bin .../static}/favicon/apple-icon-72x72.png | Bin .../static}/favicon/apple-icon-76x76.png | Bin .../favicon/apple-icon-precomposed.png | Bin .../master/static}/favicon/apple-icon.png | Bin .../master/static}/favicon/browserconfig.xml | 0 .../master/static}/favicon/favicon-16x16.png | Bin .../master/static}/favicon/favicon-32x32.png | Bin .../master/static}/favicon/favicon-96x96.png | Bin .../master/static}/favicon/favicon.ico | Bin .../master/static}/favicon/manifest.json | 0 .../static}/favicon/ms-icon-144x144.png | Bin .../static}/favicon/ms-icon-150x150.png | Bin .../static}/favicon/ms-icon-310x310.png | Bin .../master/static}/favicon/ms-icon-70x70.png | Bin .../master/static}/lib/terminal.js | 0 .../master/static}/lib/utility.js | 0 {static => packages/master/static}/main.js | 0 .../master/static}/manifest.json | 0 .../master/static}/nodeDetails.css | 0 .../master/static}/nodeDetails.js | 0 .../static}/pictures/clusterio_icon.png | Bin .../master/static}/pictures/logo.png | Bin .../master/static}/pictures/unknown-item.png | Bin .../master/static}/settings.js | 0 {static => packages/master/static}/style.css | 0 packages/slave/package.json | 28 +++++++++ slave.js => packages/slave/slave.js | 30 ++++++---- plugins/global_chat/control.js | 4 +- plugins/global_chat/info.js | 4 +- plugins/global_chat/instance.js | 4 +- plugins/research_sync/info.js | 2 +- plugins/research_sync/instance.js | 6 +- plugins/research_sync/master.js | 2 +- plugins/statistics_exporter/info.js | 2 +- plugins/statistics_exporter/instance.js | 4 +- plugins/subspace_storage/dole.js | 2 +- plugins/subspace_storage/info.js | 4 +- plugins/subspace_storage/instance.js | 4 +- plugins/subspace_storage/master.js | 6 +- plugins/subspace_storage/routes.js | 2 +- .../inventoryImports/interfacingFunctions.js | 2 +- .../test/interfacingFunctions.js | 2 +- test/clusterctl.js | 11 +--- test/integration/clusterio.js | 4 +- test/integration/export.js | 2 +- test/integration/index.js | 42 +++++++------ test/integration/patch.js | 2 +- test/integration/server.js | 4 +- test/lib/command.js | 6 +- test/lib/config/classes.js | 2 +- test/lib/database.js | 2 +- test/lib/factorio/export.js | 2 +- test/lib/factorio/patch.js | 2 +- test/lib/factorio/server.js | 2 +- test/lib/fileOps/fileOps.js | 2 +- test/lib/generateSSLcert.js | 2 +- test/lib/hash.js | 2 +- test/lib/helpers.js | 2 +- test/lib/link/connector.js | 2 +- test/lib/link/link.js | 6 +- test/lib/link/messages.js | 4 +- test/lib/luaTools.js | 2 +- test/lib/objectOps.js | 2 +- test/lib/plugin.js | 6 +- test/lib/prometheus.js | 2 +- test/lib/users.js | 2 +- test/master.js | 2 +- test/missing.js | 2 +- test/mock.js | 2 +- test/slave.js | 6 +- 133 files changed, 367 insertions(+), 259 deletions(-) create mode 100644 .eslintignore create mode 100644 lerna.json delete mode 100644 lib/package.json rename clusterctl.js => packages/ctl/clusterctl.js (98%) mode change 100644 => 100755 create mode 100644 packages/ctl/package.json rename build-mod.js => packages/lib/build_mod.js (100%) rename {lib => packages/lib}/command.js (98%) rename {lib => packages/lib}/config/classes.js (99%) rename {lib => packages/lib}/config/definitions.js (100%) rename {lib => packages/lib}/config/index.js (100%) rename {lib => packages/lib}/database.js (99%) rename {lib => packages/lib}/errors.js (100%) rename {lib => packages/lib}/factorio/export.js (99%) rename {lib => packages/lib}/factorio/index.js (58%) rename {lib => packages/lib}/factorio/patch.js (99%) rename {lib => packages/lib}/factorio/server.js (99%) rename {lib => packages/lib}/fileOps/fileOps.js (100%) rename {lib => packages/lib}/fileOps/index.js (100%) rename {lib => packages/lib}/hash.js (100%) rename {lib => packages/lib}/helpers.js (100%) rename {lib => packages/lib}/link/connectors.js (99%) rename {lib => packages/lib}/link/index.js (58%) rename {lib => packages/lib}/link/link.js (98%) rename {lib => packages/lib}/link/messages.js (99%) rename {lib => packages/lib}/luaTools.js (100%) rename {lib => packages/lib}/objectOps.js (100%) create mode 100644 packages/lib/package.json rename {lib => packages/lib}/plugin.js (98%) rename {lib => packages/lib}/prometheus.js (100%) rename {lib => packages/lib}/schema.js (100%) rename {lib => packages/lib}/users.js (100%) rename master.js => packages/master/master.js (98%) mode change 100644 => 100755 rename lib/npmPostinstall.js => packages/master/npm_post_install.js (100%) create mode 100644 packages/master/package.json rename lib/generateSSLcert.js => packages/master/src/generate_ssl_cert.js (95%) rename routes.js => packages/master/src/routes.js (100%) rename {static => packages/master/static}/bootstrap.min.css (100%) rename {static => packages/master/static}/browserconfig.xml (100%) rename {static => packages/master/static}/favicon.ico (100%) rename {static => packages/master/static}/favicon/android-icon-144x144.png (100%) rename {static => packages/master/static}/favicon/android-icon-192x192.png (100%) rename {static => packages/master/static}/favicon/android-icon-36x36.png (100%) rename {static => packages/master/static}/favicon/android-icon-48x48.png (100%) rename {static => packages/master/static}/favicon/android-icon-72x72.png (100%) rename {static => packages/master/static}/favicon/android-icon-96x96.png (100%) rename {static => packages/master/static}/favicon/apple-icon-114x114.png (100%) rename {static => packages/master/static}/favicon/apple-icon-120x120.png (100%) rename {static => packages/master/static}/favicon/apple-icon-144x144.png (100%) rename {static => packages/master/static}/favicon/apple-icon-152x152.png (100%) rename {static => packages/master/static}/favicon/apple-icon-180x180.png (100%) rename {static => packages/master/static}/favicon/apple-icon-57x57.png (100%) rename {static => packages/master/static}/favicon/apple-icon-60x60.png (100%) rename {static => packages/master/static}/favicon/apple-icon-72x72.png (100%) rename {static => packages/master/static}/favicon/apple-icon-76x76.png (100%) rename {static => packages/master/static}/favicon/apple-icon-precomposed.png (100%) rename {static => packages/master/static}/favicon/apple-icon.png (100%) rename {static => packages/master/static}/favicon/browserconfig.xml (100%) rename {static => packages/master/static}/favicon/favicon-16x16.png (100%) rename {static => packages/master/static}/favicon/favicon-32x32.png (100%) rename {static => packages/master/static}/favicon/favicon-96x96.png (100%) rename {static => packages/master/static}/favicon/favicon.ico (100%) rename {static => packages/master/static}/favicon/manifest.json (100%) rename {static => packages/master/static}/favicon/ms-icon-144x144.png (100%) rename {static => packages/master/static}/favicon/ms-icon-150x150.png (100%) rename {static => packages/master/static}/favicon/ms-icon-310x310.png (100%) rename {static => packages/master/static}/favicon/ms-icon-70x70.png (100%) rename {static => packages/master/static}/lib/terminal.js (100%) rename {static => packages/master/static}/lib/utility.js (100%) rename {static => packages/master/static}/main.js (100%) rename {static => packages/master/static}/manifest.json (100%) rename {static => packages/master/static}/nodeDetails.css (100%) rename {static => packages/master/static}/nodeDetails.js (100%) rename {static => packages/master/static}/pictures/clusterio_icon.png (100%) rename {static => packages/master/static}/pictures/logo.png (100%) rename {static => packages/master/static}/pictures/unknown-item.png (100%) rename {static => packages/master/static}/settings.js (100%) rename {static => packages/master/static}/style.css (100%) create mode 100644 packages/slave/package.json rename slave.js => packages/slave/slave.js (98%) mode change 100644 => 100755 diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..444b47c8 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +packages/master/static diff --git a/.gitignore b/.gitignore index 32870a46..57a52e6f 100644 --- a/.gitignore +++ b/.gitignore @@ -28,7 +28,7 @@ dist/ # Autogenerated docs output /docs/api -node_modules/* +node_modules Factorio* /factorio @@ -41,7 +41,7 @@ Factorio* package-lock.json mod_cache.json static/export -static/external +packages/master/static/external saves /temp/ diff --git a/.travis.yml b/.travis.yml index 01d17891..2ef6aced 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,8 @@ before_install: - tar -xf factorio.tar.gz - npm install -g codecov script: - - node build-mod --bump-patch --factorio-version 0.18 --output-dir sharedMods + - npx lerna bootstrap + - node packages/lib/build_mod --bump-patch --factorio-version 0.18 --output-dir sharedMods - curl -o sharedMods/subspace_storage_1.99.1.zip -L https://github.com/clusterio/factorioClusterioMod/releases/download/1.99.1/subspace_storage_1.99.1.zip - npm run-script ci-cover - cat temp/test/integration/log.txt diff --git a/README.md b/README.md index f4fedff6..233751fa 100644 --- a/README.md +++ b/README.md @@ -105,12 +105,13 @@ supported on EOL Ubuntu releases so make sure you're on a recent release of Ubun Master and all slaves: wget -qO - https://deb.nodesource.com/setup_12.x | sudo -E bash - - sudo apt install -y nodejs python-dev git build-essential - git clone -b master https://github.com/clusterio/factorioClusterio.git - cd factorioClusterio + sudo apt install -y nodejs + mkdir clusterio + cd clusterio + npm init -y + npm install @clusterio/master @clusterio/slave @clusterio/ctl wget -O factorio.tar.gz https://www.factorio.com/get-download/latest/headless/linux64 tar -xf factorio.tar.gz - npm install --only=production downloads and installs nodejs, git and clusterio. To specify a version, change "latest" in the link to a version number like 0.14.21. @@ -136,30 +137,19 @@ The -v flag is used to specify the instance directory. Your instances (save file **Warning**: These instructions are for the unstable master version and is not recommended for use, see [the 1.2.x branch][1.2.x] for how to install the stable version. -Clusterio is built up of multiple parts. Here is a quick guide: - -Master = master.js - -Server host (Slave) = slave.js + factorio server - -Game Client = The people connecting to the server - **Requirements** download and install nodeJS 12 from http://nodejs.org. Clusterio runs on Node.js v12 and up, v11.13.0+ and v10.16.0+. -download and install git from https://git-scm.com/ - -reboot when you are done, then proceed to the next steps. *reboots matter* - **Master** 1. Open PowerShell or Command prompt in the directory you want to install to and run the following commands. - git clone -b master https://github.com/clusterio/factorioClusterio - cd factorioClusterio - npm install --only=production + mkdir clusterio + cd clusterio + npm init -y + npm install @clusterio/master @clusterio/slave @clusterio/ctl 2. Obtain Factorio by either of these two methods: @@ -198,8 +188,8 @@ Before you can manage the cluster you need to bootstrap an admin account for it. Replace `` with your Factorio username (do not make up a new username here). - node master bootstrap create-admin - node master bootstrap create-ctl-config + npx clusteriomaster bootstrap create-admin + npx clusteriomaster bootstrap create-ctl-config The first command creates a user account with the given name and promotes it to a cluster admin. The second one sets up a @@ -213,7 +203,7 @@ It's necessary to run the master server in order for anything to work. Once you've completed the setup run the following command to start it up: - node master run + npx clusteriomaster run ### Slaves @@ -223,7 +213,7 @@ master server. In order for slaves to connect to the master server they need a valid authentication token, you can create a slave config with a valid token with the following command. - node clusterctl slave create-config --name Local --generate-token + npx clusterctl slave create-config --name Local --generate-token This will write a new `config-slave.json` file in the current directory (you can change the location with the `--output` option) with the name, @@ -232,13 +222,13 @@ the config for a remote slave you will need to have set the `master.external_address` option to the URL the master server can be reached on. -You can list the config of a slave on the slave itself with the `node -slave config list` command. Use `node slave config --help` for more -information. +You can list the config of a slave on the slave itself with the `npx +clusterioslave config list` command. Use `npx clusterioslave config +--help` for more information. Once the config is set up run the slave with - node slave run + npx clusterioslave run ### Instances @@ -253,9 +243,9 @@ clusterctl control-config set` command: The basic operations to start a new instance is the following - node clusterctl instance create "My instance" - node clusterctl instance assign "My instance" "Local" - node clusterctl instance start "My instance" + npx clusterctl instance create "My instance" + npx clusterctl instance assign "My instance" "Local" + npx clusterctl instance start "My instance" The first line creates the instance configuration on the master server. The second assigns the instance to a slave which creates the instance @@ -264,7 +254,7 @@ third line starts the instance, which creates a new save if there are no save games present. There are many more commands available with clusterctl. See -`node clusterctl --help` for a full list of them. +`npx clusterctl --help` for a full list of them. ## Plugins @@ -298,7 +288,3 @@ TLDR: the tested fix is: - select TCP and select specific local ports and type in the ports that you want to open (comma separated) and click next > 3 times - give the rule a name (like 'web server' or something), give it a description (optionally) and click finish - -### Other fixes for other potential problems: - -Sometimes the install fails. Try `node ./lib/npmPostinstall` to complete it. diff --git a/docs/communication.md b/docs/communication.md index 010a2cba..54c75af2 100644 --- a/docs/communication.md +++ b/docs/communication.md @@ -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 diff --git a/docs/config-system.md b/docs/config-system.md index e4f82268..31b65406 100644 --- a/docs/config-system.md +++ b/docs/config-system.md @@ -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. diff --git a/docs/contributing.md b/docs/contributing.md index 9370d70d..a7c909f3 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -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 diff --git a/docs/jsdoc.json b/docs/jsdoc.json index 19005b30..4974fc3b 100644 --- a/docs/jsdoc.json +++ b/docs/jsdoc.json @@ -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" } diff --git a/docs/maniging-a-cluster.md b/docs/maniging-a-cluster.md index 4db36968..b1d74abe 100644 --- a/docs/maniging-a-cluster.md +++ b/docs/maniging-a-cluster.md @@ -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 ` in the clusterio directory. This document -uses the shorthand `ctl> foo` to indicate `node clusterctl foo` should +`npx clusterctl ` in the clusterio directory. This document +uses the shorthand `ctl> foo` to indicate `npx clusterctl foo` should be executed. Mandatory parameters are shown in `` 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 ` 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 ` on the +master server, which creates the necessary `config-control.json` for +managing the cluster as the given user. Slaves diff --git a/docs/socket.md b/docs/socket.md index 99bd49ef..3e1acd27 100644 --- a/docs/socket.md +++ b/docs/socket.md @@ -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` diff --git a/docs/writing-plugins.md b/docs/writing-plugins.md index b1ba341d..6ac1a6cb 100644 --- a/docs/writing-plugins.md +++ b/docs/writing-plugins.md @@ -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) { diff --git a/lerna.json b/lerna.json new file mode 100644 index 00000000..8732d9e9 --- /dev/null +++ b/lerna.json @@ -0,0 +1,6 @@ +{ + "packages": [ + "packages/*" + ], + "version": "2.0.0-alpha0" +} diff --git a/lib/package.json b/lib/package.json deleted file mode 100644 index 269ff388..00000000 --- a/lib/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "lib", - "description": "Internal library for factorioClusterio" -} - diff --git a/package.json b/package.json index 83b0509b..5eb377f6 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,14 @@ { - "name": "clusterio", - "version": "2.0.0-alpha", - "description": "Interserver communication for factorio", - "repository": "https://github.com/clusterio/factorioClusterio", - "main": "master.js", + "name": "root", + "private": true, "scripts": { "test": "mocha --exit --check-leaks -R spec --recursive test plugins/*/test", "fast-test": "FAST_TEST=y npm test", "cover": "nyc npm test", "fast-cover": "FAST_TEST=y nyc npm test", "ci-cover": "nyc --reporter=lcovonly npm run-script test", - "lint": "eslint \"*.js\" lib plugins test", + "lint": "eslint \"*.js\" packages plugins test", "docs": "jsdoc --configure docs/jsdoc.json", - "install": "node lib/npmPostinstall", "bundle-dependencies": "bundle-dependencies" }, "nyc": { @@ -21,49 +17,24 @@ "plugins/*/test/**" ] }, - "keywords": [ - "factorio" - ], - "author": "Danielv123", - "license": "MIT", "engines": { "node": ">=10.16 <11 || >= 11.13" }, - "dependencies": { - "as-table": "^1.0.31", - "body-parser": "^1.18.2", - "chalk": "^3.0.0", - "compression": "^1.7.2", - "cookie-parser": "^1.4.3", - "ejs": "^2.5.7", - "express": "^4.16.2", - "express-fileupload": "1.2.0", - "fs-extra": "^8.1.0", - "ini": "^1.3.5", - "jimp": "^0.12.1", - "jsonwebtoken": "^8.2.1", - "jszip": "^3.2.2", - "lib": "file:./lib", - "moment": "^2.22.2", - "needle": "^2.4.0", - "node-factorio-api": "^0.3.8", - "node-forge": "^0.10.0", - "phin": "^3.4.1", - "pidusage": "^2.0.18", - "rcon-client": "^4.2.0", - "request": "^2.83.0", - "semver": "^7.1.1", - "set-blocking": "^2.0.0", - "ws": "^7.2.3", - "yargs": "^14.2.0" - }, "devDependencies": { + "@clusterio/ctl": "file:./packages/ctl", + "@clusterio/lib": "file:./packages/lib", + "@clusterio/master": "file:packages/master", + "@clusterio/slave": "file:./packages/slave", "eslint": "^7.2.0", + "fs-extra": "^8.1.0", "html5-validator": "^1.2.1", "jsdoc": "^3.6.3", - "klaw": "^3.0.0", + "jsonwebtoken": "^8.2.1", + "jszip": "^3.2.2", + "lerna": "^3.22.1", "mocha": "^6.2.0", "mocha.parallel": "^0.15.5", - "nyc": "^14.1.1" + "nyc": "^14.1.1", + "phin": "^3.4.1" } } diff --git a/clusterctl.js b/packages/ctl/clusterctl.js old mode 100644 new mode 100755 similarity index 98% rename from clusterctl.js rename to packages/ctl/clusterctl.js index 310d5265..d55c986c --- a/clusterctl.js +++ b/packages/ctl/clusterctl.js @@ -1,21 +1,23 @@ +#!/usr/bin/env node + /** * Command line interface for controlling a Clusterio cluster * @module */ "use strict"; -const jwt = require("jsonwebtoken"); const fs = require("fs-extra"); const yargs = require("yargs"); const version = require("./package").version; const asTable = require("as-table").configure({ delimiter: " | " }); const chalk = require("chalk"); const events = require("events"); +const path = require("path"); -const link = require("lib/link"); -const errors = require("lib/errors"); -const config = require("lib/config"); -const plugin = require("lib/plugin"); -const command = require("lib/command"); +const link = require("@clusterio/lib/link"); +const errors = require("@clusterio/lib/errors"); +const config = require("@clusterio/lib/config"); +const plugin = require("@clusterio/lib/plugin"); +const command = require("@clusterio/lib/command"); /** @@ -608,7 +610,9 @@ async function startControl() { continue; } - let { ControlPlugin } = require(`./plugins/${pluginInfo.name}/${pluginInfo.controlEntrypoint}`); + // XXX Does not work on Windows + let pluginPath = path.relative(__dirname, path.join("plugins", pluginInfo.name)); + let { ControlPlugin } = require(path.join(pluginPath, pluginInfo.controlEntrypoint)); let controlPlugin = new ControlPlugin(pluginInfo); controlPlugins.set(pluginInfo.name, controlPlugin); await controlPlugin.init(); diff --git a/packages/ctl/package.json b/packages/ctl/package.json new file mode 100644 index 00000000..dd9e37e4 --- /dev/null +++ b/packages/ctl/package.json @@ -0,0 +1,27 @@ +{ + "name": "@clusterio/ctl", + "description": "Clusterio command line management tool", + "author": "Hornwitser", + "license": "MIT", + "version": "2.0.0-alpha0", + "main": "clusterctl.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "bin": { + "clusterctl": "./clusterctl.js" + }, + "keywords": [ + "factorio" + ], + "engines": { + "node": ">=10.16 <11 || >= 11.13" + }, + "dependencies": { + "@clusterio/lib": "=2.0.0-alpha0", + "as-table": "^1.0.31", + "chalk": "^3.0.0", + "fs-extra": "^8.1.0", + "yargs": "^14.2.0" + } +} diff --git a/build-mod.js b/packages/lib/build_mod.js similarity index 100% rename from build-mod.js rename to packages/lib/build_mod.js diff --git a/lib/command.js b/packages/lib/command.js similarity index 98% rename from lib/command.js rename to packages/lib/command.js index 691d99f9..a2062a64 100644 --- a/lib/command.js +++ b/packages/lib/command.js @@ -7,8 +7,8 @@ * @module */ "use strict"; -const link = require("lib/link"); -const errors = require("lib/errors"); +const link = require("@clusterio/lib/link"); +const errors = require("@clusterio/lib/errors"); /** * Represents a command that can be runned by clusterctl diff --git a/lib/config/classes.js b/packages/lib/config/classes.js similarity index 99% rename from lib/config/classes.js rename to packages/lib/config/classes.js index ca369270..101b8037 100644 --- a/lib/config/classes.js +++ b/packages/lib/config/classes.js @@ -4,7 +4,7 @@ const events = require("events"); const util = require("util"); -const { basicType } = require("lib/helpers"); +const { basicType } = require("@clusterio/lib/helpers"); /** diff --git a/lib/config/definitions.js b/packages/lib/config/definitions.js similarity index 100% rename from lib/config/definitions.js rename to packages/lib/config/definitions.js diff --git a/lib/config/index.js b/packages/lib/config/index.js similarity index 100% rename from lib/config/index.js rename to packages/lib/config/index.js diff --git a/lib/database.js b/packages/lib/database.js similarity index 99% rename from lib/database.js rename to packages/lib/database.js index 74b59853..0b917115 100644 --- a/lib/database.js +++ b/packages/lib/database.js @@ -8,7 +8,7 @@ "use strict"; const fs = require("fs-extra"); -const { basicType } = require("lib/helpers"); +const { basicType } = require("@clusterio/lib/helpers"); /** diff --git a/lib/errors.js b/packages/lib/errors.js similarity index 100% rename from lib/errors.js rename to packages/lib/errors.js diff --git a/lib/factorio/export.js b/packages/lib/factorio/export.js similarity index 99% rename from lib/factorio/export.js rename to packages/lib/factorio/export.js index c1ac3da5..9a19617b 100644 --- a/lib/factorio/export.js +++ b/packages/lib/factorio/export.js @@ -6,7 +6,7 @@ const ini = require("ini"); const Jimp = require("jimp"); const JSZip = require("jszip"); -const buildMod = require("../../build-mod"); +const buildMod = require("@clusterio/lib/build_mod"); /** * Generate the export mod needed for exportData diff --git a/lib/factorio/index.js b/packages/lib/factorio/index.js similarity index 58% rename from lib/factorio/index.js rename to packages/lib/factorio/index.js index f6104a77..8624b8c4 100644 --- a/lib/factorio/index.js +++ b/packages/lib/factorio/index.js @@ -5,7 +5,7 @@ */ "use strict"; module.exports = { - ...require("lib/factorio/export"), - ...require("lib/factorio/patch"), - ...require("lib/factorio/server"), + ...require("./export"), + ...require("./patch"), + ...require("./server"), }; diff --git a/lib/factorio/patch.js b/packages/lib/factorio/patch.js similarity index 99% rename from lib/factorio/patch.js rename to packages/lib/factorio/patch.js index 6742a21f..8021e58c 100644 --- a/lib/factorio/patch.js +++ b/packages/lib/factorio/patch.js @@ -7,7 +7,7 @@ const jszip = require("jszip"); const path = require("path"); const semver = require("semver"); -const hash = require("lib/hash"); +const hash = require("@clusterio/lib/hash"); const knownScenarios = { diff --git a/lib/factorio/server.js b/packages/lib/factorio/server.js similarity index 99% rename from lib/factorio/server.js rename to packages/lib/factorio/server.js index 77f0cc70..04c88e87 100644 --- a/lib/factorio/server.js +++ b/packages/lib/factorio/server.js @@ -9,7 +9,7 @@ const crypto = require("crypto"); const ini = require("ini"); const rconClient = require("rcon-client"); -const errors = require("lib/errors"); +const errors = require("@clusterio/lib/errors"); /** diff --git a/lib/fileOps/fileOps.js b/packages/lib/fileOps/fileOps.js similarity index 100% rename from lib/fileOps/fileOps.js rename to packages/lib/fileOps/fileOps.js diff --git a/lib/fileOps/index.js b/packages/lib/fileOps/index.js similarity index 100% rename from lib/fileOps/index.js rename to packages/lib/fileOps/index.js diff --git a/lib/hash.js b/packages/lib/hash.js similarity index 100% rename from lib/hash.js rename to packages/lib/hash.js diff --git a/lib/helpers.js b/packages/lib/helpers.js similarity index 100% rename from lib/helpers.js rename to packages/lib/helpers.js diff --git a/lib/link/connectors.js b/packages/lib/link/connectors.js similarity index 99% rename from lib/link/connectors.js rename to packages/lib/link/connectors.js index a7997f0a..b18f9844 100644 --- a/lib/link/connectors.js +++ b/packages/lib/link/connectors.js @@ -3,8 +3,8 @@ const events = require("events"); const WebSocket = require("ws"); -const schema = require("lib/schema"); -const errors = require("lib/errors"); +const schema = require("@clusterio/lib/schema"); +const errors = require("@clusterio/lib/errors"); /** diff --git a/lib/link/index.js b/packages/lib/link/index.js similarity index 58% rename from lib/link/index.js rename to packages/lib/link/index.js index 2690e686..28f7aa3a 100644 --- a/lib/link/index.js +++ b/packages/lib/link/index.js @@ -5,7 +5,7 @@ */ "use strict"; module.exports = { - ...require("lib/link/link"), - ...require("lib/link/messages"), - ...require("lib/link/connectors"), + ...require("./link"), + ...require("./messages"), + ...require("./connectors"), }; diff --git a/lib/link/link.js b/packages/lib/link/link.js similarity index 98% rename from lib/link/link.js rename to packages/lib/link/link.js index d05cfb53..1a9d0822 100644 --- a/lib/link/link.js +++ b/packages/lib/link/link.js @@ -1,9 +1,9 @@ // Implementation of Link class "use strict"; -const schema = require("lib/schema"); -const errors = require("lib/errors"); -const messages = require("lib/link/messages"); +const schema = require("@clusterio/lib/schema"); +const errors = require("@clusterio/lib/errors"); +const messages = require("./messages"); // Some definitions for the terminology used here: // link: Either side of a master - client connection diff --git a/lib/link/messages.js b/packages/lib/link/messages.js similarity index 99% rename from lib/link/messages.js rename to packages/lib/link/messages.js index 648aef20..fe16e7e4 100644 --- a/lib/link/messages.js +++ b/packages/lib/link/messages.js @@ -1,7 +1,7 @@ // Message definitions for links "use strict"; -const schema = require("lib/schema"); -const errors = require("lib/errors"); +const schema = require("@clusterio/lib/schema"); +const errors = require("@clusterio/lib/errors"); /** * Represents a message that can be sent over the link diff --git a/lib/luaTools.js b/packages/lib/luaTools.js similarity index 100% rename from lib/luaTools.js rename to packages/lib/luaTools.js diff --git a/lib/objectOps.js b/packages/lib/objectOps.js similarity index 100% rename from lib/objectOps.js rename to packages/lib/objectOps.js diff --git a/packages/lib/package.json b/packages/lib/package.json new file mode 100644 index 00000000..6936c27c --- /dev/null +++ b/packages/lib/package.json @@ -0,0 +1,26 @@ +{ + "name": "@clusterio/lib", + "description": "Shared library for Clusterio", + "version": "2.0.0-alpha0", + "repository": "https://github.com/clusterio/factorioClusterio", + "license": "MIT", + "keywords": [ + "factorio" + ], + "engines": { + "node": ">=10.16 <11 || >= 11.13" + }, + "dependencies": { + "fs-extra": "^8.1.0", + "ini": "^1.3.5", + "jimp": "^0.12.1", + "jsonwebtoken": "^8.2.1", + "jszip": "^3.2.2", + "klaw": "^3.0.0", + "node-forge": "^0.10.0", + "rcon-client": "^4.2.0", + "semver": "^7.1.1", + "ws": "^7.2.3", + "yargs": "^14.2.0" + } +} diff --git a/lib/plugin.js b/packages/lib/plugin.js similarity index 98% rename from lib/plugin.js rename to packages/lib/plugin.js index 84e4cbd5..233760ef 100644 --- a/lib/plugin.js +++ b/packages/lib/plugin.js @@ -6,7 +6,7 @@ const fs = require("fs-extra"); const path = require("path"); -const errors = require("lib/errors"); +const errors = require("@clusterio/lib/errors"); /** @@ -392,7 +392,9 @@ async function loadPluginInfos(baseDir) { try { // Note: Require path is relative to this module - pluginInfo = require(path.posix.join("..", baseDir, pluginDir, "info")); + // XXX Does not work on Windows + let pluginPath = path.relative(__dirname, path.join(baseDir, pluginDir)); + pluginInfo = require(path.join(pluginPath, "info")); } catch (err) { if (err.code === "MODULE_NOT_FOUND") { diff --git a/lib/prometheus.js b/packages/lib/prometheus.js similarity index 100% rename from lib/prometheus.js rename to packages/lib/prometheus.js diff --git a/lib/schema.js b/packages/lib/schema.js similarity index 100% rename from lib/schema.js rename to packages/lib/schema.js diff --git a/lib/users.js b/packages/lib/users.js similarity index 100% rename from lib/users.js rename to packages/lib/users.js diff --git a/master.js b/packages/master/master.js old mode 100644 new mode 100755 similarity index 98% rename from master.js rename to packages/master/master.js index f597b0f7..4685b9d1 --- a/master.js +++ b/packages/master/master.js @@ -1,3 +1,5 @@ +#!/usr/bin/env node + /** * Clusterio master server * @@ -9,7 +11,7 @@ * @module * @author Danielv123, Hornwitser * @example - * node master run + * npx clusteriomaster run */ // Attempt updating @@ -38,15 +40,15 @@ let debugEvents = new events.EventEmitter(); let pluginList = {}; // homebrew modules -const generateSSLcert = require("lib/generateSSLcert"); -const database = require("lib/database"); -const schema = require("lib/schema"); -const link = require("lib/link"); -const errors = require("lib/errors"); -const plugin = require("lib/plugin"); -const prometheus = require("lib/prometheus"); -const config = require("lib/config"); -const users = require("lib/users"); +const generateSSLcert = require("./src/generate_ssl_cert"); +const database = require("@clusterio/lib/database"); +const schema = require("@clusterio/lib/schema"); +const link = require("@clusterio/lib/link"); +const errors = require("@clusterio/lib/errors"); +const plugin = require("@clusterio/lib/plugin"); +const prometheus = require("@clusterio/lib/prometheus"); +const config = require("@clusterio/lib/config"); +const users = require("@clusterio/lib/users"); const express = require("express"); const compression = require("compression"); @@ -86,9 +88,10 @@ app.use(function(req, res, next){ next(); }); -require("./routes")(app); +require("./src/routes")(app); // Set folder to serve static content from (the website) -app.use(express.static("static")); +app.use(express.static(path.join(__dirname, "static"))); +app.use(express.static("static")); // Used for data export files const endpointHitCounter = new prometheus.Counter( "clusterio_master_http_endpoint_hits_total", @@ -1481,7 +1484,9 @@ async function loadPlugins(pluginInfos) { let MasterPlugin = plugin.BaseMasterPlugin; try { if (pluginInfo.masterEntrypoint) { - ({ MasterPlugin } = require(`./plugins/${pluginInfo.name}/${pluginInfo.masterEntrypoint}`)); + // XXX Does not work on Windows + let pluginPath = path.relative(__dirname, path.join("plugins", pluginInfo.name)); + ({ MasterPlugin } = require(path.join(pluginPath, pluginInfo.masterEntrypoint))); } let masterPlugin = new MasterPlugin( diff --git a/lib/npmPostinstall.js b/packages/master/npm_post_install.js similarity index 100% rename from lib/npmPostinstall.js rename to packages/master/npm_post_install.js diff --git a/packages/master/package.json b/packages/master/package.json new file mode 100644 index 00000000..a2062d7f --- /dev/null +++ b/packages/master/package.json @@ -0,0 +1,40 @@ +{ + "name": "@clusterio/master", + "description": "Implementation of Clusterio master server", + "author": "Hornwitser", + "license": "MIT", + "version": "2.0.0-alpha0", + "main": "master.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "install": "node npm_post_install" + }, + "bin": { + "clusteriomaster": "./master.js" + }, + "keywords": [ + "factorio" + ], + "engines": { + "node": ">=10.16 <11 || >= 11.13" + }, + "dependencies": { + "@clusterio/lib": "=2.0.0-alpha0", + "body-parser": "^1.18.2", + "compression": "^1.7.2", + "cookie-parser": "^1.4.3", + "ejs": "^2.5.7", + "express": "^4.16.2", + "express-fileupload": "1.2.0", + "fs-extra": "^8.1.0", + "jsonwebtoken": "^8.2.1", + "jszip": "^3.2.2", + "moment": "^2.22.2", + "node-factorio-api": "^0.3.8", + "node-forge": "^0.10.0", + "request": "^2.83.0", + "set-blocking": "^2.0.0", + "ws": "^7.2.3", + "yargs": "^14.2.0" + } +} diff --git a/lib/generateSSLcert.js b/packages/master/src/generate_ssl_cert.js similarity index 95% rename from lib/generateSSLcert.js rename to packages/master/src/generate_ssl_cert.js index fee1b50b..0e966b8b 100644 --- a/lib/generateSSLcert.js +++ b/packages/master/src/generate_ssl_cert.js @@ -13,7 +13,7 @@ module.exports = async function({ doLogging = false, } = {}){ function log(t) { - if(doLogging) console.log("lib/generateSSLcert.js | "+t); + if(doLogging) console.log("src/generate_ssl_cert.js | "+t); } log("Generating SSL certificate with "+bits+" bits at "+sslCertPath); diff --git a/routes.js b/packages/master/src/routes.js similarity index 100% rename from routes.js rename to packages/master/src/routes.js diff --git a/static/bootstrap.min.css b/packages/master/static/bootstrap.min.css similarity index 100% rename from static/bootstrap.min.css rename to packages/master/static/bootstrap.min.css diff --git a/static/browserconfig.xml b/packages/master/static/browserconfig.xml similarity index 100% rename from static/browserconfig.xml rename to packages/master/static/browserconfig.xml diff --git a/static/favicon.ico b/packages/master/static/favicon.ico similarity index 100% rename from static/favicon.ico rename to packages/master/static/favicon.ico diff --git a/static/favicon/android-icon-144x144.png b/packages/master/static/favicon/android-icon-144x144.png similarity index 100% rename from static/favicon/android-icon-144x144.png rename to packages/master/static/favicon/android-icon-144x144.png diff --git a/static/favicon/android-icon-192x192.png b/packages/master/static/favicon/android-icon-192x192.png similarity index 100% rename from static/favicon/android-icon-192x192.png rename to packages/master/static/favicon/android-icon-192x192.png diff --git a/static/favicon/android-icon-36x36.png b/packages/master/static/favicon/android-icon-36x36.png similarity index 100% rename from static/favicon/android-icon-36x36.png rename to packages/master/static/favicon/android-icon-36x36.png diff --git a/static/favicon/android-icon-48x48.png b/packages/master/static/favicon/android-icon-48x48.png similarity index 100% rename from static/favicon/android-icon-48x48.png rename to packages/master/static/favicon/android-icon-48x48.png diff --git a/static/favicon/android-icon-72x72.png b/packages/master/static/favicon/android-icon-72x72.png similarity index 100% rename from static/favicon/android-icon-72x72.png rename to packages/master/static/favicon/android-icon-72x72.png diff --git a/static/favicon/android-icon-96x96.png b/packages/master/static/favicon/android-icon-96x96.png similarity index 100% rename from static/favicon/android-icon-96x96.png rename to packages/master/static/favicon/android-icon-96x96.png diff --git a/static/favicon/apple-icon-114x114.png b/packages/master/static/favicon/apple-icon-114x114.png similarity index 100% rename from static/favicon/apple-icon-114x114.png rename to packages/master/static/favicon/apple-icon-114x114.png diff --git a/static/favicon/apple-icon-120x120.png b/packages/master/static/favicon/apple-icon-120x120.png similarity index 100% rename from static/favicon/apple-icon-120x120.png rename to packages/master/static/favicon/apple-icon-120x120.png diff --git a/static/favicon/apple-icon-144x144.png b/packages/master/static/favicon/apple-icon-144x144.png similarity index 100% rename from static/favicon/apple-icon-144x144.png rename to packages/master/static/favicon/apple-icon-144x144.png diff --git a/static/favicon/apple-icon-152x152.png b/packages/master/static/favicon/apple-icon-152x152.png similarity index 100% rename from static/favicon/apple-icon-152x152.png rename to packages/master/static/favicon/apple-icon-152x152.png diff --git a/static/favicon/apple-icon-180x180.png b/packages/master/static/favicon/apple-icon-180x180.png similarity index 100% rename from static/favicon/apple-icon-180x180.png rename to packages/master/static/favicon/apple-icon-180x180.png diff --git a/static/favicon/apple-icon-57x57.png b/packages/master/static/favicon/apple-icon-57x57.png similarity index 100% rename from static/favicon/apple-icon-57x57.png rename to packages/master/static/favicon/apple-icon-57x57.png diff --git a/static/favicon/apple-icon-60x60.png b/packages/master/static/favicon/apple-icon-60x60.png similarity index 100% rename from static/favicon/apple-icon-60x60.png rename to packages/master/static/favicon/apple-icon-60x60.png diff --git a/static/favicon/apple-icon-72x72.png b/packages/master/static/favicon/apple-icon-72x72.png similarity index 100% rename from static/favicon/apple-icon-72x72.png rename to packages/master/static/favicon/apple-icon-72x72.png diff --git a/static/favicon/apple-icon-76x76.png b/packages/master/static/favicon/apple-icon-76x76.png similarity index 100% rename from static/favicon/apple-icon-76x76.png rename to packages/master/static/favicon/apple-icon-76x76.png diff --git a/static/favicon/apple-icon-precomposed.png b/packages/master/static/favicon/apple-icon-precomposed.png similarity index 100% rename from static/favicon/apple-icon-precomposed.png rename to packages/master/static/favicon/apple-icon-precomposed.png diff --git a/static/favicon/apple-icon.png b/packages/master/static/favicon/apple-icon.png similarity index 100% rename from static/favicon/apple-icon.png rename to packages/master/static/favicon/apple-icon.png diff --git a/static/favicon/browserconfig.xml b/packages/master/static/favicon/browserconfig.xml similarity index 100% rename from static/favicon/browserconfig.xml rename to packages/master/static/favicon/browserconfig.xml diff --git a/static/favicon/favicon-16x16.png b/packages/master/static/favicon/favicon-16x16.png similarity index 100% rename from static/favicon/favicon-16x16.png rename to packages/master/static/favicon/favicon-16x16.png diff --git a/static/favicon/favicon-32x32.png b/packages/master/static/favicon/favicon-32x32.png similarity index 100% rename from static/favicon/favicon-32x32.png rename to packages/master/static/favicon/favicon-32x32.png diff --git a/static/favicon/favicon-96x96.png b/packages/master/static/favicon/favicon-96x96.png similarity index 100% rename from static/favicon/favicon-96x96.png rename to packages/master/static/favicon/favicon-96x96.png diff --git a/static/favicon/favicon.ico b/packages/master/static/favicon/favicon.ico similarity index 100% rename from static/favicon/favicon.ico rename to packages/master/static/favicon/favicon.ico diff --git a/static/favicon/manifest.json b/packages/master/static/favicon/manifest.json similarity index 100% rename from static/favicon/manifest.json rename to packages/master/static/favicon/manifest.json diff --git a/static/favicon/ms-icon-144x144.png b/packages/master/static/favicon/ms-icon-144x144.png similarity index 100% rename from static/favicon/ms-icon-144x144.png rename to packages/master/static/favicon/ms-icon-144x144.png diff --git a/static/favicon/ms-icon-150x150.png b/packages/master/static/favicon/ms-icon-150x150.png similarity index 100% rename from static/favicon/ms-icon-150x150.png rename to packages/master/static/favicon/ms-icon-150x150.png diff --git a/static/favicon/ms-icon-310x310.png b/packages/master/static/favicon/ms-icon-310x310.png similarity index 100% rename from static/favicon/ms-icon-310x310.png rename to packages/master/static/favicon/ms-icon-310x310.png diff --git a/static/favicon/ms-icon-70x70.png b/packages/master/static/favicon/ms-icon-70x70.png similarity index 100% rename from static/favicon/ms-icon-70x70.png rename to packages/master/static/favicon/ms-icon-70x70.png diff --git a/static/lib/terminal.js b/packages/master/static/lib/terminal.js similarity index 100% rename from static/lib/terminal.js rename to packages/master/static/lib/terminal.js diff --git a/static/lib/utility.js b/packages/master/static/lib/utility.js similarity index 100% rename from static/lib/utility.js rename to packages/master/static/lib/utility.js diff --git a/static/main.js b/packages/master/static/main.js similarity index 100% rename from static/main.js rename to packages/master/static/main.js diff --git a/static/manifest.json b/packages/master/static/manifest.json similarity index 100% rename from static/manifest.json rename to packages/master/static/manifest.json diff --git a/static/nodeDetails.css b/packages/master/static/nodeDetails.css similarity index 100% rename from static/nodeDetails.css rename to packages/master/static/nodeDetails.css diff --git a/static/nodeDetails.js b/packages/master/static/nodeDetails.js similarity index 100% rename from static/nodeDetails.js rename to packages/master/static/nodeDetails.js diff --git a/static/pictures/clusterio_icon.png b/packages/master/static/pictures/clusterio_icon.png similarity index 100% rename from static/pictures/clusterio_icon.png rename to packages/master/static/pictures/clusterio_icon.png diff --git a/static/pictures/logo.png b/packages/master/static/pictures/logo.png similarity index 100% rename from static/pictures/logo.png rename to packages/master/static/pictures/logo.png diff --git a/static/pictures/unknown-item.png b/packages/master/static/pictures/unknown-item.png similarity index 100% rename from static/pictures/unknown-item.png rename to packages/master/static/pictures/unknown-item.png diff --git a/static/settings.js b/packages/master/static/settings.js similarity index 100% rename from static/settings.js rename to packages/master/static/settings.js diff --git a/static/style.css b/packages/master/static/style.css similarity index 100% rename from static/style.css rename to packages/master/static/style.css diff --git a/packages/slave/package.json b/packages/slave/package.json new file mode 100644 index 00000000..c2fba4a6 --- /dev/null +++ b/packages/slave/package.json @@ -0,0 +1,28 @@ +{ + "name": "@clusterio/slave", + "description": "Implementation of Clusterio slave server", + "author": "Hornwitser", + "license": "MIT", + "version": "2.0.0-alpha0", + "main": "slave.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "bin": { + "clusterioslave": "./slave.js" + }, + "keywords": [ + "factorio" + ], + "engines": { + "node": ">=10.16 <11 || >= 11.13" + }, + "dependencies": { + "@clusterio/lib": "=2.0.0-alpha0", + "fs-extra": "^8.1.0", + "phin": "^3.4.1", + "pidusage": "^2.0.18", + "set-blocking": "^2.0.0", + "yargs": "^14.2.0" + } +} diff --git a/slave.js b/packages/slave/slave.js old mode 100644 new mode 100755 similarity index 98% rename from slave.js rename to packages/slave/slave.js index 7852aa65..b14727ea --- a/slave.js +++ b/packages/slave/slave.js @@ -1,3 +1,5 @@ +#!/usr/bin/env node + /** * Clusterio slave * @@ -8,7 +10,7 @@ * @module * @author Danielv123, Hornwitser * @example - * node slave run + * npx clusterioslave run */ "use strict"; const fs = require("fs-extra"); @@ -22,14 +24,14 @@ const util = require("util"); const version = require("./package").version; // internal libraries -const fileOps = require("lib/fileOps"); -const factorio = require("lib/factorio"); -const link = require("lib/link"); -const plugin = require("lib/plugin"); -const errors = require("lib/errors"); -const prometheus = require("lib/prometheus"); -const luaTools = require("lib/luaTools"); -const config = require("lib/config"); +const fileOps = require("@clusterio/lib/fileOps"); +const factorio = require("@clusterio/lib/factorio"); +const link = require("@clusterio/lib/link"); +const plugin = require("@clusterio/lib/plugin"); +const errors = require("@clusterio/lib/errors"); +const prometheus = require("@clusterio/lib/prometheus"); +const luaTools = require("@clusterio/lib/luaTools"); +const config = require("@clusterio/lib/config"); const instanceRconCommandsCounter = new prometheus.Counter( @@ -198,7 +200,9 @@ class Instance extends link.Link{ async _loadPlugin(pluginInfo, slave) { let pluginLoadStarted = Date.now(); - let { InstancePlugin } = require(`./plugins/${pluginInfo.name}/${pluginInfo.instanceEntrypoint}`); + // XXX Does not work on Windows + let pluginPath = path.relative(__dirname, path.join("plugins", pluginInfo.name)); + let { InstancePlugin } = require(path.join(pluginPath, pluginInfo.instanceEntrypoint)); let instancePlugin = new InstancePlugin(pluginInfo, this, slave); this.plugins.set(pluginInfo.name, instancePlugin); await instancePlugin.init(); @@ -1423,9 +1427,9 @@ async function startSlave() { console.error("ERROR invalid config!"); console.error( "Master server requires an access token for socket operations. As clusterio\n"+ - "slaves depends upon this, please set your token using the command node slave\n"+ - "config set slave.master_token . You can generate an auth token using\n"+ - "using node clusterctl generate-slave-token." + "slaves depends upon this, please set your token using the command npx\n"+ + "clusterioslave config set slave.master_token . You can generate an\n"+ + "auth token using npx clusterctl generate-slave-token." ); process.exitCode = 1; return; diff --git a/plugins/global_chat/control.js b/plugins/global_chat/control.js index acba4340..4f810d7a 100644 --- a/plugins/global_chat/control.js +++ b/plugins/global_chat/control.js @@ -1,7 +1,7 @@ "use strict"; -const plugin = require("lib/plugin"); +const plugin = require("@clusterio/lib/plugin"); const info = require("./info"); -const command = require("lib/command"); +const command = require("@clusterio/lib/command"); const globalChatCommands = new command.CommandTree({ name: "global-chat", description: "Global Chat plugin commands" }); diff --git a/plugins/global_chat/info.js b/plugins/global_chat/info.js index 7231ce8d..bb4dece1 100644 --- a/plugins/global_chat/info.js +++ b/plugins/global_chat/info.js @@ -1,6 +1,6 @@ "use strict"; -let link = require("lib/link"); -let plugin = require("lib/plugin"); +let link = require("@clusterio/lib/link"); +let plugin = require("@clusterio/lib/plugin"); module.exports = { name: "global_chat", diff --git a/plugins/global_chat/instance.js b/plugins/global_chat/instance.js index 5cb2dadb..7cbea0dd 100644 --- a/plugins/global_chat/instance.js +++ b/plugins/global_chat/instance.js @@ -2,8 +2,8 @@ * @module */ "use strict"; -const plugin = require("lib/plugin"); -const luaTools = require("lib/luaTools"); +const plugin = require("@clusterio/lib/plugin"); +const luaTools = require("@clusterio/lib/luaTools"); /** diff --git a/plugins/research_sync/info.js b/plugins/research_sync/info.js index c9d85316..e28ef732 100644 --- a/plugins/research_sync/info.js +++ b/plugins/research_sync/info.js @@ -1,5 +1,5 @@ "use strict"; -const link = require("lib/link"); +const link = require("@clusterio/lib/link"); // schema used for syncing technologies to and from the master diff --git a/plugins/research_sync/instance.js b/plugins/research_sync/instance.js index 4a9f56c0..e924a526 100644 --- a/plugins/research_sync/instance.js +++ b/plugins/research_sync/instance.js @@ -1,8 +1,6 @@ "use strict"; -const needle = require("needle"); - -const plugin = require("lib/plugin"); -const luaTools = require("lib/luaTools"); +const plugin = require("@clusterio/lib/plugin"); +const luaTools = require("@clusterio/lib/luaTools"); function unexpectedError(err) { diff --git a/plugins/research_sync/master.js b/plugins/research_sync/master.js index a6f0cbd4..14d4104d 100644 --- a/plugins/research_sync/master.js +++ b/plugins/research_sync/master.js @@ -2,7 +2,7 @@ const fs = require("fs-extra"); const path = require("path"); -const plugin = require("lib/plugin"); +const plugin = require("@clusterio/lib/plugin"); class MasterPlugin extends plugin.BaseMasterPlugin { diff --git a/plugins/statistics_exporter/info.js b/plugins/statistics_exporter/info.js index ca83b9b5..a0dabdd4 100644 --- a/plugins/statistics_exporter/info.js +++ b/plugins/statistics_exporter/info.js @@ -1,5 +1,5 @@ "use strict"; -let link = require("lib/link"); +let link = require("@clusterio/lib/link"); module.exports = { name: "statistics_exporter", diff --git a/plugins/statistics_exporter/instance.js b/plugins/statistics_exporter/instance.js index 2e179d1f..e5793b24 100644 --- a/plugins/statistics_exporter/instance.js +++ b/plugins/statistics_exporter/instance.js @@ -1,6 +1,6 @@ "use strict"; -const plugin = require("lib/plugin"); -const { Gauge } = require("lib/prometheus"); +const plugin = require("@clusterio/lib/plugin"); +const { Gauge } = require("@clusterio/lib/prometheus"); const instancePlayerCount = new Gauge( diff --git a/plugins/subspace_storage/dole.js b/plugins/subspace_storage/dole.js index fe06bb3a..3f49a27a 100644 --- a/plugins/subspace_storage/dole.js +++ b/plugins/subspace_storage/dole.js @@ -1,7 +1,7 @@ "use strict"; const doleNN = require("./dole_nn_base"); -const prometheus = require("lib/prometheus"); +const prometheus = require("@clusterio/lib/prometheus"); const prometheusNNDoleGauge = new prometheus.Gauge( diff --git a/plugins/subspace_storage/info.js b/plugins/subspace_storage/info.js index 028162e8..cc0e9831 100644 --- a/plugins/subspace_storage/info.js +++ b/plugins/subspace_storage/info.js @@ -1,6 +1,6 @@ "use strict"; -const link = require("lib/link"); -const config = require("lib/config"); +const link = require("@clusterio/lib/link"); +const config = require("@clusterio/lib/config"); class MasterConfigGroup extends config.PluginConfigGroup {} MasterConfigGroup.groupName = "subspace_storage"; diff --git a/plugins/subspace_storage/instance.js b/plugins/subspace_storage/instance.js index 53ca3571..da4ebea4 100644 --- a/plugins/subspace_storage/instance.js +++ b/plugins/subspace_storage/instance.js @@ -1,8 +1,8 @@ "use strict"; const fs = require("fs-extra"); -const plugin = require("lib/plugin"); -const luaTools = require("lib/luaTools"); +const plugin = require("@clusterio/lib/plugin"); +const luaTools = require("@clusterio/lib/luaTools"); function unexpectedError(err) { console.log("Unexpected error in subspace_storage"); diff --git a/plugins/subspace_storage/master.js b/plugins/subspace_storage/master.js index 9a6bdab5..00d1d290 100644 --- a/plugins/subspace_storage/master.js +++ b/plugins/subspace_storage/master.js @@ -2,9 +2,9 @@ const fs = require("fs-extra"); const path = require("path"); -const database = require("lib/database"); -const plugin = require("lib/plugin"); -const prometheus = require("lib/prometheus"); +const database = require("@clusterio/lib/database"); +const plugin = require("@clusterio/lib/plugin"); +const prometheus = require("@clusterio/lib/prometheus"); const routes = require("./routes"); const dole = require("./dole"); diff --git a/plugins/subspace_storage/routes.js b/plugins/subspace_storage/routes.js index cffa5c54..32d49933 100644 --- a/plugins/subspace_storage/routes.js +++ b/plugins/subspace_storage/routes.js @@ -2,7 +2,7 @@ const express = require("express"); const path = require("path"); -const prometheus = require("lib/prometheus"); +const prometheus = require("@clusterio/lib/prometheus"); function addWebRoutes(app) { diff --git a/sharedPlugins/inventoryImports/interfacingFunctions.js b/sharedPlugins/inventoryImports/interfacingFunctions.js index a7d78b87..cca4d6c7 100644 --- a/sharedPlugins/inventoryImports/interfacingFunctions.js +++ b/sharedPlugins/inventoryImports/interfacingFunctions.js @@ -1,4 +1,4 @@ -const objectOps = require("lib/objectOps"); +const objectOps = require("@clusterio/lib/objectOps"); const needle = require("needle"); const pluginConfig = require("./config") const isJson = require("./isJson") diff --git a/sharedPlugins/inventoryImports/test/interfacingFunctions.js b/sharedPlugins/inventoryImports/test/interfacingFunctions.js index 8624ec0b..33544a14 100644 --- a/sharedPlugins/inventoryImports/test/interfacingFunctions.js +++ b/sharedPlugins/inventoryImports/test/interfacingFunctions.js @@ -2,7 +2,7 @@ const assert = require("assert"); const child_process = require("child_process"); const functions = require("../interfacingFunctions"); const luamin = require("luamin"); -const isFactorioCommand = require("lib/isFactorioCommand"); +const isFactorioCommand = require("@clusterio/lib/isFactorioCommand"); const nock = require("nock"); // sinon does weird prototype manipulation and so doen't need to be saved to anything. diff --git a/test/clusterctl.js b/test/clusterctl.js index ade97724..b9e97bd0 100644 --- a/test/clusterctl.js +++ b/test/clusterctl.js @@ -1,24 +1,19 @@ "use strict"; const assert = require("assert").strict; -const chalk = require("chalk"); const { testLines } = require("./lib/factorio/lines"); -const clusterctl = require("../clusterctl.js"); +const clusterctl = require("@clusterio/ctl/clusterctl.js"); describe("clusterctl", function() { describe("formatOutputColored()", function() { it("should pass the test lines", function() { - // Ensure tests get uncoloured output. - let old = chalk.level; - chalk.level = 0; - for (let [reference, output] of testLines) { let line = clusterctl._formatOutputColored(output); + // Strip colours + line = line.replace(/\x1B\[\d+m/g, ""); assert.deepEqual(line, reference); } - - chalk.level = old; }); }); }); diff --git a/test/integration/clusterio.js b/test/integration/clusterio.js index e2c260bf..57f0e3c9 100644 --- a/test/integration/clusterio.js +++ b/test/integration/clusterio.js @@ -5,7 +5,7 @@ const path = require("path"); const validateHTML = require("html5-validator"); const parallel = require("mocha.parallel"); -const link = require("lib/link"); +const link = require("@clusterio/lib/link"); const { slowTest, get, execCtl, sendRcon, getControl, instancesDir } = require("./index"); @@ -18,7 +18,7 @@ describe("Integration of Clusterio", function() { for (let path of paths) { it(`sends some HTML when accessing ${path}`, async function() { let res = await get(path); - let validation = await validateHTML(res.body); + let validation = await validateHTML(res.body.toString()); let filtered = validation.messages.filter(msg => msg.type !== "info"); assert( filtered.length === 0, diff --git a/test/integration/export.js b/test/integration/export.js index 6c6fc233..f50370d3 100644 --- a/test/integration/export.js +++ b/test/integration/export.js @@ -2,7 +2,7 @@ const assert = require("assert").strict; const path = require("path"); -const factorio = require("lib/factorio"); +const factorio = require("@clusterio/lib/factorio"); describe("Integration of lib/factorio/export", function() { diff --git a/test/integration/index.js b/test/integration/index.js index 21230fcf..e64df099 100644 --- a/test/integration/index.js +++ b/test/integration/index.js @@ -3,12 +3,12 @@ const path = require("path"); const fs = require("fs-extra"); const child_process = require("child_process"); const jwt = require("jsonwebtoken"); -const needle = require("needle"); +const phin = require("phin"); const util = require("util"); const events = require("events"); -const link = require("lib/link"); -const server = require("lib/factorio/server"); +const link = require("@clusterio/lib/link"); +const server = require("@clusterio/lib/factorio/server"); class TestControl extends link.Link { @@ -45,7 +45,11 @@ function slowTest(test) { } async function get(path) { - let res = await needle("get", `https://localhost:4443${path}`, { rejectUnauthorized: false }); + let res = await phin({ + method: "GET", + url: `https://localhost:4443${path}`, + core: { rejectUnauthorized: false }, + }); if (res.statusCode != 200) { throw new Error(`Got response code ${res.statusCode}, content: ${res.body}`); } @@ -70,7 +74,7 @@ async function exec(...args) { } async function execCtl(...args) { - args[0] = `node clusterctl --config ${controlConfigPath} ${args[0]}`; + args[0] = `node packages/ctl --config ${controlConfigPath} ${args[0]}`; return await exec(...args); } @@ -113,26 +117,26 @@ before(async function() { await fs.remove(slaveConfigPath); await fs.remove(controlConfigPath); - await exec(`node master --config ${masterConfigPath} config set master.database_directory ${databaseDir}`); - await exec(`node master --config ${masterConfigPath} config set master.auth_secret TestSecretDoNotUse`); - await exec(`node master --config ${masterConfigPath} config set master.http_port 8880`); - await exec(`node master --config ${masterConfigPath} config set master.https_port 4443`); - await exec(`node master --config ${masterConfigPath} config set master.tls_certificate ${path.join(databaseDir, "cert.crt")}`); - await exec(`node master --config ${masterConfigPath} config set master.tls_private_key ${path.join(databaseDir, "cert.key")}`); - await exec(`node master --config ${masterConfigPath} config set master.tls_bits 1024`); - await exec(`node master --config ${masterConfigPath} config set master.heartbeat_interval 0.25`); - await exec(`node master --config ${masterConfigPath} config set master.connector_shutdown_timeout 2`); + await exec(`node packages/master --config ${masterConfigPath} config set master.database_directory ${databaseDir}`); + await exec(`node packages/master --config ${masterConfigPath} config set master.auth_secret TestSecretDoNotUse`); + await exec(`node packages/master --config ${masterConfigPath} config set master.http_port 8880`); + await exec(`node packages/master --config ${masterConfigPath} config set master.https_port 4443`); + await exec(`node packages/master --config ${masterConfigPath} config set master.tls_certificate ${path.join(databaseDir, "cert.crt")}`); + await exec(`node packages/master --config ${masterConfigPath} config set master.tls_private_key ${path.join(databaseDir, "cert.key")}`); + await exec(`node packages/master --config ${masterConfigPath} config set master.tls_bits 1024`); + await exec(`node packages/master --config ${masterConfigPath} config set master.heartbeat_interval 0.25`); + await exec(`node packages/master --config ${masterConfigPath} config set master.connector_shutdown_timeout 2`); - await exec(`node master --config ${masterConfigPath} bootstrap create-admin test`); - await exec(`node master --config ${masterConfigPath} bootstrap create-ctl-config test --output ${controlConfigPath}`); + await exec(`node packages/master --config ${masterConfigPath} bootstrap create-admin test`); + await exec(`node packages/master --config ${masterConfigPath} bootstrap create-ctl-config test --output ${controlConfigPath}`); - masterProcess = await spawn("master:", `node master --config ${masterConfigPath} run`, "All plugins loaded"); + masterProcess = await spawn("master:", `node packages/master --config ${masterConfigPath} run`, "All plugins loaded"); let createArgs = `--id 4 --name slave --generate-token --output ${slaveConfigPath}`; await execCtl(`slave create-config ${createArgs}`); - await exec(`node slave --config ${slaveConfigPath} config set slave.instances_directory ${instancesDir}`); + await exec(`node packages/slave --config ${slaveConfigPath} config set slave.instances_directory ${instancesDir}`); - slaveProcess = await spawn("slave:", `node slave --config ${slaveConfigPath} run`, "SOCKET | received ready from master"); + slaveProcess = await spawn("slave:", `node packages/slave --config ${slaveConfigPath} run`, "SOCKET | received ready from master"); let controlConnector = new TestControlConnector(url, 2); controlConnector.token = controlToken; diff --git a/test/integration/patch.js b/test/integration/patch.js index 1baf6b1b..452ad712 100644 --- a/test/integration/patch.js +++ b/test/integration/patch.js @@ -4,7 +4,7 @@ const fs = require("fs-extra"); const jszip = require("jszip"); const path = require("path"); -const factorio = require("lib/factorio"); +const factorio = require("@clusterio/lib/factorio"); const { slowTest } = require("./index"); diff --git a/test/integration/server.js b/test/integration/server.js index 810570c1..0fe8f915 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -4,8 +4,8 @@ const events = require("events"); const fs = require("fs-extra"); const path = require("path"); -const factorio = require("lib/factorio"); -const errors = require("lib/errors"); +const factorio = require("@clusterio/lib/factorio"); +const errors = require("@clusterio/lib/errors"); const { slowTest } = require("./index"); diff --git a/test/lib/command.js b/test/lib/command.js index bc612782..f09db22e 100644 --- a/test/lib/command.js +++ b/test/lib/command.js @@ -1,9 +1,9 @@ "use strict"; const assert = require("assert").strict; -const command = require("lib/command"); -const errors = require("lib/errors"); -const link = require("lib/link"); +const command = require("@clusterio/lib/command"); +const errors = require("@clusterio/lib/errors"); +const link = require("@clusterio/lib/link"); const mock = require("../mock"); diff --git a/test/lib/config/classes.js b/test/lib/config/classes.js index 802a8860..d423f3e4 100644 --- a/test/lib/config/classes.js +++ b/test/lib/config/classes.js @@ -1,5 +1,5 @@ "use strict"; -const classes = require("lib/config/classes"); +const classes = require("@clusterio/lib/config/classes"); const assert = require("assert").strict; diff --git a/test/lib/database.js b/test/lib/database.js index 2b4670bc..1047e695 100644 --- a/test/lib/database.js +++ b/test/lib/database.js @@ -3,7 +3,7 @@ const assert = require("assert").strict; const fs = require("fs-extra"); const path = require("path"); -const database = require("lib/database"); +const database = require("@clusterio/lib/database"); describe("lib/database", function() { describe("mapToObject()", function() { diff --git a/test/lib/factorio/export.js b/test/lib/factorio/export.js index d4ce5691..a639a2da 100644 --- a/test/lib/factorio/export.js +++ b/test/lib/factorio/export.js @@ -2,7 +2,7 @@ const assert = require("assert").strict; const path = require("path"); -const factorio = require("lib/factorio"); +const factorio = require("@clusterio/lib/factorio"); describe("lib/factorio/export", function() { diff --git a/test/lib/factorio/patch.js b/test/lib/factorio/patch.js index 02a2527b..54d5109f 100644 --- a/test/lib/factorio/patch.js +++ b/test/lib/factorio/patch.js @@ -4,7 +4,7 @@ const fs = require("fs-extra"); const jszip = require("jszip"); const path = require("path"); -const factorio = require("lib/factorio"); +const factorio = require("@clusterio/lib/factorio"); describe("lib/factorio", function() { diff --git a/test/lib/factorio/server.js b/test/lib/factorio/server.js index f42438e0..32d21802 100644 --- a/test/lib/factorio/server.js +++ b/test/lib/factorio/server.js @@ -4,7 +4,7 @@ const events = require("events"); const fs = require("fs-extra"); const path = require("path"); -const factorio = require("lib/factorio"); +const factorio = require("@clusterio/lib/factorio"); const { testLines } = require("./lines"); diff --git a/test/lib/fileOps/fileOps.js b/test/lib/fileOps/fileOps.js index 30744860..9fb8d76a 100644 --- a/test/lib/fileOps/fileOps.js +++ b/test/lib/fileOps/fileOps.js @@ -3,7 +3,7 @@ const assert = require("assert").strict; const fs = require("fs-extra"); const path = require("path"); -const fileOps = require("lib/fileOps"); +const fileOps = require("@clusterio/lib/fileOps"); describe("fileOps.js", function(){ let baseDir = path.join("temp", "test", "fileOps"); diff --git a/test/lib/generateSSLcert.js b/test/lib/generateSSLcert.js index e64e6b43..a8fac889 100644 --- a/test/lib/generateSSLcert.js +++ b/test/lib/generateSSLcert.js @@ -3,7 +3,7 @@ const assert = require("assert"); const fs = require("fs-extra"); const path = require("path"); -const generateSSLcert = require("lib/generateSSLcert"); +const generateSSLcert = require("@clusterio/master/src/generate_ssl_cert"); describe("generateSSLcert.js(options)", function() { let testDir = path.join("temp", "test", "certTest"); diff --git a/test/lib/hash.js b/test/lib/hash.js index b12045d9..e349376a 100644 --- a/test/lib/hash.js +++ b/test/lib/hash.js @@ -4,7 +4,7 @@ const fs = require("fs"); const path = require("path"); const stream = require("stream"); -const hash = require("lib/hash"); +const hash = require("@clusterio/lib/hash"); describe("lib/hash", function() { diff --git a/test/lib/helpers.js b/test/lib/helpers.js index cdad02ad..30f0863c 100644 --- a/test/lib/helpers.js +++ b/test/lib/helpers.js @@ -1,7 +1,7 @@ "use strict"; const assert = require("assert").strict; -const helpers = require("lib/helpers"); +const helpers = require("@clusterio/lib/helpers"); describe("lib/helpers", function() { diff --git a/test/lib/link/connector.js b/test/lib/link/connector.js index 4d650d67..76783419 100644 --- a/test/lib/link/connector.js +++ b/test/lib/link/connector.js @@ -3,7 +3,7 @@ const assert = require("assert").strict; const events = require("events"); const mock = require("../../mock"); -const link = require("lib/link"); +const link = require("@clusterio/lib/link"); describe("lib/link/connectors", function() { diff --git a/test/lib/link/link.js b/test/lib/link/link.js index 9b860673..441600e1 100644 --- a/test/lib/link/link.js +++ b/test/lib/link/link.js @@ -2,9 +2,9 @@ const assert = require("assert").strict; const events = require("events"); -const link = require("lib/link"); -const errors = require("lib/errors"); -const schema = require("lib/schema"); +const link = require("@clusterio/lib/link"); +const errors = require("@clusterio/lib/errors"); +const schema = require("@clusterio/lib/schema"); const mock = require("../../mock"); diff --git a/test/lib/link/messages.js b/test/lib/link/messages.js index 25817638..74ba7f85 100644 --- a/test/lib/link/messages.js +++ b/test/lib/link/messages.js @@ -1,8 +1,8 @@ "use strict"; const assert = require("assert").strict; -const link = require("lib/link"); -const errors = require("lib/errors"); +const link = require("@clusterio/lib/link"); +const errors = require("@clusterio/lib/errors"); const mock = require("../../mock"); diff --git a/test/lib/luaTools.js b/test/lib/luaTools.js index c2958db1..55d5c408 100644 --- a/test/lib/luaTools.js +++ b/test/lib/luaTools.js @@ -1,7 +1,7 @@ "use strict"; const assert = require("assert").strict; -const luaTools = require("lib/luaTools"); +const luaTools = require("@clusterio/lib/luaTools"); describe("lib/luaTools", function() { diff --git a/test/lib/objectOps.js b/test/lib/objectOps.js index 8ce2a769..f975f280 100644 --- a/test/lib/objectOps.js +++ b/test/lib/objectOps.js @@ -1,6 +1,6 @@ "use strict"; var assert = require("assert"); -var objectOps = require("lib/objectOps"); +var objectOps = require("@clusterio/lib/objectOps"); describe("objectOps.js", function(){ describe("objectOps.deepclone()", function(){ diff --git a/test/lib/plugin.js b/test/lib/plugin.js index f1122edc..879e225f 100644 --- a/test/lib/plugin.js +++ b/test/lib/plugin.js @@ -4,9 +4,9 @@ const fs = require("fs-extra"); const path = require("path"); const mock = require("../mock"); -const link = require("lib/link"); -const plugin = require("lib/plugin"); -const errors = require("lib/errors"); +const link = require("@clusterio/lib/link"); +const plugin = require("@clusterio/lib/plugin"); +const errors = require("@clusterio/lib/errors"); describe("lib/plugin", function() { diff --git a/test/lib/prometheus.js b/test/lib/prometheus.js index d1602c47..f693c183 100644 --- a/test/lib/prometheus.js +++ b/test/lib/prometheus.js @@ -1,7 +1,7 @@ "use strict"; const assert = require("assert").strict; -const prometheus = require("lib/prometheus"); +const prometheus = require("@clusterio/lib/prometheus"); describe("lib/prometheus", function() { diff --git a/test/lib/users.js b/test/lib/users.js index 35788d1d..1dcf1d46 100644 --- a/test/lib/users.js +++ b/test/lib/users.js @@ -1,6 +1,6 @@ "use strict"; const assert = require("assert").strict; -const users = require("lib/users"); +const users = require("@clusterio/lib/users"); describe("lib/users", function() { diff --git a/test/master.js b/test/master.js index 128f106e..50510de8 100644 --- a/test/master.js +++ b/test/master.js @@ -2,7 +2,7 @@ const assert = require("assert").strict; const mock = require("./mock"); -const master = require("../master"); +const master = require("@clusterio/master/master"); describe("Master testing", function() { diff --git a/test/missing.js b/test/missing.js index 403ec4ae..1c0ba611 100644 --- a/test/missing.js +++ b/test/missing.js @@ -2,4 +2,4 @@ // required here in order to track coverage for them. "use strict"; -require("lib/npmPostinstall.js"); +require("@clusterio/master/npm_post_install.js"); diff --git a/test/mock.js b/test/mock.js index 6fd759ec..03e851f9 100644 --- a/test/mock.js +++ b/test/mock.js @@ -1,7 +1,7 @@ "use strict"; const events = require("events"); -const link = require("lib/link"); +const link = require("@clusterio/lib/link"); class MockSocket { diff --git a/test/slave.js b/test/slave.js index 24749e2a..bb10399e 100644 --- a/test/slave.js +++ b/test/slave.js @@ -3,9 +3,9 @@ const assert = require("assert").strict; const path = require("path"); const fs = require("fs-extra"); -const link = require("lib/link"); -const config = require("lib/config"); -const slave = require("../slave"); +const link = require("@clusterio/lib/link"); +const config = require("@clusterio/lib/config"); +const slave = require("@clusterio/slave/slave"); describe("Slave testing", function() { before(function() {