<commit_before>'use babel'

const FS = require('fs')
const Path = require('path')
const SSH = require('node-ssh')
const Helpers = require('atom-linter')
import {promisify} from 'js-toolkit'
import {CompositeDisposable} from 'atom'

const readFile = promisify(FS.readFile)
const access = promisify(FS.access)

export default new class Hack {
  constructor() {
    this.subscriptions = new CompositeDisposable
    this.config = {
      type: 'local'
    }
    this.connected = true
    this.connection = null
    this.projectPath = null

    this.subscriptions.add(atom.project.onDidChangePaths(() => this.readConfig()))
    this.readConfig()
  }
  readConfig() {
    if (this.connection !== null) {
      this.connection.end()
      this.connection = null
    }
    const projects = atom.project.getPaths()
    if (!projects[0].length) {
      atom.notifications.addError('[Hack] No configuration file (.atom-hack) found in project root', {dismissible: true})
    } else {
      this.projectPath = projects[0]
      const configPath = Path.join(this.projectPath, '.atom-hack')
      access(configPath, FS.R_OK).catch(() => {
        if (process.platform === 'win32') {
          throw new Error('No configuration file (.atom-hack) found in project root')
        } else throw null
      }).then(() => {
        this.connected = false
        return readFile(configPath)
      }).then(contents => {
        try {
          contents = JSON.parse(contents.toString('utf8'))
        } catch (error) {
          throw new Error('Configuration file is not valid JSON')
        }
        contents.type = contents.type || 'remote'
        contents.port = contents.port || 22
        if (!contents.privateKey) {
          throw new Error('No privateKey specified in configuration')
        }
        if (!contents.remoteDir) {
          throw new Error('No remoteDir specified in configuration')
        }
        this.config = contents
        this.connection = new SSH()
        return this.connection.connect(this.config).then(() => {
          return this.connection.requestSFTP().then(sftp => {
            atom.notifications.addSuccess('[Hack] Successfully connected to server')
            this.connected = true
            this.connection.sftp = sftp<commit_msg>:bug: Use real project path<commit_after>'use babel'

const FS = require('fs')
const Path = require('path')
const SSH = require('node-ssh')
const Helpers = require('atom-linter')
import {promisify} from 'js-toolkit'
import {CompositeDisposable} from 'atom'

const readFile = promisify(FS.readFile)
const access = promisify(FS.access)

export default new class Hack {
  constructor() {
    this.subscriptions = new CompositeDisposable
    this.config = {
      type: 'local'
    }
    this.connected = true
    this.connection = null
    this.projectPath = null

    this.subscriptions.add(atom.project.onDidChangePaths(() => this.readConfig()))
    this.readConfig()
  }
  readConfig() {
    if (this.connection !== null) {
      this.connection.end()
      this.connection = null
    }
    const projects = atom.project.getPaths()
    if (!projects[0].length) {
      atom.notifications.addError('[Hack] No configuration file (.atom-hack) found in project root', {dismissible: true})
    } else {
      this.projectPath = FS.realpathSync(projects[0])
      const configPath = Path.join(this.projectPath, '.atom-hack')
      access(configPath, FS.R_OK).catch(() => {
        if (process.platform === 'win32') {
          throw new Error('No configuration file (.atom-hack) found in project root')
        } else throw null
      }).then(() => {
        this.connected = false
        return readFile(configPath)
      }).then(contents => {
        try {
          contents = JSON.parse(contents.toString('utf8'))
        } catch (error) {
          throw new Error('Configuration file is not valid JSON')
        }
        contents.type = contents.type || 'remote'
        contents.port = contents.port || 22
        if (!contents.privateKey) {
          throw new Error('No privateKey specified in configuration')
        }
        if (!contents.remoteDir) {
          throw new Error('No remoteDir specified in configuration')
        }
        this.config = contents
        this.connection = new SSH()
        return this.connection.connect(this.config).then(() => {
          return this.connection.requestSFTP().then(sftp => {
            atom.notifications.addSuccess('[Hack] Successfully connected to server')
            this.connected = true
            this.connection.sftp = sftp
{'fraction_non_alphanumeric': 0.12546693034497913, 'fraction_numerical': 0.0030762469786860033, 'mean_word_length': 2.6650563607085345, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2911845', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1263, 'n_words': 319}