code: function connect(devicePath, exitCallback) {
    if (args.ideServer) log("WARNING: --ide specified, but no terminal. Don't specify a file/expression to upload.");
    if (!args.quiet) if (! args.nosend) log("Connecting to '"+devicePath+"'");
    var currentLine = "";
    var exitTimeout;
    // Handle received data
    Espruino.Core.Serial.startListening(function(data) {
     data = String.fromCharCode.apply(null, new Uint8Array(data));
     currentLine += data;
     while (currentLine.indexOf("\n")>=0) {
       var i = currentLine.indexOf("\n");
       log(args.espruinoPrefix + currentLine.substr(0,i)+args.espruinoPostfix);
       currentLine = currentLine.substr(i+1);
     }
     // if we're waiting to exit, make sure we wait until nothing has been printed
     if (exitTimeout && exitCallback) {
       clearTimeout(exitTimeout);
       exitTimeout = setTimeout(exitCallback, 500);
     }
    });
    if (! args.nosend) {
      Espruino.Core.Serial.open(devicePath, function(status) {
        if (status === undefined) {
          console.error("Unable to connect!");
          return exitCallback();
        }
        if (!args.quiet) log("Connected");
        // Do we need to update firmware?
        if (args.updateFirmware) {
          var bin = fs.readFileSync(args.updateFirmware, {encoding:"binary"});
          var flashOffset = args.firmwareFlashOffset || 0;
          Espruino.Core.Flasher.flashBinaryToDevice(bin, flashOffset, function(err) {
            log(err ? "Error!" : "Success!");
            exitTimeout = setTimeout(exitCallback, 500);
          });
        } else {
          // figure out what code we need to send (if any)
          sendCode(function() {
            exitTimeout = setTimeout(exitCallback, 500);
          });
        }
        // send code over here...
  
        // ----------------------
       }, function() {
         log("Disconnected.");
         exitCallback();
       });
    } else {
      sendCode(function() {
            exitTimeout = setTimeout(exitCallback, 500);
          });
    }
  }
docs: /* Connect and send file/expression/etc