parsePathToOpen (pathToOpen, executedFrom = '') {
    let initialColumn, initialLine
    if (!pathToOpen) {
      return {pathToOpen}
    }

    pathToOpen = pathToOpen.replace(/[:\s]+$/, '')
    const match = pathToOpen.match(LocationSuffixRegExp)

    if (match != null) {
      pathToOpen = pathToOpen.slice(0, -match[0].length)
      if (match[1]) {
        initialLine = Math.max(0, parseInt(match[1].slice(1)) - 1)
      }
      if (match[2]) {
        initialColumn = Math.max(0, parseInt(match[2].slice(1)) - 1)
      }
    } else {
      initialLine = initialColumn = null
    }

    const normalizedPath = path.normalize(path.resolve(executedFrom, fs.normalize(pathToOpen)))
    const stat = fs.statSyncNoException(normalizedPath)
    if (stat || !url.parse(pathToOpen).protocol) pathToOpen = normalizedPath

    return {pathToOpen, stat, initialLine, initialColumn}
  }
Exemple #2
0
 clearDebugOutput (name, fn) {
   const {normalize} = require('fs-plus')
   const filePath = normalize(settings.get('debugOutputFilePath'))
   atom.workspace.open(filePath, {searchAllPanes: true, activatePane: false}).then(editor => {
     editor.setText('')
     editor.save()
   })
 }
  static create(opts) {
    opts.name = opts.name.trim();
    opts.nameNorm = utils.normalize(opts.name);
    opts.path = fs.normalize(path.join(opts.basepath, opts.nameNorm));

    if (!opts.name) throw "Please, specify a valid usercontrol name";
    if (!opts.description)
      throw "Please, specify a valid usercontrol description";

    if (opts.platforms.length == 0)
      throw "At least one platform must be defined";

    if (fs.existsSync(opts.path)) throw "The path already exists";

    Usercontrol.initUC(opts);
    atom.open({ pathsToOpen: [opts.path] });
  }
