@@ -237,8 +237,38 @@ switch (commands[0]) {
237237 scripts . push ( `*.*` )
238238
239239 if ( commands [ 0 ] == `push` ) {
240+ const dtsPathOption = popOption ( `dts-path` )
241+
240242 complainAboutUnrecognisedOptions ( )
241243
244+ let declarationPathPromise
245+
246+ if ( dtsPathOption ) {
247+ if ( typeof dtsPathOption . value != `string` ) {
248+ logError (
249+ `Option ${ colourN ( dtsPathOption . name ) } must be a string, got ${ colourV ( dtsPathOption . value )
250+ } \n`
251+ )
252+
253+ logHelp ( )
254+ process . exit ( 1 )
255+ }
256+
257+ let typeDeclarationPath = resolvePath ( dtsPathOption . value )
258+ const typeDeclaration = await generateTypeDeclaration ( sourcePath , hackmudPath )
259+
260+ declarationPathPromise = writeFile ( typeDeclarationPath , typeDeclaration ) . catch ( error => {
261+ assert ( error instanceof Error , HERE )
262+
263+ if ( ( error as NodeJS . ErrnoException ) . code != `EISDIR` )
264+ throw error
265+
266+ typeDeclarationPath = resolvePath ( typeDeclarationPath , `player.d.ts` )
267+
268+ return writeFile ( typeDeclarationPath , typeDeclaration )
269+ } ) . then ( ( ) => typeDeclarationPath )
270+ }
271+
242272 const { push, MissingSourceFolderError, MissingHackmudFolderError, NoUsersError } = await pushModule
243273
244274 const infos = await push ( sourcePath , hackmudPath , {
@@ -263,6 +293,9 @@ ${colourN(`--hackmud-path`)}=${colourB(`<path>`)} option or ${colourN(`HSM_HACKM
263293 }
264294 } else if ( ! infos . length )
265295 logError ( `Could not find any scripts to push` )
296+
297+ if ( declarationPathPromise )
298+ log ( `Wrote type declaration to ${ chalk . bold ( await declarationPathPromise ) } ` )
266299 } else {
267300 const dtsPathOption =
268301 popOption ( `dts-path` , `type-declaration-path` , `type-declaration` , `dts` , `gen-types` )
@@ -428,9 +461,8 @@ ${colourN(`--mangle-names`)}
428461${ colourN ( `--force-quine-cheats` ) }
429462 ${ forceQuineCheatsOptionDescription }
430463${ hackmudPathOption }
431- ${ commands [ 0 ] == `push` ? `` : ` ${ colourN ( `--dts-path` ) } =${ colourB ( `<path>` ) }
464+ ${ colourN ( `--dts-path` ) } =${ colourB ( `<path>` ) }
432465 Path to generate a type declaration (.d.ts) file for the scripts
433- ` } \
434466
435467${ colourA ( `Examples:` ) }
436468${ colourC ( `hsm` ) } ${ colourL ( commands [ 0 ] ) } ${ colourV ( `src` ) }
0 commit comments