setupEnvironment = args => {
  patchEnvPath()

  const isDevMode = process.env.NODE_ENV !== 'production'
  const debug = args['--debug'] || !!process.env.MARKTEXT_DEBUG || process.env.NODE_ENV !== 'production'
  const verbose = args['--verbose'] || 0
  const safeMode = args['--safe']
  const userDataPath = args['--user-data-dir'] // or null (= default user data path)
  const disableSpellcheck = args['--disable-spellcheck']

  const appEnvironment = new AppEnvironment({
    debug,
    isDevMode,
    verbose,
    safeMode,
    userDataPath,
    disableSpellcheck
  })

  ensureAppDirectoriesSync(appEnvironment.paths)

  // Keep this for easier access.
  global.MARKTEXT_DEBUG = debug
  global.MARKTEXT_DEBUG_VERBOSE = verbose
  global.MARKTEXT_SAFE_MODE = safeMode

  return appEnvironment
}
Create a (global) application environment instance and bootstraps the application.

@param {arg.Result} args The parsed application arguments.
@returns {AppEnvironment} The current (global) environment.