Exemple #4
0
 lookupPreferIpv6(config.host).then(function (address) {
   if (config.authMethod === SupportedMethods.SSL_AGENT) {
     // Point to ssh-agent's socket for ssh-agent-based authentication.
     var agent = process.env['SSH_AUTH_SOCK'];
     if (!agent && /^win/.test(process.platform)) {
       // #100: On Windows, fall back to pageant.
       agent = 'pageant';
     }
     _this2._connection.connect({
       host: address,
       port: config.sshPort,
       username: config.username,
       agent: agent,
       tryKeyboard: true,
       readyTimeout: READY_TIMEOUT
     });
   } else if (config.authMethod === SupportedMethods.PASSWORD) {
     // When the user chooses password-based authentication, we specify
     // the config as follows so that it tries simple password auth and
     // failing that it falls through to the keyboard interactive path
     _this2._connection.connect({
       host: address,
       port: config.sshPort,
       username: config.username,
       password: config.password,
       tryKeyboard: true
     });
   } else if (config.authMethod === SupportedMethods.PRIVATE_KEY) {
     // We use fs-plus's normalize() function because it will expand the ~, if present.
     var expandedPath = fs.normalize(config.pathToPrivateKey);
     fsPromise.readFile(expandedPath).then(function (privateKey) {
       _this2._connection.connect({
         host: address,
         port: config.sshPort,
         username: config.username,
         privateKey: privateKey,
         tryKeyboard: true,
         readyTimeout: READY_TIMEOUT
       });
     })['catch'](function (e) {
       _this2._delegate.onError(e, _this2._config);
     });
   } else {
     throw new Error('Invalid authentication method');
   }
 })['catch'](function (e) {
  runBenchmarks ({headless, test, resourcePath, executedFrom, pathsToOpen, env}) {
    let windowInitializationScript
    if (resourcePath !== this.resourcePath && !fs.existsSync(resourcePath)) {
      ;({resourcePath} = this)
    }

    try {
      windowInitializationScript = require.resolve(
        path.resolve(this.devResourcePath, 'src', 'initialize-benchmark-window')
      )
    } catch (error) {
      windowInitializationScript = require.resolve(
        path.resolve(__dirname, '..', '..', 'src', 'initialize-benchmark-window')
      )
    }

    const benchmarkPaths = []
    if (pathsToOpen != null) {
      for (let pathToOpen of pathsToOpen) {
        benchmarkPaths.push(path.resolve(executedFrom, fs.normalize(pathToOpen)))
      }
    }

    if (benchmarkPaths.length === 0) {
      process.stderr.write('Error: Specify at least one benchmark path.\n\n')
      process.exit(1)
    }

    const devMode = true
    const isSpec = true
    const safeMode = false
    const window = new AtomWindow(this, this.fileRecoveryService, {
      windowInitializationScript,
      resourcePath,
      headless,
      test,
      isSpec,
      devMode,
      benchmarkPaths,
      safeMode,
      env
    })
    this.addWindow(window)
    return window
  }
Exemple #6
0
  async connect(config: SshConnectionConfiguration): Promise<void> {
    this._config = config;
    this._willConnect();

    const existingConnection = RemoteConnection
      .getByHostnameAndPath(this._config.host, this._config.cwd);

    if (existingConnection) {
      this._didConnect(existingConnection);
      return;
    }

    const connection = await RemoteConnection.createConnectionBySavedConfig(
      this._config.host,
      this._config.cwd,
      this._config.displayTitle,
    );

    if (connection) {
      this._didConnect(connection);
      return;
    }

    const {lookupPreferIpv6} = require('../../nuclide-commons').dnsUtils;
    let address = null;
    try {
      address = await lookupPreferIpv6(config.host);
    } catch (e) {
      this._error(
        'Failed to resolve DNS.',
        SshHandshake.ErrorType.HOST_NOT_FOUND,
        e,
      );
    }

    if (config.authMethod === SupportedMethods.SSL_AGENT) {
      // Point to ssh-agent's socket for ssh-agent-based authentication.
      let agent = process.env['SSH_AUTH_SOCK'];
      if (!agent && /^win/.test(process.platform)) {
        // #100: On Windows, fall back to pageant.
        agent = 'pageant';
      }
      this._connection.connect({
        host: address,
        port: config.sshPort,
        username: config.username,
        agent,
        tryKeyboard: true,
        readyTimeout: READY_TIMEOUT_MS,
      });
    } else if (config.authMethod === SupportedMethods.PASSWORD) {
        // When the user chooses password-based authentication, we specify
        // the config as follows so that it tries simple password auth and
        // failing that it falls through to the keyboard interactive path
      this._connection.connect({
        host: address,
        port: config.sshPort,
        username: config.username,
        password: config.password,
        tryKeyboard: true,
      });
    } else if (config.authMethod === SupportedMethods.PRIVATE_KEY) {
      // We use fs-plus's normalize() function because it will expand the ~, if present.
      const expandedPath = fs.normalize(config.pathToPrivateKey);
      let privateKey: string = (null : any);
      try {
        privateKey = await fsPromise.readFile(expandedPath);
      } catch (e) {
        this._error(
          `Failed to read private key`,
          SshHandshake.ErrorType.CANT_READ_PRIVATE_KEY,
          e,
        );
      }
      this._connection.connect({
        host: address,
        port: config.sshPort,
        username: config.username,
        privateKey,
        tryKeyboard: true,
        readyTimeout: READY_TIMEOUT_MS,
      });
    }
  }
const cleanPath = path => (path ? resolveEnv(fs.normalize(path)) : '')
  // Opens up a new {AtomWindow} to run specs within.
  //
  // options -
  //   :headless - A Boolean that, if true, will close the window upon
  //                   completion.
  //   :resourcePath - The path to include specs from.
  //   :specPath - The directory to load specs from.
  //   :safeMode - A Boolean that, if true, won't run specs from ~/.atom/packages
  //               and ~/.atom/dev/packages, defaults to false.
  runTests ({headless, resourcePath, executedFrom, pathsToOpen, logFile, safeMode, timeout, env}) {
    let windowInitializationScript
    if (resourcePath !== this.resourcePath && !fs.existsSync(resourcePath)) {
      ;({resourcePath} = this)
    }

    const timeoutInSeconds = Number.parseFloat(timeout)
    if (!Number.isNaN(timeoutInSeconds)) {
      const timeoutHandler = function () {
        console.log(
          `The test suite has timed out because it has been running for more than ${timeoutInSeconds} seconds.`
        )
        return process.exit(124) // Use the same exit code as the UNIX timeout util.
      }
      setTimeout(timeoutHandler, timeoutInSeconds * 1000)
    }

    try {
      windowInitializationScript = require.resolve(
        path.resolve(this.devResourcePath, 'src', 'initialize-test-window')
      )
    } catch (error) {
      windowInitializationScript = require.resolve(
        path.resolve(__dirname, '..', '..', 'src', 'initialize-test-window')
      )
    }

    const testPaths = []
    if (pathsToOpen != null) {
      for (let pathToOpen of pathsToOpen) {
        testPaths.push(path.resolve(executedFrom, fs.normalize(pathToOpen)))
      }
    }

    if (testPaths.length === 0) {
      process.stderr.write('Error: Specify at least one test path\n\n')
      process.exit(1)
    }

    const legacyTestRunnerPath = this.resolveLegacyTestRunnerPath()
    const testRunnerPath = this.resolveTestRunnerPath(testPaths[0])
    const devMode = true
    const isSpec = true
    if (safeMode == null) {
      safeMode = false
    }
    const window = new AtomWindow(this, this.fileRecoveryService, {
      windowInitializationScript,
      resourcePath,
      headless,
      isSpec,
      devMode,
      testRunnerPath,
      legacyTestRunnerPath,
      testPaths,
      logFile,
      safeMode,
      env
    })
    this.addWindow(window)
    return window
  }