hackmud-script-manager 0.20.4-9596502 → 0.20.4-9d6d467
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 +13 -5
 - package/package.json +1 -1
 - package/push.d.ts +5 -1
 - package/push.js +12 -6
 
    
        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- 
     | 
| 
      
 15 
     | 
    
         
            +
            const version = "0.20.4-9d6d467",
         
     | 
| 
       16 
16 
     | 
    
         
             
            	options = new Map(),
         
     | 
| 
       17 
17 
     | 
    
         
             
            	commands = [],
         
     | 
| 
       18 
18 
     | 
    
         
             
            	userColours = new Cache(user => {
         
     | 
| 
         @@ -119,7 +119,7 @@ switch (commands[0]) { 
     | 
|
| 
       119 
119 
     | 
    
         
             
            				logHelp()
         
     | 
| 
       120 
120 
     | 
    
         
             
            				break
         
     | 
| 
       121 
121 
     | 
    
         
             
            			}
         
     | 
| 
       122 
     | 
    
         
            -
            			const { push } = await pushModule,
         
     | 
| 
      
 122 
     | 
    
         
            +
            			const { push, MissingSourceFolderError, MissingHackmudFolderError, NoUsersError } = await pushModule,
         
     | 
| 
       123 
123 
     | 
    
         
             
            				infos = await push(sourcePath, hackmudPath, {
         
     | 
| 
       124 
124 
     | 
    
         
             
            					scripts,
         
     | 
| 
       125 
125 
     | 
    
         
             
            					onPush: info => logInfo(info, hackmudPath),
         
     | 
| 
         @@ -127,9 +127,17 @@ switch (commands[0]) { 
     | 
|
| 
       127 
127 
     | 
    
         
             
            					mangleNames: shouldMangleNames,
         
     | 
| 
       128 
128 
     | 
    
         
             
            					forceQuineCheats: shouldforceQuineCheats
         
     | 
| 
       129 
129 
     | 
    
         
             
            				})
         
     | 
| 
       130 
     | 
    
         
            -
            			infos instanceof Error  
     | 
| 
      
 130 
     | 
    
         
            +
            			if (infos instanceof Error) {
         
     | 
| 
       131 
131 
     | 
    
         
             
            				logError(infos.message)
         
     | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
      
 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")
         
     | 
| 
       133 
141 
     | 
    
         
             
            		}
         
     | 
| 
       134 
142 
     | 
    
         
             
            		break
         
     | 
| 
       135 
143 
     | 
    
         
             
            	case "dev":
         
     | 
| 
         @@ -246,7 +254,7 @@ switch (commands[0]) { 
     | 
|
| 
       246 
254 
     | 
    
         
             
            				typeDeclaration = await generateTypeDeclaration(sourcePath, getHackmudPath())
         
     | 
| 
       247 
255 
     | 
    
         
             
            			let typeDeclarationPath = resolve(outputPath)
         
     | 
| 
       248 
256 
     | 
    
         
             
            			await writeFile(typeDeclarationPath, typeDeclaration).catch(error => {
         
     | 
| 
       249 
     | 
    
         
            -
            				assert(error instanceof Error, "src/bin/hsm.ts: 
     | 
| 
      
 257 
     | 
    
         
            +
            				assert(error instanceof Error, "src/bin/hsm.ts:340:35")
         
     | 
| 
       250 
258 
     | 
    
         
             
            				if ("EISDIR" != error.code) throw error
         
     | 
| 
       251 
259 
     | 
    
         
             
            				typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
         
     | 
| 
       252 
260 
     | 
    
         
             
            				return writeFile(typeDeclarationPath, typeDeclaration)
         
     | 
    
        package/package.json
    CHANGED
    
    
    
        package/push.d.ts
    CHANGED
    
    | 
         @@ -22,6 +22,10 @@ export declare class MissingSourceFolderError extends Error { 
     | 
|
| 
       22 
22 
     | 
    
         
             
            }
         
     | 
| 
       23 
23 
     | 
    
         
             
            export declare class MissingHackmudFolderError extends Error {
         
     | 
| 
       24 
24 
     | 
    
         
             
            }
         
     | 
| 
      
 25 
     | 
    
         
            +
            export declare class NoUsersError extends Error {
         
     | 
| 
      
 26 
     | 
    
         
            +
            }
         
     | 
| 
      
 27 
     | 
    
         
            +
            export declare class NoScriptsError extends Error {
         
     | 
| 
      
 28 
     | 
    
         
            +
            }
         
     | 
| 
       25 
29 
     | 
    
         
             
            /** Push scripts from a source directory to the hackmud directory.
         
     | 
| 
       26 
30 
     | 
    
         
             
              *
         
     | 
| 
       27 
31 
     | 
    
         
             
              * Pushes files directly in the source folder to all users
         
     | 
| 
         @@ -29,4 +33,4 @@ export declare class MissingHackmudFolderError extends Error { 
     | 
|
| 
       29 
33 
     | 
    
         
             
              * @param hackmudPath directory created by hackmud containing user data including scripts
         
     | 
| 
       30 
34 
     | 
    
         
             
              * @param options {@link PushOptions details}
         
     | 
| 
       31 
35 
     | 
    
         
             
              * @returns array of info on pushed scripts */
         
     | 
| 
       32 
     | 
    
         
            -
            export declare function push(sourcePath: string, hackmudPath: string, { scripts, onPush, minify, mangleNames, forceQuineCheats }?: PushOptions): Promise<MissingSourceFolderError | MissingHackmudFolderError | Info[]>;
         
     | 
| 
      
 36 
     | 
    
         
            +
            export declare function push(sourcePath: string, hackmudPath: string, { scripts, onPush, minify, mangleNames, forceQuineCheats }?: PushOptions): Promise<MissingSourceFolderError | MissingHackmudFolderError | NoUsersError | NoScriptsError | Info[]>;
         
     | 
    
        package/push.js
    CHANGED
    
    | 
         @@ -46,6 +46,10 @@ class MissingSourceFolderError extends Error {} 
     | 
|
| 
       46 
46 
     | 
    
         
             
            Object.defineProperty(MissingSourceFolderError.prototype, "name", { value: "MissingSourceFolderError" })
         
     | 
| 
       47 
47 
     | 
    
         
             
            class MissingHackmudFolderError extends Error {}
         
     | 
| 
       48 
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" })
         
     | 
| 
       49 
53 
     | 
    
         
             
            async function push(
         
     | 
| 
       50 
54 
     | 
    
         
             
            	sourcePath,
         
     | 
| 
       51 
55 
     | 
    
         
             
            	hackmudPath,
         
     | 
| 
         @@ -68,7 +72,7 @@ async function push( 
     | 
|
| 
       68 
72 
     | 
    
         
             
            	const sourceFolderFolders = sourceFolder.filter(({ stats }) => stats.isDirectory()),
         
     | 
| 
       69 
73 
     | 
    
         
             
            		allUsers = new Set([
         
     | 
| 
       70 
74 
     | 
    
         
             
            			...scripts
         
     | 
| 
       71 
     | 
    
         
            -
            				.map(scriptName => ensure(scriptName.split(".")[0], "src/push.ts: 
     | 
| 
      
 75 
     | 
    
         
            +
            				.map(scriptName => ensure(scriptName.split(".")[0], "src/push.ts:82:65"))
         
     | 
| 
       72 
76 
     | 
    
         
             
            				.filter(name => "*" != name),
         
     | 
| 
       73 
77 
     | 
    
         
             
            			...sourceFolderFolders.map(({ name }) => name),
         
     | 
| 
       74 
78 
     | 
    
         
             
            			...hackmudFolder.filter(({ stats }) => stats.isDirectory()).map(({ name }) => name),
         
     | 
| 
         @@ -77,13 +81,15 @@ async function push( 
     | 
|
| 
       77 
81 
     | 
    
         
             
            				.map(({ name }) => name.slice(0, -4))
         
     | 
| 
       78 
82 
     | 
    
         
             
            		])
         
     | 
| 
       79 
83 
     | 
    
         
             
            	if (!allUsers.size)
         
     | 
| 
       80 
     | 
    
         
            -
            		 
     | 
| 
      
 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 
     | 
    
         
            +
            		)
         
     | 
| 
       81 
87 
     | 
    
         
             
            	const usersToScriptsToPush = new Cache(_user => new Map()),
         
     | 
| 
       82 
88 
     | 
    
         
             
            		scriptNamesToUsers = new Cache(_scriptName => new Set())
         
     | 
| 
       83 
89 
     | 
    
         
             
            	for (const script of scripts) {
         
     | 
| 
       84 
90 
     | 
    
         
             
            		const [user, scriptName] = script.split(".")
         
     | 
| 
       85 
     | 
    
         
            -
            		assert(user, "src/push.ts: 
     | 
| 
       86 
     | 
    
         
            -
            		assert(scriptName, "src/push.ts: 
     | 
| 
      
 91 
     | 
    
         
            +
            		assert(user, "src/push.ts:105:16")
         
     | 
| 
      
 92 
     | 
    
         
            +
            		assert(scriptName, "src/push.ts:106:22")
         
     | 
| 
       87 
93 
     | 
    
         
             
            		"*" == user ? scriptNamesToUsers.set(scriptName, allUsers) : scriptNamesToUsers.get(scriptName).add(user)
         
     | 
| 
       88 
94 
     | 
    
         
             
            	}
         
     | 
| 
       89 
95 
     | 
    
         
             
            	const sourceFolderFiles = sourceFolder.filter(({ stats }) => stats.isFile()),
         
     | 
| 
         @@ -114,7 +120,7 @@ async function push( 
     | 
|
| 
       114 
120 
     | 
    
         
             
            	for (const [scriptName, users] of scriptNamesToUsers)
         
     | 
| 
       115 
121 
     | 
    
         
             
            		for (const user of users)
         
     | 
| 
       116 
122 
     | 
    
         
             
            			if (!usersToScriptsToPush.get(user).has(scriptName))
         
     | 
| 
       117 
     | 
    
         
            -
            				 
     | 
| 
      
 123 
     | 
    
         
            +
            				return new NoScriptsError(`Could not find script ${user}.${scriptName} to push`)
         
     | 
| 
       118 
124 
     | 
    
         
             
            	const pathsToUsers = new Cache(_path => new Set())
         
     | 
| 
       119 
125 
     | 
    
         
             
            	for (const [user, scriptsToPush] of usersToScriptsToPush)
         
     | 
| 
       120 
126 
     | 
    
         
             
            		for (const path of scriptsToPush.values()) pathsToUsers.get(path).add(user)
         
     | 
| 
         @@ -151,4 +157,4 @@ async function push( 
     | 
|
| 
       151 
157 
     | 
    
         
             
            	)
         
     | 
| 
       152 
158 
     | 
    
         
             
            	return allInfo
         
     | 
| 
       153 
159 
     | 
    
         
             
            }
         
     | 
| 
       154 
     | 
    
         
            -
            export { MissingHackmudFolderError, MissingSourceFolderError, push }
         
     | 
| 
      
 160 
     | 
    
         
            +
            export { MissingHackmudFolderError, MissingSourceFolderError, NoScriptsError, NoUsersError, push }
         
     |