@amxts/core 0.1.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 (247) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +162 -0
  3. package/README.ru.md +162 -0
  4. package/amxmodx/base/include/amxconst.inc +594 -0
  5. package/amxmodx/base/include/amxmisc.inc +902 -0
  6. package/amxmodx/base/include/amxmodx.inc +3447 -0
  7. package/amxmodx/base/include/amxmodx_version.inc +20 -0
  8. package/amxmodx/base/include/cellarray.inc +525 -0
  9. package/amxmodx/base/include/cellstack.inc +166 -0
  10. package/amxmodx/base/include/celltrie.inc +412 -0
  11. package/amxmodx/base/include/core.inc +202 -0
  12. package/amxmodx/base/include/csstats.inc +298 -0
  13. package/amxmodx/base/include/csstats_const.inc +29 -0
  14. package/amxmodx/base/include/cstrike.inc +1287 -0
  15. package/amxmodx/base/include/cstrike_const.inc +521 -0
  16. package/amxmodx/base/include/csx.inc +259 -0
  17. package/amxmodx/base/include/cvars.inc +547 -0
  18. package/amxmodx/base/include/datapack.inc +161 -0
  19. package/amxmodx/base/include/dbi.inc +154 -0
  20. package/amxmodx/base/include/dodconst.inc +152 -0
  21. package/amxmodx/base/include/dodfun.inc +152 -0
  22. package/amxmodx/base/include/dodstats.inc +69 -0
  23. package/amxmodx/base/include/dodx.inc +161 -0
  24. package/amxmodx/base/include/engine.inc +1343 -0
  25. package/amxmodx/base/include/engine_const.inc +310 -0
  26. package/amxmodx/base/include/engine_stocks.inc +248 -0
  27. package/amxmodx/base/include/esf.inc +70 -0
  28. package/amxmodx/base/include/esf_const.inc +74 -0
  29. package/amxmodx/base/include/fakemeta.inc +1127 -0
  30. package/amxmodx/base/include/fakemeta_const.inc +793 -0
  31. package/amxmodx/base/include/fakemeta_stocks.inc +395 -0
  32. package/amxmodx/base/include/fakemeta_util.inc +882 -0
  33. package/amxmodx/base/include/file.inc +666 -0
  34. package/amxmodx/base/include/float.inc +422 -0
  35. package/amxmodx/base/include/fun.inc +333 -0
  36. package/amxmodx/base/include/gameconfig.inc +93 -0
  37. package/amxmodx/base/include/geoip.inc +264 -0
  38. package/amxmodx/base/include/ham_const.inc +4352 -0
  39. package/amxmodx/base/include/hamsandwich.inc +439 -0
  40. package/amxmodx/base/include/hlsdk_const.inc +808 -0
  41. package/amxmodx/base/include/json.inc +777 -0
  42. package/amxmodx/base/include/lang.inc +119 -0
  43. package/amxmodx/base/include/message_const.inc +1130 -0
  44. package/amxmodx/base/include/message_stocks.inc +161 -0
  45. package/amxmodx/base/include/messages.inc +604 -0
  46. package/amxmodx/base/include/newmenus.inc +387 -0
  47. package/amxmodx/base/include/ns.inc +754 -0
  48. package/amxmodx/base/include/ns_const.inc +196 -0
  49. package/amxmodx/base/include/nvault.inc +154 -0
  50. package/amxmodx/base/include/regex.inc +348 -0
  51. package/amxmodx/base/include/sockets.inc +183 -0
  52. package/amxmodx/base/include/sorting.inc +107 -0
  53. package/amxmodx/base/include/sqlx.inc +582 -0
  54. package/amxmodx/base/include/string.inc +786 -0
  55. package/amxmodx/base/include/string_const.inc +156 -0
  56. package/amxmodx/base/include/string_stocks.inc +325 -0
  57. package/amxmodx/base/include/textparse_ini.inc +214 -0
  58. package/amxmodx/base/include/textparse_smc.inc +261 -0
  59. package/amxmodx/base/include/tfcconst.inc +84 -0
  60. package/amxmodx/base/include/tfcstats.inc +62 -0
  61. package/amxmodx/base/include/tfcx.inc +148 -0
  62. package/amxmodx/base/include/time.inc +118 -0
  63. package/amxmodx/base/include/tsconst.inc +154 -0
  64. package/amxmodx/base/include/tsfun.inc +198 -0
  65. package/amxmodx/base/include/tsstats.inc +65 -0
  66. package/amxmodx/base/include/tsx.inc +88 -0
  67. package/amxmodx/base/include/vault.inc +60 -0
  68. package/amxmodx/base/include/vector.inc +131 -0
  69. package/amxmodx/base/include/xs.inc +1570 -0
  70. package/as/amxts.d.ts +153 -0
  71. package/as/constants.ts +4730 -0
  72. package/as/effects.ts +1449 -0
  73. package/as/entities.ts +5482 -0
  74. package/as/events.ts +3054 -0
  75. package/as/facade.ts +4639 -0
  76. package/as/flags.ts +299 -0
  77. package/as/fs.ts +287 -0
  78. package/as/hooks.ts +18536 -0
  79. package/as/kit.ts +25 -0
  80. package/as/lib/check.ts +86 -0
  81. package/as/modules/http.ts +184 -0
  82. package/as/natives.ts +11845 -0
  83. package/as/os.ts +30 -0
  84. package/as/promise.ts +1392 -0
  85. package/as/promise.types.d.ts +82 -0
  86. package/as/remote.ts +288 -0
  87. package/as/tsconfig.json +22 -0
  88. package/as/vector.ts +65 -0
  89. package/bin/amxts.mjs +10 -0
  90. package/includes/menu_core.inc +355 -0
  91. package/includes/order.txt +54 -0
  92. package/includes/sources.json +27 -0
  93. package/includes/universal_config.inc +355 -0
  94. package/lint/oxlint-plugin.mjs +77 -0
  95. package/node_modules/assemblyscript/LICENSE +201 -0
  96. package/node_modules/assemblyscript/NOTICE +93 -0
  97. package/node_modules/assemblyscript/package.json +63 -0
  98. package/node_modules/assemblyscript/std/README.md +6 -0
  99. package/node_modules/assemblyscript/std/assembly/array.ts +526 -0
  100. package/node_modules/assemblyscript/std/assembly/arraybuffer.ts +77 -0
  101. package/node_modules/assemblyscript/std/assembly/atomics.ts +127 -0
  102. package/node_modules/assemblyscript/std/assembly/bindings/asyncify.ts +16 -0
  103. package/node_modules/assemblyscript/std/assembly/bindings/dom.ts +291 -0
  104. package/node_modules/assemblyscript/std/assembly/bindings/node.ts +6 -0
  105. package/node_modules/assemblyscript/std/assembly/builtins.ts +2631 -0
  106. package/node_modules/assemblyscript/std/assembly/compat.ts +2 -0
  107. package/node_modules/assemblyscript/std/assembly/console.ts +42 -0
  108. package/node_modules/assemblyscript/std/assembly/crypto.ts +9 -0
  109. package/node_modules/assemblyscript/std/assembly/dataview.ts +181 -0
  110. package/node_modules/assemblyscript/std/assembly/date.ts +373 -0
  111. package/node_modules/assemblyscript/std/assembly/diagnostics.ts +11 -0
  112. package/node_modules/assemblyscript/std/assembly/error.ts +44 -0
  113. package/node_modules/assemblyscript/std/assembly/function.ts +38 -0
  114. package/node_modules/assemblyscript/std/assembly/index.d.ts +2822 -0
  115. package/node_modules/assemblyscript/std/assembly/iterator.ts +35 -0
  116. package/node_modules/assemblyscript/std/assembly/map.ts +260 -0
  117. package/node_modules/assemblyscript/std/assembly/math.ts +3289 -0
  118. package/node_modules/assemblyscript/std/assembly/memory.ts +123 -0
  119. package/node_modules/assemblyscript/std/assembly/number.ts +388 -0
  120. package/node_modules/assemblyscript/std/assembly/object.ts +36 -0
  121. package/node_modules/assemblyscript/std/assembly/performance.ts +9 -0
  122. package/node_modules/assemblyscript/std/assembly/polyfills.ts +27 -0
  123. package/node_modules/assemblyscript/std/assembly/process.ts +50 -0
  124. package/node_modules/assemblyscript/std/assembly/reference.ts +48 -0
  125. package/node_modules/assemblyscript/std/assembly/regexp.ts +12 -0
  126. package/node_modules/assemblyscript/std/assembly/rt/README.md +83 -0
  127. package/node_modules/assemblyscript/std/assembly/rt/common.ts +81 -0
  128. package/node_modules/assemblyscript/std/assembly/rt/index-incremental.ts +2 -0
  129. package/node_modules/assemblyscript/std/assembly/rt/index-minimal.ts +2 -0
  130. package/node_modules/assemblyscript/std/assembly/rt/index-stub.ts +1 -0
  131. package/node_modules/assemblyscript/std/assembly/rt/index.d.ts +37 -0
  132. package/node_modules/assemblyscript/std/assembly/rt/itcms.ts +419 -0
  133. package/node_modules/assemblyscript/std/assembly/rt/rtrace.ts +15 -0
  134. package/node_modules/assemblyscript/std/assembly/rt/stub.ts +133 -0
  135. package/node_modules/assemblyscript/std/assembly/rt/tcms.ts +254 -0
  136. package/node_modules/assemblyscript/std/assembly/rt/tlsf.ts +592 -0
  137. package/node_modules/assemblyscript/std/assembly/rt.ts +87 -0
  138. package/node_modules/assemblyscript/std/assembly/set.ts +220 -0
  139. package/node_modules/assemblyscript/std/assembly/shared/feature.ts +65 -0
  140. package/node_modules/assemblyscript/std/assembly/shared/runtime.ts +11 -0
  141. package/node_modules/assemblyscript/std/assembly/shared/target.ts +11 -0
  142. package/node_modules/assemblyscript/std/assembly/shared/tsconfig.json +11 -0
  143. package/node_modules/assemblyscript/std/assembly/shared/typeinfo.ts +72 -0
  144. package/node_modules/assemblyscript/std/assembly/staticarray.ts +401 -0
  145. package/node_modules/assemblyscript/std/assembly/string.ts +847 -0
  146. package/node_modules/assemblyscript/std/assembly/symbol.ts +114 -0
  147. package/node_modules/assemblyscript/std/assembly/table.ts +16 -0
  148. package/node_modules/assemblyscript/std/assembly/tsconfig.json +6 -0
  149. package/node_modules/assemblyscript/std/assembly/typedarray.ts +1945 -0
  150. package/node_modules/assemblyscript/std/assembly/uri.ts +17 -0
  151. package/node_modules/assemblyscript/std/assembly/util/bytes.ts +107 -0
  152. package/node_modules/assemblyscript/std/assembly/util/casemap.ts +497 -0
  153. package/node_modules/assemblyscript/std/assembly/util/error.ts +54 -0
  154. package/node_modules/assemblyscript/std/assembly/util/hash.ts +117 -0
  155. package/node_modules/assemblyscript/std/assembly/util/math.ts +1922 -0
  156. package/node_modules/assemblyscript/std/assembly/util/memory.ts +290 -0
  157. package/node_modules/assemblyscript/std/assembly/util/number.ts +873 -0
  158. package/node_modules/assemblyscript/std/assembly/util/sort.ts +313 -0
  159. package/node_modules/assemblyscript/std/assembly/util/string.ts +1202 -0
  160. package/node_modules/assemblyscript/std/assembly/util/uri.ts +275 -0
  161. package/node_modules/assemblyscript/std/assembly/vector.ts +4 -0
  162. package/node_modules/assemblyscript/std/assembly.json +16 -0
  163. package/node_modules/assemblyscript/std/portable/index.d.ts +462 -0
  164. package/node_modules/assemblyscript/std/portable/index.js +416 -0
  165. package/node_modules/assemblyscript/std/portable.json +11 -0
  166. package/node_modules/assemblyscript/std/types/assembly/index.d.ts +1 -0
  167. package/node_modules/assemblyscript/std/types/assembly/package.json +3 -0
  168. package/node_modules/assemblyscript/std/types/portable/index.d.ts +1 -0
  169. package/node_modules/assemblyscript/std/types/portable/package.json +3 -0
  170. package/node_modules/assemblyscript/tsconfig-base.json +13 -0
  171. package/package.json +112 -0
  172. package/runtime/deps/assemblyscript/LICENSE +201 -0
  173. package/runtime/deps/assemblyscript/NOTICE +93 -0
  174. package/runtime/deps/assemblyscript/bin/asc.js +35 -0
  175. package/runtime/deps/assemblyscript/dist/asc.js +25035 -0
  176. package/runtime/deps/assemblyscript/dist/assemblyscript.js +337 -0
  177. package/runtime/deps/assemblyscript/node_modules/binaryen/LICENSE +201 -0
  178. package/runtime/deps/assemblyscript/node_modules/binaryen/index.js +28905 -0
  179. package/runtime/deps/assemblyscript/node_modules/binaryen/package.json +50 -0
  180. package/runtime/deps/assemblyscript/node_modules/long/LICENSE +202 -0
  181. package/runtime/deps/assemblyscript/node_modules/long/index.js +1581 -0
  182. package/runtime/deps/assemblyscript/node_modules/long/package.json +58 -0
  183. package/runtime/deps/assemblyscript/package.json +114 -0
  184. package/runtime/host/amxts.inc +85 -0
  185. package/runtime/licenses/AMXX-LICENSE.txt +34 -0
  186. package/runtime/licenses/AssemblyScript-LICENSE +201 -0
  187. package/runtime/licenses/AssemblyScript-NOTICE +93 -0
  188. package/runtime/licenses/Binaryen-LICENSE +201 -0
  189. package/runtime/licenses/Bun-LICENSE.md +84 -0
  190. package/runtime/licenses/GPL-3.0.txt +674 -0
  191. package/runtime/licenses/LLVM-LICENSE.TXT +279 -0
  192. package/runtime/licenses/README.md +25 -0
  193. package/runtime/licenses/WAMR-LICENSE +219 -0
  194. package/runtime/natives.txt +1095 -0
  195. package/runtime/patches/README.md +59 -0
  196. package/runtime/patches/assemblyscript-0.28.20-amxts.patch +14174 -0
  197. package/runtime/patches/wamr-2.4.5-amxts.patch +364 -0
  198. package/scripts/apply-docs.ts +508 -0
  199. package/scripts/asc.ts +27 -0
  200. package/scripts/auto-imports.ts +258 -0
  201. package/scripts/build-wasm.ts +595 -0
  202. package/scripts/check.ts +93 -0
  203. package/scripts/compile-cache.ts +179 -0
  204. package/scripts/compile.ts +401 -0
  205. package/scripts/docker-server.ts +73 -0
  206. package/scripts/docs/as/amxts.ts +210 -0
  207. package/scripts/docs/as/effects.ts +1684 -0
  208. package/scripts/docs/as/facade.ts +3302 -0
  209. package/scripts/docs/as/fs.ts +173 -0
  210. package/scripts/docs/as/lib/check.ts +68 -0
  211. package/scripts/docs/as/modules/http.ts +66 -0
  212. package/scripts/docs/as/os.ts +16 -0
  213. package/scripts/docs/as/promise.ts +132 -0
  214. package/scripts/docs/as/promise.types.ts +63 -0
  215. package/scripts/docs/as/vector.ts +48 -0
  216. package/scripts/docs/entities.ts +2338 -0
  217. package/scripts/docs/events.ts +245 -0
  218. package/scripts/docs/game.ts +497 -0
  219. package/scripts/docs/messages.ts +148 -0
  220. package/scripts/file-contents.ts +74 -0
  221. package/scripts/includes.ts +134 -0
  222. package/scripts/player-fields.ts +866 -0
  223. package/scripts/plugin-cache.ts +92 -0
  224. package/scripts/plugin-natives.ts +1157 -0
  225. package/scripts/prebuilt.ts +268 -0
  226. package/scripts/prepare.ts +134 -0
  227. package/scripts/project.ts +973 -0
  228. package/scripts/run.ts +28 -0
  229. package/scripts/shared-modules.ts +906 -0
  230. package/scripts/system.ts +33 -0
  231. package/scripts/tracked-fs.ts +115 -0
  232. package/scripts/typed-configs.ts +788 -0
  233. package/scripts/ui.ts +77 -0
  234. package/src/cli-api.mjs +175 -0
  235. package/src/parser/include-parser.ts +506 -0
  236. package/src/system.mjs +155 -0
  237. package/src/testing/compile-cache.ts +31 -0
  238. package/src/testing/compile.ts +222 -0
  239. package/src/testing/coroutines.ts +191 -0
  240. package/src/testing/index.ts +39 -0
  241. package/src/testing/kits.ts +55 -0
  242. package/src/testing/memory.ts +125 -0
  243. package/src/testing/natives.ts +925 -0
  244. package/src/testing/server.ts +1874 -0
  245. package/src/testing/setup.ts +63 -0
  246. package/src/testing/tables.ts +139 -0
  247. package/src/types.ts +51 -0
