<commit_before>Help = require "./steroids/Help"
paths = require "./steroids/paths"

argv = require('optimist').argv
util = require "util"
open = require "open"
fs = require("fs")
chalk = require "chalk"

global.Promise = require("bluebird")
Promise.onPossiblyUnhandledRejection (e, promise) ->
  throw e


class SteroidsError extends Error
  constructor: (message)->
    Error.call @
    Error.captureStackTrace(@, @constructor)
    @name = @constructor.name
    @message = message

class Steroids

  SteroidsError: SteroidsError
  PlatformError: class PlatformError extends SteroidsError

  # move this to globals
  simulator: null

  globals:
    genymotion: null
    simulator: null

  constructor: (@options = {}) ->
    Simulator = require "./steroids/Simulator"
    Version = require "./steroids/version/version"
    Config = require "./steroids/Config"

    @simulator = new Simulator
      debug: @options.debug

    @version = new Version
    @pathToSelf = process.argv[1]
    @config = new Config
    @platform = @options.argv.platform || "ios"
    @debugEnabled = @options.debug

  host:
    os:
      isOSX: ->
        process.platform == "darwin"
      isWindows: ->
        process.platform == "win32"
      isLinux: ->
        process.platform == "linux"


  readApplicationConfig: ->
    applicationConfig = paths.application.configs.application

    if fs.existsSync(applicationConfig)
      contents = fs.readFileSync(applicationConfig).toString()

    return contents

  detectSteroidsProject: ->
    return fs.existsSync(paths.application.configDir) and (fs.existsSync(paths.application.appDir) or fs.existsSync(paths.application.wwwDir))

  debug: (options = {}, other) =>
    message = if other?
      options + ": " + other
    else if options.constructor.name == "String"
      options
    else
      options.message

    message = "#{new Date()} #{message}"

    steroidsCli.debugMessages ||= []
    steroidsCli.debugMessages.push message

    if steroidsCli.options.debug
      process.stdout.cursorTo(0) if process.stdout.cursorTo?
      console.log "[DEBUG]", message

  log: (options) =>
    #TODO: detect that we are in prompt and prepend with \n
    console.log "#{options}"

  ensureProjectIfNeededFor: (command, otherOptions) ->
    if command in ["push", "make", "package", "connect", "update", "generate", "deploy", "debug", "emulate"]
      return if @detectSteroidsProject()

      steroidsCli.log "Error: command '#{command}' requires to be run in a Steroids project directory."
      process.exit(1)

  execute: =>
    [firstOption, otherOptions...] = argv._

    if argv.version
      firstOption = "version"

    if firstOption not in ["emulate", "debug"] and argv.help
      firstOption = "usage"

    unless steroidsCli.host.os.isOSX()
      wrongPlatform = true
      if firstOption == "emulate" and otherOptions[0] == "ios"
        steroidsCli.log "Error: iOS Simulator requires Mac OS X."
      else
        wrongPlatform = false

      process.exit(1) if wrongPlatform


    @ensureProjectIfNeededFor(firstOption, otherOptions)

    if firstOption in ["connect", "create"]
      Help.logo() unless argv.noLogo<commit_msg>added data to list of commands that require a project<commit_after>Help = require "./steroids/Help"
paths = require "./steroids/paths"

argv = require('optimist').argv
util = require "util"
open = require "open"
fs = require("fs")
chalk = require "chalk"

global.Promise = require("bluebird")
Promise.onPossiblyUnhandledRejection (e, promise) ->
  throw e


class SteroidsError extends Error
  constructor: (message)->
    Error.call @
    Error.captureStackTrace(@, @constructor)
    @name = @constructor.name
    @message = message

class Steroids

  SteroidsError: SteroidsError
  PlatformError: class PlatformError extends SteroidsError

  # move this to globals
  simulator: null

  globals:
    genymotion: null
    simulator: null

  constructor: (@options = {}) ->
    Simulator = require "./steroids/Simulator"
    Version = require "./steroids/version/version"
    Config = require "./steroids/Config"

    @simulator = new Simulator
      debug: @options.debug

    @version = new Version
    @pathToSelf = process.argv[1]
    @config = new Config
    @platform = @options.argv.platform || "ios"
    @debugEnabled = @options.debug

  host:
    os:
      isOSX: ->
        process.platform == "darwin"
      isWindows: ->
        process.platform == "win32"
      isLinux: ->
        process.platform == "linux"


  readApplicationConfig: ->
    applicationConfig = paths.application.configs.application

    if fs.existsSync(applicationConfig)
      contents = fs.readFileSync(applicationConfig).toString()

    return contents

  detectSteroidsProject: ->
    return fs.existsSync(paths.application.configDir) and (fs.existsSync(paths.application.appDir) or fs.existsSync(paths.application.wwwDir))

  debug: (options = {}, other) =>
    message = if other?
      options + ": " + other
    else if options.constructor.name == "String"
      options
    else
      options.message

    message = "#{new Date()} #{message}"

    steroidsCli.debugMessages ||= []
    steroidsCli.debugMessages.push message

    if steroidsCli.options.debug
      process.stdout.cursorTo(0) if process.stdout.cursorTo?
      console.log "[DEBUG]", message

  log: (options) =>
    #TODO: detect that we are in prompt and prepend with \n
    console.log "#{options}"

  ensureProjectIfNeededFor: (command, otherOptions) ->
    commands = [
      "push"
      "make"
      "package"
      "connect"
      "update"
      "generate"
      "deploy"
      "debug"
      "emulate"
      "data"
    ]

    if command in commands
      return if @detectSteroidsProject()

      steroidsCli.log "Error: command '#{command}' requires to be run in a Steroids project directory."
      process.exit(1)

  execute: =>
    [firstOption, otherOptions...] = argv._

    if argv.version
      firstOption = "version"

    if firstOption not in ["emulate", "debug"] and argv.help
      firstOption = "usage"

    unless steroidsCli.host.os.isOSX()
      wrongPlatform = true
      if firstOption == "emulate" and otherOptions[0] == "ios"
        steroidsCli.log "Error: iOS Simulator requires Mac OS X."
      else
        wrongPlatform = false

      process.exit(1) if wrongPlatform


    @ensureProjectIfNeededFor(firstOption, otherOptions)

    if firstOption in ["connect", "create"]
      Help.logo() unless argv.noLogo
{'fraction_non_alphanumeric': 0.11614599443241572, 'fraction_numerical': 0.0021651716671821837, 'mean_word_length': 3.0647391577624137, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5406493', 'n_tokens_mistral': 1927, 'n_tokens_neox': 1849, 'n_words': 499}