omegga 1.2.8 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -1
- package/dist/brickadia/config.js +26 -90
- package/dist/brickadia/config.js.map +1 -1
- package/dist/brickadia/server.js +294 -293
- package/dist/brickadia/server.js.map +1 -1
- package/dist/cli/auth.js +149 -177
- package/dist/cli/auth.js.map +1 -1
- package/dist/cli/config.js +64 -66
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/index.js +14 -14
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/installer.js +37 -43
- package/dist/cli/installer.js.map +1 -1
- package/dist/cli/plugin.js +651 -682
- package/dist/cli/plugin.js.map +1 -1
- package/dist/cli/terminal.js +811 -733
- package/dist/cli/terminal.js.map +1 -1
- package/dist/config/formats/format_js.js +6 -6
- package/dist/config/formats/format_js.js.map +1 -1
- package/dist/config/formats/format_yml.js +7 -10
- package/dist/config/formats/format_yml.js.map +1 -1
- package/dist/config/index.js +46 -68
- package/dist/config/index.js.map +1 -1
- package/dist/config/reader.js +16 -27
- package/dist/config/reader.js.map +1 -1
- package/dist/config/validator.js +23 -25
- package/dist/config/validator.js.map +1 -1
- package/dist/config/writer.js +11 -21
- package/dist/config/writer.js.map +1 -1
- package/dist/index.js +18 -64
- package/dist/index.js.map +1 -1
- package/dist/info/default_commands.json.js +39 -0
- package/dist/info/default_commands.json.js.map +1 -0
- package/dist/logger.js +61 -60
- package/dist/logger.js.map +1 -1
- package/dist/main.js +424 -471
- package/dist/main.js.map +1 -1
- package/dist/omegga/auth.js +101 -148
- package/dist/omegga/auth.js.map +1 -1
- package/dist/omegga/commandInjector.js +261 -251
- package/dist/omegga/commandInjector.js.map +1 -1
- package/dist/omegga/index.js +14 -52
- package/dist/omegga/index.js.map +1 -1
- package/dist/omegga/logWrangler.js +224 -275
- package/dist/omegga/logWrangler.js.map +1 -1
- package/dist/omegga/matchers/auth.js +36 -50
- package/dist/omegga/matchers/auth.js.map +1 -1
- package/dist/omegga/matchers/chat.js +49 -71
- package/dist/omegga/matchers/chat.js.map +1 -1
- package/dist/omegga/matchers/command.js +25 -36
- package/dist/omegga/matchers/command.js.map +1 -1
- package/dist/omegga/matchers/exit.js +15 -18
- package/dist/omegga/matchers/exit.js.map +1 -1
- package/dist/omegga/matchers/index.js +26 -40
- package/dist/omegga/matchers/index.js.map +1 -1
- package/dist/omegga/matchers/init.js +20 -23
- package/dist/omegga/matchers/init.js.map +1 -1
- package/dist/omegga/matchers/interact.js +58 -64
- package/dist/omegga/matchers/interact.js.map +1 -1
- package/dist/omegga/matchers/join.js +74 -95
- package/dist/omegga/matchers/join.js.map +1 -1
- package/dist/omegga/matchers/leave.js +43 -56
- package/dist/omegga/matchers/leave.js.map +1 -1
- package/dist/omegga/matchers/mapChange.js +26 -35
- package/dist/omegga/matchers/mapChange.js.map +1 -1
- package/dist/omegga/matchers/minigameJoin.js +24 -31
- package/dist/omegga/matchers/minigameJoin.js.map +1 -1
- package/dist/omegga/matchers/version.js +42 -49
- package/dist/omegga/matchers/version.js.map +1 -1
- package/dist/omegga/player.js +527 -527
- package/dist/omegga/player.js.map +1 -1
- package/dist/omegga/plugin/interface.js +91 -98
- package/dist/omegga/plugin/interface.js.map +1 -1
- package/dist/omegga/plugin/plugin_jsonrpc_stdio.js +524 -429
- package/dist/omegga/plugin/plugin_jsonrpc_stdio.js.map +1 -1
- package/dist/omegga/plugin/plugin_node_safe/proxyOmegga.js +282 -294
- package/dist/omegga/plugin/plugin_node_safe/proxyOmegga.js.map +1 -1
- package/dist/omegga/plugin/plugin_node_safe.js +365 -393
- package/dist/omegga/plugin/plugin_node_safe.js.map +1 -1
- package/dist/omegga/plugin/plugin_node_unsafe.js +119 -179
- package/dist/omegga/plugin/plugin_node_unsafe.js.map +1 -1
- package/dist/omegga/plugin.js +402 -347
- package/dist/omegga/plugin.js.map +1 -1
- package/dist/omegga/server.js +742 -774
- package/dist/omegga/server.js.map +1 -1
- package/dist/omegga/wrapper.js +64 -91
- package/dist/omegga/wrapper.js.map +1 -1
- package/dist/plugin.js +11 -31
- package/dist/plugin.js.map +1 -1
- package/dist/softconfig.js +121 -100
- package/dist/softconfig.js.map +1 -1
- package/dist/updater/steam.js +97 -112
- package/dist/updater/steam.js.map +1 -1
- package/dist/util/brdb.js +496 -528
- package/dist/util/brdb.js.map +1 -1
- package/dist/util/brick/checkBounds.js +11 -15
- package/dist/util/brick/checkBounds.js.map +1 -1
- package/dist/util/brick/constants.js +723 -174
- package/dist/util/brick/constants.js.map +1 -1
- package/dist/util/brick/displayName.js +204 -211
- package/dist/util/brick/displayName.js.map +1 -1
- package/dist/util/brick/getBounds.js +29 -41
- package/dist/util/brick/getBounds.js.map +1 -1
- package/dist/util/brick/getBrickSize.js +6 -7
- package/dist/util/brick/getBrickSize.js.map +1 -1
- package/dist/util/brick/getScaleAxis.js +24 -30
- package/dist/util/brick/getScaleAxis.js.map +1 -1
- package/dist/util/brick/index.js +8 -29
- package/dist/util/brick/index.js.map +1 -1
- package/dist/util/brick/rotate.js +29 -34
- package/dist/util/brick/rotate.js.map +1 -1
- package/dist/util/brick/setOwnership.js +13 -19
- package/dist/util/brick/setOwnership.js.map +1 -1
- package/dist/util/chat.js +53 -44
- package/dist/util/chat.js.map +1 -1
- package/dist/util/color.js +112 -124
- package/dist/util/color.js.map +1 -1
- package/dist/util/file.js +54 -98
- package/dist/util/file.js.map +1 -1
- package/dist/util/index.js +84 -106
- package/dist/util/index.js.map +1 -1
- package/dist/util/map.js +18 -20
- package/dist/util/map.js.map +1 -1
- package/dist/util/pattern.js +6 -9
- package/dist/util/pattern.js.map +1 -1
- package/dist/util/time.js +31 -34
- package/dist/util/time.js.map +1 -1
- package/dist/util/uuid.js +10 -8
- package/dist/util/uuid.js.map +1 -1
- package/dist/util/wsl.js +19 -25
- package/dist/util/wsl.js.map +1 -1
- package/dist/version.js +7 -9
- package/dist/version.js.map +1 -1
- package/dist/webserver/backend/api.js +784 -874
- package/dist/webserver/backend/api.js.map +1 -1
- package/dist/webserver/backend/calendar.js +14 -17
- package/dist/webserver/backend/calendar.js.map +1 -1
- package/dist/webserver/backend/database.js +563 -613
- package/dist/webserver/backend/database.js.map +1 -1
- package/dist/webserver/backend/index.js +153 -191
- package/dist/webserver/backend/index.js.map +1 -1
- package/dist/webserver/backend/metrics.js +219 -248
- package/dist/webserver/backend/metrics.js.map +1 -1
- package/dist/webserver/backend/util.js +47 -68
- package/dist/webserver/backend/util.js.map +1 -1
- package/dist/worker.js +322 -0
- package/dist/worker.js.map +1 -0
- package/package.json +14 -10
- package/templates/safe-ts/omegga.d.ts +2 -2
- package/vite.backend.config.mts +46 -0
- package/vite.frontend.config.mts +58 -0
- package/vitest.backend.config.mts +7 -0
- package/dist/brickadia/config.d.ts +0 -3
- package/dist/brickadia/presets.d.ts +0 -65
- package/dist/brickadia/presets.js +0 -3
- package/dist/brickadia/presets.js.map +0 -1
- package/dist/brickadia/server.d.ts +0 -36
- package/dist/brickadia/types.d.ts +0 -45
- package/dist/brickadia/types.js +0 -3
- package/dist/brickadia/types.js.map +0 -1
- package/dist/cli/auth.d.ts +0 -26
- package/dist/cli/config.d.ts +0 -10
- package/dist/cli/index.d.ts +0 -30
- package/dist/cli/installer.d.ts +0 -1
- package/dist/cli/plugin.d.ts +0 -22
- package/dist/cli/terminal.d.ts +0 -25
- package/dist/config/authorizer.d.ts +0 -2
- package/dist/config/authorizer.js +0 -38
- package/dist/config/authorizer.js.map +0 -1
- package/dist/config/formats/format_js.d.ts +0 -3
- package/dist/config/formats/format_yml.d.ts +0 -3
- package/dist/config/index.d.ts +0 -18
- package/dist/config/reader.d.ts +0 -3
- package/dist/config/types.d.ts +0 -50
- package/dist/config/types.js +0 -3
- package/dist/config/types.js.map +0 -1
- package/dist/config/validator.d.ts +0 -6
- package/dist/config/writer.d.ts +0 -3
- package/dist/index.d.ts +0 -22
- package/dist/info/default_commands.json +0 -29
- package/dist/logger.d.ts +0 -41
- package/dist/main.d.ts +0 -1
- package/dist/omegga/auth.d.ts +0 -9
- package/dist/omegga/commandInjector.d.ts +0 -35
- package/dist/omegga/index.d.ts +0 -7
- package/dist/omegga/logWrangler.d.ts +0 -32
- package/dist/omegga/matchers/auth.d.ts +0 -10
- package/dist/omegga/matchers/chat.d.ts +0 -10
- package/dist/omegga/matchers/command.d.ts +0 -7
- package/dist/omegga/matchers/exit.d.ts +0 -3
- package/dist/omegga/matchers/index.d.ts +0 -3
- package/dist/omegga/matchers/init.d.ts +0 -3
- package/dist/omegga/matchers/interact.d.ts +0 -4
- package/dist/omegga/matchers/join.d.ts +0 -4
- package/dist/omegga/matchers/leave.d.ts +0 -4
- package/dist/omegga/matchers/mapChange.d.ts +0 -3
- package/dist/omegga/matchers/minigameJoin.d.ts +0 -9
- package/dist/omegga/matchers/types.d.ts +0 -5
- package/dist/omegga/matchers/types.js +0 -3
- package/dist/omegga/matchers/types.js.map +0 -1
- package/dist/omegga/matchers/version.d.ts +0 -3
- package/dist/omegga/player.d.ts +0 -81
- package/dist/omegga/plugin/interface.d.ts +0 -30
- package/dist/omegga/plugin/plugin_jsonrpc_stdio.d.ts +0 -23
- package/dist/omegga/plugin/plugin_node_safe/proxyOmegga.d.ts +0 -145
- package/dist/omegga/plugin/plugin_node_safe/worker.d.ts +0 -1
- package/dist/omegga/plugin/plugin_node_safe/worker.js +0 -367
- package/dist/omegga/plugin/plugin_node_safe/worker.js.map +0 -1
- package/dist/omegga/plugin/plugin_node_safe.d.ts +0 -23
- package/dist/omegga/plugin/plugin_node_unsafe.d.ts +0 -13
- package/dist/omegga/plugin.d.ts +0 -63
- package/dist/omegga/server.d.ts +0 -166
- package/dist/omegga/types.d.ts +0 -49
- package/dist/omegga/types.js +0 -3
- package/dist/omegga/types.js.map +0 -1
- package/dist/omegga/wrapper.d.ts +0 -32
- package/dist/plugin.d.ts +0 -916
- package/dist/softconfig.d.ts +0 -67
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/updater/index.d.ts +0 -1
- package/dist/updater/index.js +0 -10
- package/dist/updater/index.js.map +0 -1
- package/dist/updater/steam.d.ts +0 -52
- package/dist/util/brdb.d.ts +0 -31
- package/dist/util/brick/checkBounds.d.ts +0 -8
- package/dist/util/brick/constants.d.ts +0 -18
- package/dist/util/brick/displayName.d.ts +0 -7
- package/dist/util/brick/getBounds.d.ts +0 -5
- package/dist/util/brick/getBrickSize.d.ts +0 -3
- package/dist/util/brick/getScaleAxis.d.ts +0 -3
- package/dist/util/brick/index.d.ts +0 -14
- package/dist/util/brick/rotate.d.ts +0 -16
- package/dist/util/brick/setOwnership.d.ts +0 -12
- package/dist/util/chat.d.ts +0 -23
- package/dist/util/color.d.ts +0 -13
- package/dist/util/file.d.ts +0 -5
- package/dist/util/index.d.ts +0 -183
- package/dist/util/map.d.ts +0 -6
- package/dist/util/pattern.d.ts +0 -1
- package/dist/util/time.d.ts +0 -39
- package/dist/util/uuid.d.ts +0 -3
- package/dist/util/wsl.d.ts +0 -2
- package/dist/version.d.ts +0 -2
- package/dist/webserver/backend/api.d.ts +0 -115
- package/dist/webserver/backend/calendar.d.ts +0 -5
- package/dist/webserver/backend/database.d.ts +0 -150
- package/dist/webserver/backend/index.d.ts +0 -30
- package/dist/webserver/backend/metrics.d.ts +0 -3
- package/dist/webserver/backend/types.d.ts +0 -114
- package/dist/webserver/backend/types.js +0 -3
- package/dist/webserver/backend/types.js.map +0 -1
- package/dist/webserver/backend/util.d.ts +0 -2
- package/dist/webserver/index.d.ts +0 -2
- package/dist/webserver/index.js +0 -9
- package/dist/webserver/index.js.map +0 -1
package/dist/cli/plugin.js
CHANGED
|
@@ -1,736 +1,705 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.install = install;
|
|
40
|
-
exports.update = update;
|
|
41
|
-
exports.check = check;
|
|
42
|
-
const logger_1 = __importDefault(require("../logger"));
|
|
43
|
-
const softconfig_1 = __importDefault(require("../softconfig"));
|
|
44
|
-
const config = __importStar(require("../config"));
|
|
45
|
-
const plugin_1 = require("../omegga/plugin");
|
|
46
|
-
const child_process_1 = require("child_process");
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const logger = require("../logger.js");
|
|
4
|
+
const softconfig = require("../softconfig.js");
|
|
5
|
+
const index = require("../config/index.js");
|
|
6
|
+
const plugin = require("../omegga/plugin.js");
|
|
7
|
+
const node_child_process = require("node:child_process");
|
|
47
8
|
require("colors");
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
const exec =
|
|
57
|
-
const MAIN_BRANCHES = [
|
|
58
|
-
// get the working directory for omegga
|
|
9
|
+
const fs = require("node:fs");
|
|
10
|
+
const hasbin = require("hasbin");
|
|
11
|
+
const path = require("node:path");
|
|
12
|
+
const prompts = require("prompts");
|
|
13
|
+
const semver = require("semver");
|
|
14
|
+
const simpleGit = require("simple-git");
|
|
15
|
+
const node_util = require("node:util");
|
|
16
|
+
const version = require("../version.js");
|
|
17
|
+
const exec = node_util.promisify(node_child_process.exec);
|
|
18
|
+
const MAIN_BRANCHES = ["master", "main"];
|
|
59
19
|
function getWorkDir() {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
workDir = '.';
|
|
66
|
-
const confFile = config.find(workDir);
|
|
67
|
-
return confFile
|
|
68
|
-
? path_1.default.resolve(process.cwd(), path_1.default.dirname(confFile))
|
|
69
|
-
: undefined;
|
|
20
|
+
let workDir = index.store.get("defaultOmegga");
|
|
21
|
+
verboseLog("Using working directory", workDir.yellow);
|
|
22
|
+
if (index.find(".")) workDir = ".";
|
|
23
|
+
const confFile = index.find(workDir);
|
|
24
|
+
return confFile ? path.resolve(process.cwd(), path.dirname(confFile)) : void 0;
|
|
70
25
|
}
|
|
71
|
-
const PLUGIN_TYPES = [
|
|
72
|
-
// plugin url transformers
|
|
26
|
+
const PLUGIN_TYPES = ["safe", "safe-ts", "unsafe", "rust", "rpc"];
|
|
73
27
|
const transformers = [
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
28
|
+
{
|
|
29
|
+
// github transformer
|
|
30
|
+
pattern: /^gh:(?<owner>[^/]+)\/(?<repo>[^/]+)$/,
|
|
31
|
+
fn: ({ owner, repo }) => ({
|
|
32
|
+
type: "short",
|
|
33
|
+
name: repo,
|
|
34
|
+
url: `https://github.com/${owner}/omegga-${repo}`
|
|
35
|
+
})
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
// gitlab transformer
|
|
39
|
+
pattern: /^gl:(?<owner>[^/]+)\/(?<repo>[^/]+)$/,
|
|
40
|
+
fn: ({ owner, repo }) => ({
|
|
41
|
+
type: "short",
|
|
42
|
+
name: repo,
|
|
43
|
+
url: `https://gitlab.com/${owner}/omegga-${repo}`
|
|
44
|
+
})
|
|
45
|
+
}
|
|
92
46
|
];
|
|
93
|
-
// convert a shortened url into a full length one
|
|
94
47
|
const transformUrl = (url) => {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return found.fn(url.match(found.pattern).groups);
|
|
48
|
+
const found = transformers.find((t) => url.match(t.pattern));
|
|
49
|
+
if (!found) return { type: "raw", url };
|
|
50
|
+
return found.fn(url.match(found.pattern).groups);
|
|
99
51
|
};
|
|
100
52
|
let needsNL = false;
|
|
101
|
-
// rewrite a console line
|
|
102
53
|
const rewriteLine = (...args) => {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
54
|
+
process.stdout.clearLine(0);
|
|
55
|
+
process.stdout.cursorTo(0);
|
|
56
|
+
process.stdout.write(args.join(" "));
|
|
57
|
+
needsNL = true;
|
|
107
58
|
};
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
console.log(plugin.name, '>>'.green, ...args);
|
|
59
|
+
const plg = (plugin2, ...args) => {
|
|
60
|
+
if (needsNL) {
|
|
61
|
+
needsNL = false;
|
|
62
|
+
console.log();
|
|
63
|
+
}
|
|
64
|
+
console.log(plugin2.name, ">>".green, ...args);
|
|
115
65
|
};
|
|
116
|
-
const plgLog = (
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
else
|
|
120
|
-
rewriteLine(plugin.name, '>>'.green, ...args);
|
|
66
|
+
const plgLog = (plugin2, ...args) => {
|
|
67
|
+
if (logger.default.VERBOSE) plg(plugin2, ...args);
|
|
68
|
+
else rewriteLine(plugin2.name, ">>".green, ...args);
|
|
121
69
|
};
|
|
122
|
-
const plgWarn = (
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
70
|
+
const plgWarn = (plugin2, ...args) => {
|
|
71
|
+
if (needsNL) {
|
|
72
|
+
needsNL = false;
|
|
73
|
+
console.warn();
|
|
74
|
+
}
|
|
75
|
+
console.warn(plugin2.name, "W>".yellow, ...args);
|
|
128
76
|
};
|
|
129
|
-
const plgErr = (
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
77
|
+
const plgErr = (plugin2, ...args) => {
|
|
78
|
+
if (needsNL) {
|
|
79
|
+
needsNL = false;
|
|
80
|
+
console.error();
|
|
81
|
+
}
|
|
82
|
+
console.error(plugin2.name, "!>".red, ...args);
|
|
135
83
|
};
|
|
136
84
|
const err = (...args) => {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
85
|
+
if (needsNL) {
|
|
86
|
+
needsNL = false;
|
|
87
|
+
console.error();
|
|
88
|
+
}
|
|
89
|
+
console.error("!>".red, ...args);
|
|
142
90
|
};
|
|
143
91
|
const log = (...args) => {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
92
|
+
if (needsNL) {
|
|
93
|
+
needsNL = false;
|
|
94
|
+
console.log();
|
|
95
|
+
}
|
|
96
|
+
console.log(">>".green, ...args);
|
|
149
97
|
};
|
|
150
98
|
const verboseLog = (...args) => {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
console.log('V>'.magenta, ...args);
|
|
99
|
+
if (!logger.default.VERBOSE) return;
|
|
100
|
+
if (needsNL) {
|
|
101
|
+
needsNL = false;
|
|
102
|
+
console.log();
|
|
103
|
+
}
|
|
104
|
+
console.log("V>".magenta, ...args);
|
|
158
105
|
};
|
|
159
|
-
function checkPlugin(omeggaPath,
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
106
|
+
function checkPlugin(omeggaPath, plugin2) {
|
|
107
|
+
const pluginPath = path.join(omeggaPath, softconfig.default.PLUGIN_PATH, plugin2.name);
|
|
108
|
+
if (fs.existsSync(path.join(pluginPath, softconfig.default.PLUGIN_FILE))) {
|
|
109
|
+
if (needsNL) {
|
|
110
|
+
console.log();
|
|
111
|
+
needsNL = false;
|
|
112
|
+
}
|
|
113
|
+
plgLog(plugin2, "Checking plugin file...");
|
|
114
|
+
let data;
|
|
115
|
+
try {
|
|
116
|
+
data = JSON.parse(
|
|
117
|
+
fs.readFileSync(path.join(pluginPath, softconfig.default.PLUGIN_FILE), "utf8")
|
|
118
|
+
);
|
|
119
|
+
} catch (e) {
|
|
120
|
+
plgErr(plugin2, "Error reading plugin file", e);
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
if (data.formatVersion !== 1) {
|
|
124
|
+
plgWarn(
|
|
125
|
+
plugin2,
|
|
126
|
+
"WARNING - Plugin file has invalid",
|
|
127
|
+
"formatVersion".yellow + ". Expected",
|
|
128
|
+
"1".yellow
|
|
129
|
+
);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (!data.omeggaVersion || !semver.validRange(data.omeggaVersion)) {
|
|
133
|
+
plgWarn(
|
|
134
|
+
plugin2,
|
|
135
|
+
"WARNING - Plugin file has invalid",
|
|
136
|
+
"omeggaVersion".yellow + ". Expected semver expression"
|
|
137
|
+
);
|
|
138
|
+
return false;
|
|
139
|
+
} else if (!semver.satisfies(version.VERSION, data.omeggaVersion)) {
|
|
140
|
+
plgWarn(
|
|
141
|
+
plugin2,
|
|
142
|
+
`WARNING - Plugin is not made for this version of omegga (${version.VERSION.yellow} vs ${data.omeggaVersion.yellow})`
|
|
143
|
+
);
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
plgLog(plugin2, "Plugin file", "OK".green);
|
|
196
147
|
return true;
|
|
148
|
+
}
|
|
149
|
+
plgWarn(
|
|
150
|
+
plugin2,
|
|
151
|
+
`WARNING - Plugin is missing plugin file (${softconfig.default.PLUGIN_FILE}), this may be a problem in future versions`
|
|
152
|
+
);
|
|
153
|
+
return true;
|
|
197
154
|
}
|
|
198
|
-
// install plugins from a list of plugins
|
|
199
155
|
async function install(plugins, _options) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
156
|
+
const omeggaPath = getWorkDir();
|
|
157
|
+
if (!omeggaPath)
|
|
158
|
+
return err(
|
|
159
|
+
"Not an omegga directory, run ",
|
|
160
|
+
"omegga init".yellow,
|
|
161
|
+
"to setup one."
|
|
162
|
+
);
|
|
163
|
+
log("Attempting to install", (plugins.length + "").yellow, "plugins...");
|
|
164
|
+
for (const pluginUrl of plugins) {
|
|
165
|
+
const plugin2 = transformUrl(pluginUrl);
|
|
166
|
+
if (!("name" in plugin2)) {
|
|
167
|
+
try {
|
|
168
|
+
const { name } = path.parse(plugin2.url);
|
|
169
|
+
plugin2.name = name.replace(/^omegga-/, "");
|
|
170
|
+
} catch (e) {
|
|
171
|
+
console.error("!>".red, "Error parsing name from url", plugin2.url);
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
log(
|
|
176
|
+
"Installing plugin",
|
|
177
|
+
plugin2.name.yellow,
|
|
178
|
+
"from",
|
|
179
|
+
plugin2.url.yellow + "..."
|
|
180
|
+
);
|
|
181
|
+
const pluginPath = path.join(omeggaPath, softconfig.default.PLUGIN_PATH, plugin2.name);
|
|
182
|
+
if (fs.existsSync(pluginPath) && fs.existsSync(path.join(pluginPath, "doc.json"))) {
|
|
183
|
+
plgErr(
|
|
184
|
+
plugin2,
|
|
185
|
+
"Directory already exists! Try",
|
|
186
|
+
("omegga update " + plugin2.name).yellow,
|
|
187
|
+
"or check for plugin name collisions"
|
|
188
|
+
);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (!fs.existsSync(pluginPath)) {
|
|
192
|
+
try {
|
|
193
|
+
fs.mkdirSync(pluginPath, { recursive: true });
|
|
194
|
+
} catch (e) {
|
|
195
|
+
plgErr(plugin2, "Error creating plugin directory", e);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
plgLog(plugin2, "Cloning...");
|
|
200
|
+
const git = simpleGit(pluginPath);
|
|
201
|
+
await git.clone(plugin2.url, pluginPath);
|
|
202
|
+
} catch (e) {
|
|
203
|
+
plgErr(plugin2, "Error cloning plugin", e);
|
|
204
|
+
}
|
|
205
|
+
if (!checkPlugin(omeggaPath, plugin2)) continue;
|
|
206
|
+
const postInstallPath = path.join(pluginPath, softconfig.default.PLUGIN_POSTINSTALL);
|
|
207
|
+
if (fs.existsSync(postInstallPath)) {
|
|
208
|
+
plgLog(plugin2, "Running post install script...");
|
|
209
|
+
try {
|
|
210
|
+
verboseLog("Changing permission of", postInstallPath);
|
|
211
|
+
fs.chmodSync(postInstallPath, "0755");
|
|
212
|
+
verboseLog("Executing bash file");
|
|
213
|
+
let { stdout, stderr } = await exec(postInstallPath, {
|
|
214
|
+
cwd: pluginPath,
|
|
215
|
+
shell: "bash"
|
|
216
|
+
});
|
|
217
|
+
if (stderr.length) plgErr(plugin2, stderr);
|
|
218
|
+
verboseLog(stdout);
|
|
219
|
+
} catch (e) {
|
|
220
|
+
plgErr(plugin2, "Error running post install script:", e);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
269
224
|
}
|
|
270
225
|
async function update(pluginsNames, _options) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
continue;
|
|
328
|
-
}
|
|
329
|
-
// try to correct a weird detached branch
|
|
330
|
-
if (remotes.length === 1 &&
|
|
331
|
-
remotes[0].name === 'origin' &&
|
|
332
|
-
!status.tracking) {
|
|
333
|
-
let skip = false;
|
|
334
|
-
for (const branch of MAIN_BRANCHES) {
|
|
335
|
-
if (branches.current === branch &&
|
|
336
|
-
branches.branches[`remotes/origin/${branch}`]) {
|
|
337
|
-
plgLog(plugin, 'Correcting upstream...');
|
|
338
|
-
try {
|
|
339
|
-
await git.branch({ '--set-upstream-to': `origin/${branch}` });
|
|
340
|
-
status = await git.status();
|
|
341
|
-
break;
|
|
342
|
-
}
|
|
343
|
-
catch (e) {
|
|
344
|
-
plgErr(plugin, 'Error getting status/fixing upstream branch', e);
|
|
345
|
-
skip = true;
|
|
346
|
-
break;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
if (skip)
|
|
351
|
-
continue;
|
|
352
|
-
}
|
|
353
|
-
// this should be corrected by the above check, though if it's not I am not fighting git lol
|
|
354
|
-
if (!status.tracking) {
|
|
355
|
-
plgErr(plugin, 'No upstream branch - ignoring');
|
|
356
|
-
continue;
|
|
357
|
-
}
|
|
358
|
-
// local developers, publish your code please!!! :)
|
|
359
|
-
if (remotes.length === 0) {
|
|
360
|
-
plgErr(plugin, 'No remotes - ignoring');
|
|
361
|
-
continue;
|
|
362
|
-
}
|
|
226
|
+
const omeggaPath = getWorkDir();
|
|
227
|
+
if (!omeggaPath)
|
|
228
|
+
return err(
|
|
229
|
+
"Not an omegga directory, run ",
|
|
230
|
+
"omegga init".yellow,
|
|
231
|
+
"to setup one."
|
|
232
|
+
);
|
|
233
|
+
const pluginFolder = path.join(omeggaPath, softconfig.default.PLUGIN_PATH);
|
|
234
|
+
if (pluginsNames.length === 0) {
|
|
235
|
+
pluginsNames = fs.readdirSync(pluginFolder);
|
|
236
|
+
}
|
|
237
|
+
const plugins = pluginsNames.map((dir) => path.join(pluginFolder, dir)).filter(
|
|
238
|
+
(dir) => fs.existsSync(dir) && fs.lstatSync(dir).isDirectory() && fs.existsSync(path.join(dir, ".git"))
|
|
239
|
+
).map((dir) => ({ name: path.basename(dir) }));
|
|
240
|
+
if (plugins.length === 0) {
|
|
241
|
+
log("Found no plugins that can be updated");
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
log("Checking", (plugins.length + "").yellow, "plugins for updates...");
|
|
245
|
+
let pluginsToUpdate = [];
|
|
246
|
+
for (const plugin2 of plugins) {
|
|
247
|
+
if (needsNL) {
|
|
248
|
+
console.log();
|
|
249
|
+
needsNL = false;
|
|
250
|
+
}
|
|
251
|
+
plgLog(plugin2, "Checking...");
|
|
252
|
+
const pluginPath = path.join(pluginFolder, plugin2.name);
|
|
253
|
+
plugin2.path = pluginPath;
|
|
254
|
+
const git = simpleGit(pluginPath);
|
|
255
|
+
plugin2.git = git;
|
|
256
|
+
if (!await git.checkIsRepo()) {
|
|
257
|
+
plgErr(plugin2, "No git repo detected");
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
let status;
|
|
261
|
+
try {
|
|
262
|
+
status = await git.status();
|
|
263
|
+
} catch (e) {
|
|
264
|
+
plgErr(plugin2, "Error getting status", e);
|
|
265
|
+
}
|
|
266
|
+
try {
|
|
267
|
+
if (status.files.some((f) => f.working_dir !== "?")) {
|
|
268
|
+
plgErr(plugin2, "Detected uncommitted changes - ignoring");
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
const remotes = await git.getRemotes();
|
|
272
|
+
const branches = await git.branch();
|
|
273
|
+
if (!MAIN_BRANCHES.includes(branches.current)) {
|
|
274
|
+
plgErr(plugin2, "Not on a main branch - ignoring");
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
if (remotes.length === 1 && remotes[0].name === "origin" && !status.tracking) {
|
|
278
|
+
let skip = false;
|
|
279
|
+
for (const branch of MAIN_BRANCHES) {
|
|
280
|
+
if (branches.current === branch && branches.branches[`remotes/origin/${branch}`]) {
|
|
281
|
+
plgLog(plugin2, "Correcting upstream...");
|
|
363
282
|
try {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
283
|
+
await git.branch({ "--set-upstream-to": `origin/${branch}` });
|
|
284
|
+
status = await git.status();
|
|
285
|
+
break;
|
|
286
|
+
} catch (e) {
|
|
287
|
+
plgErr(plugin2, "Error getting status/fixing upstream branch", e);
|
|
288
|
+
skip = true;
|
|
289
|
+
break;
|
|
367
290
|
}
|
|
368
|
-
|
|
369
|
-
plgErr(plugin, 'Error fetching remote code', e);
|
|
370
|
-
continue;
|
|
371
|
-
}
|
|
372
|
-
if (status.ahead > 0) {
|
|
373
|
-
plgErr(plugin, 'Detected plugin is ahead - ignoring');
|
|
374
|
-
continue;
|
|
375
|
-
}
|
|
376
|
-
if (status.behind === 0) {
|
|
377
|
-
plgLog(plugin, 'Already up-to-date!'.green);
|
|
378
|
-
continue;
|
|
379
|
-
}
|
|
380
|
-
plgLog(plugin, 'Update available');
|
|
381
|
-
pluginsToUpdate.push(plugin);
|
|
382
|
-
}
|
|
383
|
-
catch (e) {
|
|
384
|
-
plgErr(plugin, 'Error', e);
|
|
291
|
+
}
|
|
385
292
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
293
|
+
if (skip) continue;
|
|
294
|
+
}
|
|
295
|
+
if (!status.tracking) {
|
|
296
|
+
plgErr(plugin2, "No upstream branch - ignoring");
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
if (remotes.length === 0) {
|
|
300
|
+
plgErr(plugin2, "No remotes - ignoring");
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
try {
|
|
304
|
+
plgLog(plugin2, "Fetching...");
|
|
305
|
+
await git.fetch();
|
|
306
|
+
status = await git.status();
|
|
307
|
+
} catch (e) {
|
|
308
|
+
plgErr(plugin2, "Error fetching remote code", e);
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
if (status.ahead > 0) {
|
|
312
|
+
plgErr(plugin2, "Detected plugin is ahead - ignoring");
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
if (status.behind === 0) {
|
|
316
|
+
plgLog(plugin2, "Already up-to-date!".green);
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
plgLog(plugin2, "Update available");
|
|
320
|
+
pluginsToUpdate.push(plugin2);
|
|
321
|
+
} catch (e) {
|
|
322
|
+
plgErr(plugin2, "Error", e);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
if (pluginsToUpdate.length === 0) {
|
|
326
|
+
log("All plugins are currently up-to-date");
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
log("Updating", (pluginsToUpdate.length + "").yellow, "plugins...");
|
|
330
|
+
let updates = 0;
|
|
331
|
+
for (const plugin2 of pluginsToUpdate) {
|
|
332
|
+
const { git } = plugin2;
|
|
333
|
+
if (needsNL) {
|
|
334
|
+
console.log();
|
|
335
|
+
needsNL = false;
|
|
336
|
+
}
|
|
337
|
+
plgLog(plugin2, "Creating backup branch...");
|
|
338
|
+
try {
|
|
339
|
+
const branches = await git.branch();
|
|
340
|
+
const mainBranch = MAIN_BRANCHES.find((b) => branches.branches[b]) ?? MAIN_BRANCHES[0];
|
|
341
|
+
if (branches.branches["omegga-upgrade-backup"]) {
|
|
342
|
+
plgLog(plugin2, "Deleting leftover backup branch...");
|
|
343
|
+
await git.deleteLocalBranch("omegga-upgrade-backup", true);
|
|
344
|
+
}
|
|
345
|
+
await git.checkoutBranch("omegga-upgrade-backup", mainBranch);
|
|
346
|
+
await git.branch({ "--set-upstream-to": `origin/${mainBranch}` });
|
|
347
|
+
await git.checkout(mainBranch);
|
|
348
|
+
plgLog(plugin2, "Pulling update...");
|
|
349
|
+
await git.pull();
|
|
350
|
+
if ((await git.status()).behind > 0) {
|
|
351
|
+
throw "- still behind?";
|
|
352
|
+
}
|
|
353
|
+
plgLog(plugin2, "Checking plugin versions...");
|
|
354
|
+
if (!checkPlugin(omeggaPath, plugin2)) {
|
|
355
|
+
throw "Incompatible";
|
|
356
|
+
}
|
|
357
|
+
const postInstallPath = path.join(plugin2.path, softconfig.default.PLUGIN_POSTINSTALL);
|
|
358
|
+
if (fs.existsSync(postInstallPath)) {
|
|
359
|
+
plgLog(plugin2, "Running post install script...");
|
|
400
360
|
try {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
plgLog(plugin, 'Pulling update...');
|
|
411
|
-
await git.pull();
|
|
412
|
-
if ((await git.status()).behind > 0) {
|
|
413
|
-
throw '- still behind?';
|
|
414
|
-
}
|
|
415
|
-
plgLog(plugin, 'Checking plugin versions...');
|
|
416
|
-
if (!checkPlugin(omeggaPath, plugin)) {
|
|
417
|
-
throw 'Incompatible';
|
|
418
|
-
}
|
|
419
|
-
const postInstallPath = path_1.default.join(plugin.path, softconfig_1.default.PLUGIN_POSTINSTALL);
|
|
420
|
-
if (fs_1.default.existsSync(postInstallPath)) {
|
|
421
|
-
plgLog(plugin, 'Running post install script...');
|
|
422
|
-
try {
|
|
423
|
-
fs_1.default.chmodSync(postInstallPath, '0755');
|
|
424
|
-
let { stdout, stderr } = await exec(postInstallPath, {
|
|
425
|
-
cwd: plugin.path,
|
|
426
|
-
shell: 'bash',
|
|
427
|
-
});
|
|
428
|
-
if (stderr.length)
|
|
429
|
-
plgErr(plugin, stderr);
|
|
430
|
-
verboseLog(stdout);
|
|
431
|
-
}
|
|
432
|
-
catch (e) {
|
|
433
|
-
plgErr(plugin, 'Error running post install script:', e);
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
plgLog(plugin, 'Updated!'.green);
|
|
437
|
-
updates++;
|
|
361
|
+
fs.chmodSync(postInstallPath, "0755");
|
|
362
|
+
let { stdout, stderr } = await exec(postInstallPath, {
|
|
363
|
+
cwd: plugin2.path,
|
|
364
|
+
shell: "bash"
|
|
365
|
+
});
|
|
366
|
+
if (stderr.length) plgErr(plugin2, stderr);
|
|
367
|
+
verboseLog(stdout);
|
|
368
|
+
} catch (e) {
|
|
369
|
+
plgErr(plugin2, "Error running post install script:", e);
|
|
438
370
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
371
|
+
}
|
|
372
|
+
plgLog(plugin2, "Updated!".green);
|
|
373
|
+
updates++;
|
|
374
|
+
} catch (e) {
|
|
375
|
+
plgErr(
|
|
376
|
+
plugin2,
|
|
377
|
+
"Error updating - attempting to restore from backup branch",
|
|
378
|
+
e
|
|
379
|
+
);
|
|
380
|
+
try {
|
|
381
|
+
const branches = await git.branch();
|
|
382
|
+
if (!MAIN_BRANCHES.includes(branches.current)) {
|
|
383
|
+
plgErr(
|
|
384
|
+
plugin2,
|
|
385
|
+
"Not on expected branch - exiting before I break more things"
|
|
386
|
+
);
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
const mainBranch = MAIN_BRANCHES.find((b) => branches.branches[b]) ?? MAIN_BRANCHES[0];
|
|
390
|
+
plg(plugin2, "Resetting current branch");
|
|
391
|
+
await git.reset(simpleGit.ResetMode.HARD);
|
|
392
|
+
plgLog(plugin2, "Attempting to checkout backup branch");
|
|
393
|
+
await git.checkout("omegga-upgrade-backup");
|
|
394
|
+
plgLog(plugin2, `Replacing ${mainBranch} with backup`);
|
|
395
|
+
await git.deleteLocalBranch(mainBranch);
|
|
396
|
+
await git.checkoutBranch(mainBranch, "omegga-upgrade-backup");
|
|
397
|
+
plgLog(plugin2, "Restored to backup branch");
|
|
398
|
+
if ((await git.branch()).current !== mainBranch) {
|
|
399
|
+
plgErr(
|
|
400
|
+
plugin2,
|
|
401
|
+
`Failed to checkout newly created ${mainBranch} branch`
|
|
402
|
+
);
|
|
403
|
+
continue;
|
|
404
|
+
} else {
|
|
405
|
+
plgWarn(plugin2, "Restored from backup and plugin not updated...");
|
|
468
406
|
}
|
|
407
|
+
} catch (e2) {
|
|
408
|
+
plgErr(plugin2, "Error restoring from backup... Whelp...");
|
|
409
|
+
}
|
|
410
|
+
continue;
|
|
469
411
|
}
|
|
470
|
-
|
|
412
|
+
}
|
|
413
|
+
log("Updated", (updates + "").yellow, "plugins!");
|
|
471
414
|
}
|
|
472
415
|
async function check(pluginNames, _options) {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
416
|
+
const omeggaPath = getWorkDir();
|
|
417
|
+
if (!omeggaPath)
|
|
418
|
+
return err(
|
|
419
|
+
"Not an omegga directory, run ",
|
|
420
|
+
"omegga init".yellow,
|
|
421
|
+
"to setup one."
|
|
422
|
+
);
|
|
423
|
+
const pluginFolder = path.join(omeggaPath, softconfig.default.PLUGIN_PATH);
|
|
424
|
+
if (pluginNames.length === 0) {
|
|
425
|
+
pluginNames = fs.readdirSync(pluginFolder);
|
|
426
|
+
}
|
|
427
|
+
const plugins = pluginNames.map((dir) => path.join(pluginFolder, dir)).filter(
|
|
428
|
+
(dir) => fs.existsSync(dir) && fs.lstatSync(dir).isDirectory() && fs.existsSync(path.join(dir, ".git"))
|
|
429
|
+
).map((dir) => ({ name: path.basename(dir) }));
|
|
430
|
+
if (plugins.length === 0) {
|
|
431
|
+
log("Found no plugins that can be checked");
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
log(
|
|
435
|
+
"Checking",
|
|
436
|
+
(plugins.length + "").yellow,
|
|
437
|
+
"plugins for valid plugin files"
|
|
438
|
+
);
|
|
439
|
+
for (const plugin2 of plugins) {
|
|
440
|
+
const pluginPath = path.join(pluginFolder, plugin2.name);
|
|
441
|
+
plugin2.path = pluginPath;
|
|
442
|
+
const git = simpleGit(pluginPath);
|
|
443
|
+
plugin2.git = git;
|
|
444
|
+
if (!await git.checkIsRepo()) {
|
|
445
|
+
plgErr(plugin2, "No git repo detected");
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
checkPlugin(omeggaPath, plugin2);
|
|
449
|
+
}
|
|
450
|
+
console.log();
|
|
505
451
|
}
|
|
506
|
-
const EXECUTABLES = [
|
|
452
|
+
const EXECUTABLES = ["setup.sh", "omegga_plugin"];
|
|
507
453
|
async function init() {
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
}
|
|
597
|
-
|
|
454
|
+
const { author, ...response } = await prompts([
|
|
455
|
+
{
|
|
456
|
+
type: "text",
|
|
457
|
+
name: "name",
|
|
458
|
+
message: "What would you like to " + "name".yellow + " your plugin?",
|
|
459
|
+
validate: (value) => value.match(/^[\w-_]+$/) ? true : "Invalid plugin name!"
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
type: "select",
|
|
463
|
+
name: "type",
|
|
464
|
+
message: "What " + "type".yellow + " of plugin would you like to initialize?",
|
|
465
|
+
choices: [
|
|
466
|
+
{ title: "safe " + "(default)".italic, value: "safe" },
|
|
467
|
+
{ title: "unsafe", value: "unsafe" },
|
|
468
|
+
{ title: "rust", value: "rust" },
|
|
469
|
+
{ title: "rpc", value: "rpc" }
|
|
470
|
+
]
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
type: (prev) => prev == "safe" ? "confirm" : null,
|
|
474
|
+
name: "ts",
|
|
475
|
+
message: "Would you like to use " + "TypeScript".yellow + " in your plugin?",
|
|
476
|
+
initial: false
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
type: "text",
|
|
480
|
+
name: "author",
|
|
481
|
+
message: "Who is the " + "author".yellow + " of this plugin?"
|
|
482
|
+
}
|
|
483
|
+
]);
|
|
484
|
+
const name = response.name;
|
|
485
|
+
const type = response.type == "safe" && response.ts ? "safe-ts" : response.type;
|
|
486
|
+
if (!PLUGIN_TYPES.includes(type)) {
|
|
487
|
+
err("Invalid plugin type", type.red, "!");
|
|
488
|
+
process.exit(1);
|
|
489
|
+
}
|
|
490
|
+
let dest;
|
|
491
|
+
if (!index.find(".")) {
|
|
492
|
+
log(
|
|
493
|
+
"Warning:".yellow,
|
|
494
|
+
"This is not an omegga installation, initializing here instead..."
|
|
495
|
+
);
|
|
496
|
+
dest = `./${name}`;
|
|
497
|
+
} else {
|
|
498
|
+
dest = `./plugins/${name}`;
|
|
499
|
+
if (!fs.existsSync("./plugins")) fs.mkdirSync("./plugins");
|
|
500
|
+
}
|
|
501
|
+
if (fs.existsSync(dest)) {
|
|
502
|
+
err("A directory already exists at the desired plugin location.");
|
|
503
|
+
process.exit(1);
|
|
504
|
+
}
|
|
505
|
+
log("Initializing new", type.yellow, "plugin", name.cyan, "...");
|
|
506
|
+
const templateData = {
|
|
507
|
+
name,
|
|
508
|
+
author: author ?? "AUTHOR",
|
|
509
|
+
omeggaVersion: version.VERSION
|
|
510
|
+
};
|
|
511
|
+
const copyAndRender = async (src2, dest2) => {
|
|
512
|
+
const stats = fs.statSync(src2);
|
|
513
|
+
dest2 = dest2.replace(/\.rename$/, "");
|
|
514
|
+
if (stats.isDirectory()) {
|
|
515
|
+
await fs.promises.mkdir(dest2);
|
|
516
|
+
const contents = await fs.promises.readdir(src2);
|
|
517
|
+
for (const child of contents)
|
|
518
|
+
await copyAndRender(path.join(src2, child), path.join(dest2, child));
|
|
519
|
+
} else {
|
|
520
|
+
const data = (await fs.promises.readFile(src2)).toString();
|
|
521
|
+
const mode = EXECUTABLES.includes(path.basename(dest2)) ? 493 : 420;
|
|
522
|
+
await fs.promises.writeFile(
|
|
523
|
+
dest2,
|
|
524
|
+
data.replace(/{{(\w+)}}/g, (_, p) => templateData[p] ?? `{{${p}}}`),
|
|
525
|
+
{ mode }
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
const src = path.join(__dirname, `../../templates/${type}`);
|
|
530
|
+
verboseLog("Copying and rendering template...");
|
|
531
|
+
await copyAndRender(src, dest);
|
|
532
|
+
if (hasbin.sync("git")) {
|
|
533
|
+
verboseLog("Running", "git init".yellow, "in the new plugin directory ...");
|
|
534
|
+
await exec("git init", { cwd: dest });
|
|
535
|
+
}
|
|
536
|
+
if (fs.existsSync(path.join(src, "package.json"))) {
|
|
537
|
+
verboseLog("Running", "npm i".yellow, "in the new plugin directory ...");
|
|
538
|
+
try {
|
|
539
|
+
await exec("npm i", { cwd: dest });
|
|
540
|
+
} catch (e) {
|
|
541
|
+
log("Warning: npm i".yellow, "failed to execute. Proceeding anyway...");
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
log("Initialized", type.yellow, "plugin", `${name}`.cyan, "successfully!");
|
|
598
545
|
}
|
|
599
546
|
function pluginLoaderFactory() {
|
|
600
|
-
|
|
601
|
-
|
|
547
|
+
const workDir = getWorkDir();
|
|
548
|
+
return new plugin.PluginLoader(workDir);
|
|
602
549
|
}
|
|
603
|
-
/** Loads in a plugin and it's documentation. */
|
|
604
550
|
async function loadPlugin(pluginName) {
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
551
|
+
const pluginLoader = pluginLoaderFactory();
|
|
552
|
+
const foundPluginDirectory = fs.readdirSync(pluginLoader.path).find((dir) => dir.toLowerCase() === pluginName.toLowerCase());
|
|
553
|
+
if (!foundPluginDirectory) {
|
|
554
|
+
err(
|
|
555
|
+
`Plugin ${pluginName} not found! Make sure to use the plugin's directory name.`
|
|
556
|
+
);
|
|
557
|
+
process.exit(1);
|
|
558
|
+
}
|
|
559
|
+
const plugin2 = await pluginLoader.scanPlugin(
|
|
560
|
+
path.join(pluginLoader.path, foundPluginDirectory)
|
|
561
|
+
);
|
|
562
|
+
return plugin2;
|
|
615
563
|
}
|
|
616
564
|
async function listConfig(pluginName, json = false) {
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
565
|
+
const plugin2 = await loadPlugin(pluginName);
|
|
566
|
+
const configDoc = plugin2.getDocumentation().config;
|
|
567
|
+
const config2 = await plugin2.storage.getConfig();
|
|
568
|
+
if (json) {
|
|
569
|
+
console.log(JSON.stringify(config2, null, 2));
|
|
570
|
+
} else {
|
|
571
|
+
for (const key in config2) {
|
|
572
|
+
if (!configDoc[key]) continue;
|
|
573
|
+
const value = config2[key];
|
|
574
|
+
log(
|
|
575
|
+
key.cyan,
|
|
576
|
+
"=",
|
|
577
|
+
["string", "number", "boolean"].includes(typeof value) ? value.toString().yellow : JSON.stringify(value).yellow
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
process.exit();
|
|
634
582
|
}
|
|
635
583
|
async function getConfig(pluginName, configName, json = false) {
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
process.exit();
|
|
584
|
+
const plugin2 = await loadPlugin(pluginName);
|
|
585
|
+
const configDoc = plugin2.getDocumentation().config[configName];
|
|
586
|
+
if (configDoc === void 0) {
|
|
587
|
+
err("Config", configName.cyan, "not found");
|
|
588
|
+
process.exit(1);
|
|
589
|
+
}
|
|
590
|
+
const config2 = await plugin2.storage.getConfig();
|
|
591
|
+
if (json) {
|
|
592
|
+
console.log(JSON.stringify(config2[configName], null, 2));
|
|
593
|
+
} else {
|
|
594
|
+
log(config2[configName]);
|
|
595
|
+
}
|
|
596
|
+
process.exit();
|
|
650
597
|
}
|
|
651
598
|
async function setConfig(pluginName, configName, valueString) {
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
599
|
+
const plugin2 = await loadPlugin(pluginName);
|
|
600
|
+
const configDoc = plugin2.getDocumentation().config[configName];
|
|
601
|
+
if (configDoc === void 0) {
|
|
602
|
+
err("Config", configName.cyan, "not found");
|
|
603
|
+
process.exit(1);
|
|
604
|
+
}
|
|
605
|
+
let parsed;
|
|
606
|
+
switch (configDoc.type) {
|
|
607
|
+
case "boolean":
|
|
608
|
+
parsed = valueString === "true";
|
|
609
|
+
break;
|
|
610
|
+
case "number":
|
|
611
|
+
parsed = Number(valueString);
|
|
612
|
+
if (isNaN(parsed)) {
|
|
613
|
+
err("Invalid number value", valueString.yellow);
|
|
656
614
|
process.exit(1);
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
615
|
+
}
|
|
616
|
+
break;
|
|
617
|
+
case "string":
|
|
618
|
+
parsed = valueString;
|
|
619
|
+
break;
|
|
620
|
+
case "enum":
|
|
621
|
+
if (!configDoc.options.includes(valueString)) {
|
|
622
|
+
err(
|
|
623
|
+
"Config",
|
|
624
|
+
configName.cyan,
|
|
625
|
+
"must be one of",
|
|
626
|
+
configDoc.options.join(", ").yellow
|
|
627
|
+
);
|
|
628
|
+
process.exit(1);
|
|
629
|
+
}
|
|
630
|
+
parsed = valueString;
|
|
631
|
+
break;
|
|
632
|
+
default:
|
|
633
|
+
err("set-context does not support config type", configDoc.type.cyan);
|
|
634
|
+
process.exit(1);
|
|
635
|
+
}
|
|
636
|
+
const pluginConfig = await plugin2.storage.getConfig();
|
|
637
|
+
pluginConfig[configName] = parsed;
|
|
638
|
+
await plugin2.storage.setConfig(pluginConfig);
|
|
639
|
+
log(
|
|
640
|
+
"Set config",
|
|
641
|
+
configName.cyan,
|
|
642
|
+
"of plugin",
|
|
643
|
+
plugin2.getName().cyan,
|
|
644
|
+
"to",
|
|
645
|
+
parsed.toString().yellow
|
|
646
|
+
);
|
|
647
|
+
process.exit();
|
|
690
648
|
}
|
|
691
649
|
async function resetAllConfigs(pluginName, force) {
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
650
|
+
const plugin2 = await loadPlugin(pluginName);
|
|
651
|
+
if (!force) {
|
|
652
|
+
const { answer } = await prompts([
|
|
653
|
+
{
|
|
654
|
+
type: "confirm",
|
|
655
|
+
name: "answer",
|
|
656
|
+
message: "Are you sure you want to reset all configs?",
|
|
657
|
+
initial: false
|
|
658
|
+
}
|
|
659
|
+
]);
|
|
660
|
+
if (!answer) {
|
|
661
|
+
log("Reset aborted.");
|
|
662
|
+
process.exit(1);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
await plugin2.storage.wipeConfig();
|
|
666
|
+
await plugin2.storage.init();
|
|
667
|
+
log("Reset all configs of plugin", plugin2.getName().cyan);
|
|
668
|
+
process.exit();
|
|
711
669
|
}
|
|
712
670
|
async function resetConfig(pluginName, configName) {
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
671
|
+
const plugin2 = await loadPlugin(pluginName);
|
|
672
|
+
const configDoc = plugin2.getDocumentation().config[configName];
|
|
673
|
+
if (configDoc === void 0) {
|
|
674
|
+
err("Config", configName.cyan, "not found");
|
|
675
|
+
process.exit(1);
|
|
676
|
+
}
|
|
677
|
+
const pluginConfig = await plugin2.storage.getConfig();
|
|
678
|
+
pluginConfig[configName] = plugin2.storage.getDefaultConfig()[configName];
|
|
679
|
+
await plugin2.storage.setConfig(pluginConfig);
|
|
680
|
+
log(
|
|
681
|
+
"Reset config",
|
|
682
|
+
configName.cyan,
|
|
683
|
+
"of plugin",
|
|
684
|
+
plugin2.getName().cyan,
|
|
685
|
+
"to",
|
|
686
|
+
pluginConfig[configName]
|
|
687
|
+
);
|
|
688
|
+
process.exit();
|
|
724
689
|
}
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
690
|
+
const _pluginUtil = {
|
|
691
|
+
install,
|
|
692
|
+
update,
|
|
693
|
+
check,
|
|
694
|
+
init,
|
|
695
|
+
listConfig,
|
|
696
|
+
getConfig,
|
|
697
|
+
setConfig,
|
|
698
|
+
resetAllConfigs,
|
|
699
|
+
resetConfig
|
|
735
700
|
};
|
|
736
|
-
|
|
701
|
+
exports.check = check;
|
|
702
|
+
exports.default = _pluginUtil;
|
|
703
|
+
exports.install = install;
|
|
704
|
+
exports.update = update;
|
|
705
|
+
//# sourceMappingURL=plugin.js.map
|