@unitybase/base/argv

Utils for connecting to a local UnityBase server

In case you need to work with command line use a @unitybase/base.options module

Example
const argv = require('@unitybase/base').argv
  // connect to server
  let session = argv.establishConnectionFromCmdLineAttributes()
  console.log('Session.uData:', session.uData, typeof session.uData, session.uData.lang)

  let userLang = session.uData.lang
  let conn = session.connection
  // obtain domain information
  const domainInfo = conn.getDomainInfo()

Classes

ServerSession

Members

findCmdLineSwitch static

Deprecated:
  • Use `options.switchIndex' instead

findCmdLineSwitchValue static

Deprecated:
  • Use `options.switchValue' instead

Methods

getConfigFileName()String inner

Get config file name. if -cfg switch passed then use this switch value, else use default

serverSessionFromCmdLineAttributes()ServerSession inner

Parse cmd line and environment variables for command line parameters expected by UnityBase cmd mode

establishConnectionFromCmdLineAttributes(configopt)ServerSession inner

Service function for establish UnityBase server connection from client-side command line script. Parse command line attributes for switches host, u, p and:

  • Check specified server is started (simple request to host) and if not started then start server locally with local config
  • Establish connection to specified host
  • Retrieve application information and in case authorization is required then call login method using u and p params
  • Return serverSession object with connection in case of success or throw assertion error
Arguments:
  1. [config] (Object)
    Properties
    1. [host] (String)
    2. [user] (String)
    3. [pwd] (String)
    4. forceStartServer=false} (Boolean)  If we sure local server not started - start it without checking. Faster because check take near 2 sec.

checkServerStarted(URL)boolean inner

Perform check somebody listen on URL
Arguments:
  1. URL (String)

getServerConfiguration()Object inner

Read server configuration using file, resolved by argv.getConfigFileName parse it in safe mode, replace environment variables by it values and return parsed config

serverURLFromConfig(config) inner

Return a URL server actually listen on
Arguments:
  1. config (Object)  Server configuration

safeParseJSONfile(fileName, allowMultiLineStringopt, preprocessoropt)Object inner

JSON file parsing, allow to parse semi-JSON files with comments. In case of errors inside JSON show detailed error description
Arguments:
  1. fileName (String)
  2. [allowMultiLineString=false] (Boolean)  Replace \n before parse (not compatible with JSON format, but multiline string is useful)
  3. [preprocessor] (function)  Optional function accept file content transform it and return new content