package/scripts/ui.ts ADDED
@@ -0,0 +1,77 @@
1
+ // How the build scripts talk, as the amxts command does: colors when the
2
+ // terminal has them, one line per step, and an error as one line with a hint
3
+ // under it. The stack of an error is printed only with --debug (the command
4
+ // passes it on as AMXTS_DEBUG=1).
5
+ import process from 'node:process';
6
+
7
+ /** Whether the output takes colors: a terminal, and NO_COLOR not set; FORCE_COLOR wins. */
8
+ function colorful(stream = process.stdout): boolean {
9
+ if (process.env.FORCE_COLOR && process.env.FORCE_COLOR !== '0') return true;
10
+ if (process.env.NO_COLOR !== undefined || process.env.TERM === 'dumb') return false;
11
+ return Boolean(stream.isTTY);
12
+ }
13
+
14
+ const enabled = colorful();
15
+
16
+ function paint(open: number, close: number) {
17
+ return (text: unknown) => (enabled ? `\x1B[${open}m${text}\x1B[${close}m` : String(text));
18
+ }
19
+
20
+ export const c = {
21
+ bold: paint(1, 22),
22
+ dim: paint(2, 22),
23
+ red: paint(31, 39),
24
+ green: paint(32, 39),
25
+ yellow: paint(33, 39),
26
+ blue: paint(34, 39),
27
+ magenta: paint(35, 39),
28
+ cyan: paint(36, 39),
29
+ gray: paint(90, 39),
30
+ };
31
+
32
+ export const debug = () => process.argv.includes('--debug') || process.env.AMXTS_DEBUG === '1';
33
+
34
+ export const log = {
35
+ info: (text: string) => console.log(`${c.cyan('i')} ${text}`),
36
+ success: (text: string) => console.log(`${c.green('✔')} ${text}`),
37
+ warn: (text: string) => console.log(`${c.yellow('▲')} ${text}`),
38
+ step: (text: string) => console.log(`${c.cyan('◇')} ${text}`),
39
+ error: (text: string) => process.stderr.write(`${c.red('✖')} ${text}\n`),
40
+ hint: (text: string) => process.stderr.write(`${String(text).split('\n').map(line => ` ${c.dim(line)}`).join('\n')}\n`),
41
+ };
42
+
43
+ /** Seconds since `started` (a `performance.now()`), as a report shows them: `3.1s`. */
44
+ export function since(started: number): string {
45
+ return `${((performance.now() - started) / 1000).toFixed(1)}s`;
46
+ }
47
+
48
+ /**
49
+ * A step that takes a while, said as it starts - `◇ compiling hello` - and
50
+ * ended with the line that says it is done, or with none when an error says
51
+ * it instead. In a terminal the step's line is rewritten by its end; in a log
52
+ * (CI, a pipe) the start is a line of its own.
53
+ */
54
+ export function progress(text: string) {
55
+ const live = Boolean(process.stdout.isTTY) && !process.env.CI;
56
+ process.stdout.write(`${c.cyan('◇')} ${text}${live ? '' : '\n'}`);
57
+ return {
58
+ end(done?: string) {
59
+ if (live) process.stdout.write('\r\x1B[2K');
60
+ if (done) log.success(done);
61
+ },
62
+ };
63
+ }
64
+
65
+ /**
66
+ * An error, printed as the user should see it: its first line, then the rest
67
+ * of it - or its `hint`, what to do about it; the stack only with --debug.
68
+ */
69
+ export function report(error: unknown): void {
70
+ const hint = error instanceof Error && 'hint' in error && typeof error.hint === 'string' ? error.hint : undefined;
71
+ const [first, ...rest] = (error instanceof Error ? error.message : String(error)).trim().split('\n');
72
+ log.error(first);
73
+ if (rest.length) process.stderr.write(`${rest.map(line => ` ${line}`).join('\n')}\n`);
74
+ if (hint) log.hint(hint);
75
+ else if (!debug()) log.hint('Run it again with --debug to see where it happened.');
76
+ if (debug() && error instanceof Error && error.stack) process.stderr.write(`${c.gray(error.stack)}\n`);
77
+ }
@@ -0,0 +1,175 @@
1
+ // What the amxts command asks of the core: `@amxts/core/cli-api`.
2
+ //
3
+ // The command is its own package, @amxts/cli. It finds the core a project
4
+ // installed and imports this file - never a path inside the core - so the
5
+ // core can move its scripts without breaking it.
6
+ // Plain JavaScript: the command runs on Node, and so does this file; what
7
+ // compiles runs on Bun, as a task the command starts.
8
+ //
9
+ // const core = await import('@amxts/core/cli-api');
10
+ // core.cliApi 3 - the contract below; the command checks it
11
+ // core.task('build', ['--deploy']) { runtime: 'bun', args: [...] }
12
+ // core.includeSources().reapi the ReAPI release the API is built from
13
+ // core.bunBinary() the Bun the tasks run on, installed with the core
14
+ // core.serverSystem([], env) { system: 'linux', from: 'server', reason: 'hlds_linux' }
15
+ import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
16
+ import { createRequire } from 'node:module';
17
+ import { dirname, join, resolve } from 'node:path';
18
+ import process from 'node:process';
19
+ import { fileURLToPath } from 'node:url';
20
+ import { wamrcPath } from './system.mjs';
21
+
22
+ /** The core's folder: the package this file ships in. */
23
+ export const coreDir = resolve(dirname(fileURLToPath(import.meta.url)), '..');
24
+
25
+ const pkg = JSON.parse(readFileSync(join(coreDir, 'package.json'), 'utf8'));
26
+
27
+ /** The core's version. */
28
+ export const version = String(pkg.version);
29
+
30
+ /**
31
+ * The version of this contract. It goes up when a task, an export or what one
32
+ * returns changes in a way an older command would misread; the command says
33
+ * which of the two to update when they differ.
34
+ */
35
+ export const cliApi = 3;
36
+
37
+ /** Whether the core runs from a checkout (a .git folder beside it) rather than from npm. */
38
+ export const fromSource = existsSync(join(coreDir, '.git'));
39
+
40
+ const require = createRequire(import.meta.url);
41
+
42
+ /**
43
+ * The official modules this core is developed with, from folders on this
44
+ * machine: its package.json's `file:` links, by package name. Until the
45
+ * modules are on npm, `--local` takes them from here.
46
+ *
47
+ * @returns {Record<string, string>} the package's name and its folder
48
+ */
49
+ export function localModules() {
50
+ const deps = { ...pkg.dependencies, ...pkg.devDependencies };
51
+ const found = {};
52
+ for (const [name, spec] of Object.entries(deps)) {
53
+ if (typeof spec !== 'string' || !spec.startsWith('file:') || !name.startsWith('@amxts/')) continue;
54
+ const dir = resolve(coreDir, spec.slice(5));
55
+ if (existsSync(join(dir, 'package.json')) && JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')).amxts?.module) found[name] = dir;
56
+ }
57
+ return found;
58
+ }
59
+
60
+ /** The scripts a task runs, each with Bun through scripts/run.ts. */
61
+ const SCRIPTS = {
62
+ prepare: 'prepare.ts',
63
+ build: 'build-wasm.ts',
64
+ check: 'check.ts',
65
+ };
66
+
67
+ /**
68
+ * @typedef {object} Task
69
+ * @property {'bun' | 'node'} runtime what runs it
70
+ * @property {string[]} args its arguments, the script first; the project is the current folder
71
+ */
72
+
73
+ /**
74
+ * How to run one of the core's tasks in the current folder:
75
+ *
76
+ * - `prepare` writes .amxts/tsconfig.json;
77
+ * - `build` builds the plugins and the modules (`--deploy`, `--watch`, and
78
+ * `--docker`: for the Docker server that mounts the project - no deploy,
79
+ * Linux only, its console shown);
80
+ * - `check` checks a module package before it is published;
81
+ * - `typecheck` runs TypeScript over the project, after `prepare`.
82
+ *
83
+ * A failure is printed by the task itself and ends it with a non-zero code.
84
+ *
85
+ * @param {string} name
86
+ * @param {string[]} [args]
87
+ * @returns {Task} what runs it, and its arguments
88
+ */
89
+ export function task(name, args = []) {
90
+ if (name === 'typecheck') {
91
+ return { runtime: 'node', args: [require.resolve('typescript/bin/tsc'), '--noEmit', '-p', '.amxts/tsconfig.json', ...args] };
92
+ }
93
+ const script = SCRIPTS[name];
94
+ if (!script) throw new Error(`@amxts/core ${version} has no task "${name}"`);
95
+ return { runtime: 'bun', args: [join(coreDir, 'scripts', 'run.ts'), script, ...args] };
96
+ }
97
+
98
+ /**
99
+ * The third-party includes this core's API is generated from, as
100
+ * includes/sources.json pins them, by id: `reapi`, `easy_http`, `resemiclip`,
101
+ * each `{ name, version, license, home, url, sha256, include? }` - `url` gives
102
+ * a file whose sha256 is `sha256`; for a .zip, `include` is the folder in it
103
+ * whose .inc files are the includes. The command fetches ReAPI's for a
104
+ * project without a server by these.
105
+ *
106
+ * @returns {Record<string, { name: string, version: string, license: string, home: string, url: string, sha256: string, include?: string }>} the sources
107
+ */
108
+ export function includeSources() {
109
+ return JSON.parse(readFileSync(join(coreDir, 'includes', 'sources.json'), 'utf8'));
110
+ }
111
+
112
+ /**
113
+ * The Bun a `bun` task runs on: the binary of the `bun` package the core
114
+ * depends on, so a project needs no Bun of its own. It is looked for in the
115
+ * platform package (`@oven/bun-<os>-<arch>`), which every package manager
116
+ * installs as an optional dependency without running a script, then where
117
+ * `bun`'s own postinstall puts it (`bun/bin/bun.exe`, a placeholder until
118
+ * then). Null when neither is there - the command then takes a Bun on PATH.
119
+ *
120
+ * @returns {string | null} the binary's path
121
+ */
122
+ export function bunBinary() {
123
+ let bunDir;
124
+ try {
125
+ bunDir = dirname(require.resolve('bun/package.json'));
126
+ } catch {
127
+ return null;
128
+ }
129
+ const from = createRequire(join(bunDir, 'package.json'));
130
+ const os = process.platform === 'win32' ? 'windows' : process.platform;
131
+ const arch = process.arch === 'arm64' ? 'aarch64' : process.arch;
132
+ // On musl (Alpine) only the -musl build runs; a package manager that does
133
+ // not read `libc` may have installed the glibc one beside it.
134
+ const musl = process.platform === 'linux' && !process.report?.getReport?.().header?.glibcVersionRuntime;
135
+ const exe = process.platform === 'win32' ? 'bun.exe' : 'bun';
136
+ try {
137
+ const binary = join(dirname(from.resolve(`@oven/bun-${os}-${arch}${musl ? '-musl' : ''}/package.json`)), 'bin', exe);
138
+ if (existsSync(binary)) return binary;
139
+ } catch {}
140
+ // The placeholder is a few hundred bytes; the binary is tens of megabytes.
141
+ const placed = join(bunDir, 'bin', 'bun.exe');
142
+ return existsSync(placed) && statSync(placed).size > 1_000_000 ? placed : null;
143
+ }
144
+
145
+ /**
146
+ * The system of the server a build compiles for - Windows or Linux - and how
147
+ * that was decided: `--os` in `argv`, AMXTS_SERVER_OS, what the AMXTS_SERVER
148
+ * folder holds (hlds_linux or hlds.exe, else its modules), this machine's.
149
+ * `describeSystem` writes it as the build reports it: "Linux (hlds_linux)".
150
+ */
151
+ export { describeSystem, serverSystem } from './system.mjs';
152
+
153
+ /** The TypeScript the core builds with: the command reads amxts.config.ts with its parser. */
154
+ export function typescript() {
155
+ return require('typescript');
156
+ }
157
+
158
+ /**
159
+ * The patched compilers the build runs: the version each patch is for, and
160
+ * whether its build is there.
161
+ */
162
+ export function toolchain() {
163
+ const patches = existsSync(join(coreDir, 'runtime', 'patches')) ? readdirSync(join(coreDir, 'runtime', 'patches')) : [];
164
+ const patched = name => patches.map(file => file.match(new RegExp(`^${name}-(.+)-amxts\\.patch$`))?.[1]).find(Boolean) ?? null;
165
+ return {
166
+ assemblyscript: {
167
+ version: patched('assemblyscript'),
168
+ built: existsSync(process.env.AMXTS_ASC ?? join(coreDir, 'runtime/deps/assemblyscript/bin/asc.js')),
169
+ },
170
+ wamr: {
171
+ version: patched('wamr'),
172
+ wamrc: existsSync(wamrcPath()),
173
+ },
174
+ };
175
+ }