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