hackmud-script-manager 0.20.4-9d6d467 → 0.20.4-abe4703

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/bin/hsm.js CHANGED
@@ -12,7 +12,7 @@ import { pull } from "../pull.js"
12
12
  import { syncMacros } from "../syncMacros.js"
13
13
  import "@samual/lib/readDirectoryWithStats"
14
14
  import "@samual/lib/copyFilePersistent"
15
- const version = "0.20.4-9d6d467",
15
+ const version = "0.20.4-abe4703",
16
16
  options = new Map(),
17
17
  commands = [],
18
18
  userColours = new Cache(user => {
@@ -119,25 +119,16 @@ switch (commands[0]) {
119
119
  logHelp()
120
120
  break
121
121
  }
122
- const { push, MissingSourceFolderError, MissingHackmudFolderError, NoUsersError } = await pushModule,
123
- infos = await push(sourcePath, hackmudPath, {
122
+ const { push } = await pushModule
123
+ ;(
124
+ await push(sourcePath, hackmudPath, {
124
125
  scripts,
125
126
  onPush: info => logInfo(info, hackmudPath),
126
127
  minify: shouldMinify,
127
128
  mangleNames: shouldMangleNames,
128
129
  forceQuineCheats: shouldforceQuineCheats
129
130
  })
130
- if (infos instanceof Error) {
131
- logError(infos.message)
132
- if (infos instanceof MissingSourceFolderError || infos instanceof NoUsersError) {
133
- console.log()
134
- logHelp()
135
- } else
136
- infos instanceof MissingHackmudFolderError &&
137
- log(
138
- `If this is not where your hackmud folder is, you can specify it with the\n${colourN("--hackmud-path")}=${colourB("<path>")} option or ${colourN("HSM_HACKMUD_PATH")} environment variable`
139
- )
140
- } else infos.length || logError("Could not find any scripts to push")
131
+ ).length || logError("Could not find any scripts to push")
141
132
  }
142
133
  break
143
134
  case "dev":
@@ -254,7 +245,7 @@ switch (commands[0]) {
254
245
  typeDeclaration = await generateTypeDeclaration(sourcePath, getHackmudPath())
255
246
  let typeDeclarationPath = resolve(outputPath)
256
247
  await writeFile(typeDeclarationPath, typeDeclaration).catch(error => {
257
- assert(error instanceof Error, "src/bin/hsm.ts:340:35")
248
+ assert(error instanceof Error, "src/bin/hsm.ts:327:35")
258
249
  if ("EISDIR" != error.code) throw error
259
250
  typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
260
251
  return writeFile(typeDeclarationPath, typeDeclaration)
package/env.d.ts CHANGED
@@ -4,13 +4,6 @@ type ScriptFailure = { ok: false, msg?: string }
4
4
  type ScriptResponse<T = object> = ScriptSuccess<T> | ScriptFailure
5
5
  type ErrorScripts = Record<string, () => ScriptFailure>
6
6
 
7
- type AllOptional<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? true : false }[keyof T]
8
-
9
- type Scriptor<Args = unknown, Ret = unknown> = {
10
- name: string
11
- call: AllOptional<Args> extends true ? (args?: Args) => Ret : (args: Args) => Ret
12
- }
13
-
14
7
  type Subscripts = Record<string, Record<string, (...args: any) => any>> & {
15
8
  accts: ErrorScripts
16
9
  autos: ErrorScripts
@@ -33,27 +26,23 @@ interface PlayerMidsec {}
33
26
  interface PlayerLowsec {}
34
27
  interface PlayerNullsec {}
35
28
 
36
- type UpgradeRarityString = "`0noob`" | "`1kiddie`" | "`2h4x0r`" | "`3h4rdc0r3`" | "`4|_|b3|2`" | "`531337`"
37
- type UpgradeRarityNumber = 0 | 1 | 2 | 3 | 4 | 5;
38
- type UpgradeRarity = UpgradeRarityString | UpgradeRarityNumber;
39
-
40
- type UpgradeBase = {
29
+ type UpgradeCore = {
41
30
  name: string
42
31
  type: "lock" | "script_space" | "chat" | "script" | "tool" | "bot_brain" | "glam"
43
32
  up_class?: -1 | 0 | 1 | 2 | 3
44
33
  tier: 1 | 2 | 3 | 4
45
- rarity: UpgradeRarityNumber
34
+ rarity: 0 | 1 | 2 | 3 | 4 | 5
46
35
  i: number
47
36
  loaded: boolean
48
37
  sn: string
49
38
  description: string
50
39
  }
51
40
 
52
- type Upgrade = UpgradeBase & Record<string, null | boolean | number | string>
41
+ type Upgrade = UpgradeCore & Record<string, null | boolean | number | string>
53
42
 
54
- type CliUpgrade = Omit<UpgradeBase, `rarity`> & {
43
+ type CLIUpgrade = Omit<UpgradeCore, `rarity`> & {
55
44
  [x: string]: null | boolean | number | string
56
- rarity: UpgradeRarityString
45
+ rarity: "`0noob`" | "`1kiddie`" | "`2h4x0r`" | "`3h4rdc0r3`" | "`4|_|b3|2`" | "`531337`"
57
46
  }
58
47
 
59
48
  type UsersTopItem<R> = { rank: R, name: string, last_activity: string, balance: string }
@@ -151,7 +140,7 @@ type Fullsec = Subscripts & PlayerFullsec & {
151
140
  market: {
152
141
  /** **FULLSEC** */ browse: {
153
142
  (args:
154
- Partial<{ seller: string, listed_before: number, listed_after: number, cost: number | string } & Omit<CliUpgrade, "rarity">>
143
+ Partial<{ seller: string, listed_before: number, listed_after: number, cost: number | string } & Omit<CLIUpgrade, "rarity">>
155
144
  ): { i: string, name: string, rarity: Upgrade["rarity"], cost: number }[] | ScriptFailure
156
145
 
157
146
  <I extends string>(args: { i: I }): {
@@ -420,17 +409,17 @@ type Fullsec = Subscripts & PlayerFullsec & {
420
409
  upgrades_of_owner: {
421
410
  <F extends Partial<Upgrade & { loaded: boolean }> = object>(args?: { filter?: F, full?: false }): (
422
411
  Omit<
423
- Pick<UpgradeBase, "tier" | "rarity" | "name" | "type" | "i" | "loaded">,
412
+ Pick<UpgradeCore, "tier" | "rarity" | "name" | "type" | "i" | "loaded">,
424
413
  keyof F
425
414
  > & Pick<F, "tier" | "rarity" | "name" | "type" | "i" | "loaded">
426
415
  )[] | ScriptFailure
427
416
 
428
417
  <F extends Partial<Upgrade & { loaded: boolean }> = object>(args: { filter?: F, full: true }): (
429
- Omit<UpgradeBase, keyof F> & F & Record<string, null | boolean | number | string>
418
+ Omit<UpgradeCore, keyof F> & F & Record<string, null | boolean | number | string>
430
419
  )[] | ScriptFailure
431
420
 
432
421
  <I extends number>(args: { i: I }): (
433
- Omit<UpgradeBase, "i"> & { [x: string]: null | boolean | number | string, i: I }
422
+ Omit<UpgradeCore, "i"> & { [x: string]: null | boolean | number | string, i: I }
434
423
  ) | ScriptFailure
435
424
  }
436
425
 
@@ -507,7 +496,7 @@ type Highsec = Fullsec & PlayerHighsec & {
507
496
  /** **HIGHSEC** */
508
497
  upgrades: {
509
498
  <I extends number>(args: { i: I }): (
510
- Omit<UpgradeBase, "i"> & { [x: string]: null | boolean | number | string, i: I }
499
+ Omit<UpgradeCore, "i"> & { [x: string]: null | boolean | number | string, i: I }
511
500
  ) | ScriptFailure
512
501
 
513
502
  <F extends Partial<Upgrade & { loaded: boolean }> = object>(args?: {
@@ -515,22 +504,22 @@ type Highsec = Fullsec & PlayerHighsec & {
515
504
  is_script?: true
516
505
  full?: false
517
506
  }): (
518
- Omit<Pick<UpgradeBase, "tier" | "rarity" | "name" | "type" | "i" | "loaded">, keyof F> & F &
507
+ Omit<Pick<UpgradeCore, "tier" | "rarity" | "name" | "type" | "i" | "loaded">, keyof F> & F &
519
508
  Record<string, null | boolean | number | string>
520
509
  )[] | ScriptFailure
521
510
 
522
511
  <F extends Partial<Upgrade & { loaded: boolean }> = object>(args?:
523
512
  { filter?: F, is_script?: true, full: true }
524
- ): (Omit<UpgradeBase, keyof F> & F & Record<string, null | boolean | number | string>)[] | ScriptFailure
513
+ ): (Omit<UpgradeCore, keyof F> & F & Record<string, null | boolean | number | string>)[] | ScriptFailure
525
514
 
526
515
  (args?: { filter?: Partial<Upgrade & { loaded: boolean }>, is_script: false, full?: false }):
527
516
  { msg: string, upgrades: string[] } | ScriptFailure
528
517
 
529
518
  <F extends Partial<Upgrade & { loaded: boolean }> = object>(
530
519
  args?: { filter?: F, is_script: false, full: true }
531
- ): (Omit<UpgradeBase, keyof F | `rarity`> & F & {
520
+ ): (Omit<UpgradeCore, keyof F | `rarity`> & F & {
532
521
  [x: string]: null | boolean | number | string
533
- rarity: UpgradeRarityString
522
+ rarity: "`0noob`" | "`1kiddie`" | "`2h4x0r`" | "`3h4rdc0r3`" | "`4|_|b3|2`" | "`531337`"
534
523
  })[] | ScriptFailure
535
524
  }
536
525
  }
@@ -762,7 +751,7 @@ type Cursor = {
762
751
  ObjectId: () => any
763
752
  }
764
753
 
765
- type CliContext = {
754
+ type CLIContext = {
766
755
  /** The name of the user who is calling the script. */ caller: string
767
756
  /** The name of this script. */ this_script: string
768
757
  /** The number of columns in the caller’s terminal. */ cols: number
@@ -770,23 +759,17 @@ type CliContext = {
770
759
 
771
760
  /** The name of the script that directly called this script, or null if called on the command line or as a
772
761
  * scriptor. */ calling_script: null
773
- is_scriptor?: undefined
774
- is_brain?: undefined
775
762
  }
776
763
 
777
- type SubscriptContext = Replace<CliContext, {
764
+ type SubscriptContext = Replace<CLIContext, {
778
765
  /** The name of the script that directly called this script, or null if called on the command line or as a scriptor.
779
766
  */
780
767
  calling_script: string
781
768
  }>
782
769
 
783
- type ScriptorContext =
784
- Replace<CliContext, { /** Whether the script is being run as a scriptor. */ is_scriptor: true }>
785
-
786
- type BrainContext =
787
- Replace<CliContext, { /** Whether the script is being run via a bot brain. */ is_brain: true }>
788
-
789
- type Context = CliContext | SubscriptContext | ScriptorContext | BrainContext
770
+ type ScriptorContext = CLIContext & { /** Whether the script is being run as a scriptor. */ is_scriptor: true }
771
+ type BrainContext = CLIContext & { /** Whether the script is being run via a bot brain. */ is_brain: true }
772
+ type Context = CLIContext | SubscriptContext | ScriptorContext | BrainContext
790
773
 
791
774
  /** Subscript space that can call FULLSEC scripts. */ declare const $fs: Fullsec
792
775
 
@@ -829,8 +812,6 @@ declare const $0s: typeof $ns
829
812
  * } */
830
813
  declare const $s: Nullsec
831
814
 
832
- type ObjectId = { $oid: string }
833
-
834
815
  declare const $db: {
835
816
  /** Insert a document or documents into a collection.
836
817
  * @param documents A document or array of documents to insert into the collection. */
@@ -924,8 +905,6 @@ declare const $db: {
924
905
  signature: { hash: "Undefined Conversion", keyId: "Undefined Conversion" }
925
906
  }
926
907
  }
927
-
928
- ObjectId: () => ObjectId
929
908
  }
930
909
 
931
910
  /** Debug Log.
@@ -962,7 +941,7 @@ declare const $FMCL: undefined | true
962
941
  * @example
963
942
  * if (!$G.dbCache)
964
943
  * $G.dbCache = $db.f({ whatever: true }).first() */
965
- declare const $G: Record<string | symbol, any>
944
+ declare const $G: any
966
945
 
967
946
  /** This contains a JS timestamp (not Date) set immediately before your code begins running.
968
947
  * @example
@@ -1011,14 +990,3 @@ declare const _FULL_SCRIPT_NAME: string
1011
990
  *
1012
991
  * In rare cases where it's not known at build time, it's `-1`. */
1013
992
  declare const _SECLEVEL: -1 | 0 | 1 | 2 | 3 | 4
1014
-
1015
- type DeepFreeze<T> = { readonly [P in keyof T]: DeepFreeze<T[P]> }
1016
-
1017
- /** Recursively
1018
- * [`Object.freeze()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
1019
- * an object and its properties' objects and its properties' objects and so on.
1020
- *
1021
- * [Official Hackmud Wiki](https://wiki.hackmud.com/scripting/extensions/deep_freeze) */
1022
- declare const DEEP_FREEZE: <T>(value: T) => DeepFreeze<T>
1023
-
1024
- declare const _RUN_ID: string
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hackmud-script-manager",
3
- "version": "0.20.4-9d6d467",
3
+ "version": "0.20.4-abe4703",
4
4
  "description": "Script manager for game hackmud, with minification, TypeScript support, and player script type definition generation.",
5
5
  "keywords": [
6
6
  "api",
package/push.d.ts CHANGED
@@ -18,14 +18,6 @@ export type PushOptions = LaxPartial<{
18
18
  */
19
19
  forceQuineCheats: boolean;
20
20
  }>;
21
- export declare class MissingSourceFolderError extends Error {
22
- }
23
- export declare class MissingHackmudFolderError extends Error {
24
- }
25
- export declare class NoUsersError extends Error {
26
- }
27
- export declare class NoScriptsError extends Error {
28
- }
29
21
  /** Push scripts from a source directory to the hackmud directory.
30
22
  *
31
23
  * Pushes files directly in the source folder to all users
@@ -33,4 +25,4 @@ export declare class NoScriptsError extends Error {
33
25
  * @param hackmudPath directory created by hackmud containing user data including scripts
34
26
  * @param options {@link PushOptions details}
35
27
  * @returns array of info on pushed scripts */
36
- export declare function push(sourcePath: string, hackmudPath: string, { scripts, onPush, minify, mangleNames, forceQuineCheats }?: PushOptions): Promise<MissingSourceFolderError | MissingHackmudFolderError | NoUsersError | NoScriptsError | Info[]>;
28
+ export declare function push(sourcePath: string, hackmudPath: string, { scripts, onPush, minify, mangleNames, forceQuineCheats }?: PushOptions): Promise<Info[]>;
package/push.js CHANGED
@@ -42,37 +42,19 @@ import "./processScript/preprocess.js"
42
42
  import "import-meta-resolve"
43
43
  import "./processScript/transform.js"
44
44
  import "@samual/lib/clearObject"
45
- class MissingSourceFolderError extends Error {}
46
- Object.defineProperty(MissingSourceFolderError.prototype, "name", { value: "MissingSourceFolderError" })
47
- class MissingHackmudFolderError extends Error {}
48
- Object.defineProperty(MissingHackmudFolderError.prototype, "name", { value: "MissingHackmudFolderError" })
49
- class NoUsersError extends Error {}
50
- Object.defineProperty(NoUsersError.prototype, "name", { value: "NoUsersError" })
51
- class NoScriptsError extends Error {}
52
- Object.defineProperty(NoScriptsError.prototype, "name", { value: "NoScriptsError" })
53
45
  async function push(
54
46
  sourcePath,
55
47
  hackmudPath,
56
48
  { scripts = ["*.*"], onPush = () => {}, minify = !0, mangleNames = !1, forceQuineCheats } = {}
57
49
  ) {
58
50
  const [sourceFolder, hackmudFolder] = await Promise.all([
59
- readDirectoryWithStats(sourcePath).catch(error => {
60
- if (error && "ENOENT" == error.code)
61
- return new MissingSourceFolderError("There is no folder at " + sourcePath)
62
- throw error
63
- }),
64
- readDirectoryWithStats(hackmudPath).catch(error => {
65
- if (error && "ENOENT" == error.code)
66
- return new MissingHackmudFolderError("There is no folder at " + hackmudPath)
67
- throw error
68
- })
69
- ])
70
- if (sourceFolder instanceof Error) return sourceFolder
71
- if (hackmudFolder instanceof Error) return hackmudFolder
72
- const sourceFolderFolders = sourceFolder.filter(({ stats }) => stats.isDirectory()),
51
+ readDirectoryWithStats(sourcePath),
52
+ readDirectoryWithStats(hackmudPath)
53
+ ]),
54
+ sourceFolderFolders = sourceFolder.filter(({ stats }) => stats.isDirectory()),
73
55
  allUsers = new Set([
74
56
  ...scripts
75
- .map(scriptName => ensure(scriptName.split(".")[0], "src/push.ts:82:65"))
57
+ .map(scriptName => ensure(scriptName.split(".")[0], "src/push.ts:52:65"))
76
58
  .filter(name => "*" != name),
77
59
  ...sourceFolderFolders.map(({ name }) => name),
78
60
  ...hackmudFolder.filter(({ stats }) => stats.isDirectory()).map(({ name }) => name),
@@ -81,15 +63,13 @@ async function push(
81
63
  .map(({ name }) => name.slice(0, -4))
82
64
  ])
83
65
  if (!allUsers.size)
84
- return new NoUsersError(
85
- "Could not find any users. Either provide the names of your users or log into a user in hackmud"
86
- )
66
+ throw Error("Could not find any users. Either provide the names of your users or log into a user in hackmud.")
87
67
  const usersToScriptsToPush = new Cache(_user => new Map()),
88
68
  scriptNamesToUsers = new Cache(_scriptName => new Set())
89
69
  for (const script of scripts) {
90
70
  const [user, scriptName] = script.split(".")
91
- assert(user, "src/push.ts:105:16")
92
- assert(scriptName, "src/push.ts:106:22")
71
+ assert(user, "src/push.ts:72:16")
72
+ assert(scriptName, "src/push.ts:73:22")
93
73
  "*" == user ? scriptNamesToUsers.set(scriptName, allUsers) : scriptNamesToUsers.get(scriptName).add(user)
94
74
  }
95
75
  const sourceFolderFiles = sourceFolder.filter(({ stats }) => stats.isFile()),
@@ -120,7 +100,7 @@ async function push(
120
100
  for (const [scriptName, users] of scriptNamesToUsers)
121
101
  for (const user of users)
122
102
  if (!usersToScriptsToPush.get(user).has(scriptName))
123
- return new NoScriptsError(`Could not find script ${user}.${scriptName} to push`)
103
+ throw Error(`Could not find script ${user}.${scriptName} to push`)
124
104
  const pathsToUsers = new Cache(_path => new Set())
125
105
  for (const [user, scriptsToPush] of usersToScriptsToPush)
126
106
  for (const path of scriptsToPush.values()) pathsToUsers.get(path).add(user)
@@ -157,4 +137,4 @@ async function push(
157
137
  )
158
138
  return allInfo
159
139
  }
160
- export { MissingHackmudFolderError, MissingSourceFolderError, NoScriptsError, NoUsersError, push }
140
+ export { push }