<commit_before>sbawn = require "./sbawn"
util = require "util"

class Project

  constructor: (@options={}) ->

  initialize: (options={}) =>
    process.chdir(@options.folder)

    @make
      onSuccess: =>
        @package(options.onSuccess)

  push: (options = {}) =>
    steroidsCli.debug "Starting push"

    @make
      onSuccess: =>
        @package
          onSuccess: () =>
            options.onSuccess.call() if options.onSuccess?
      onFailure: options.onFailure

  preMake: (options = {}) =>
    config = steroidsCli.config.getCurrent()

    if config.hooks.preMake.cmd and config.hooks.preMake.args

      util.log "preMake started"

      preMakeSbawn = sbawn
        cmd: config.hooks.preMake.cmd
        args: config.hooks.preMake.args
        stdout: true
        stderr: true

      preMakeSbawn.on "exit", =>
        util.log "preMake done"

        options.onSuccess.call() if options.onSuccess?

    else
      options.onSuccess.call() if options.onSuccess?


  postMake: (options = {}) =>
    config = steroidsCli.config.getCurrent()

    if config.hooks.postMake.cmd and config.hooks.postMake.args

      util.log "postMake started"

      postMakeSbawn = sbawn
        cmd: config.hooks.postMake.cmd
        args: config.hooks.postMake.args
        stdout: true
        stderr: true

      postMakeSbawn.on "exit", =>
        util.log "postMake done"

        options.onSuccess.call() if options.onSuccess?
    else
      options.onSuccess.call() if options.onSuccess?

  makeOnly: (options = {}) => # without hooks

    steroidsCli.debug "Spawning steroids grunt"

    gruntSbawn = sbawn
      cmd: steroidsCli.pathToSelf
      args: ["grunt"]
      stdout: true
      stderr: true

    gruntSbawn.on "exit", () =>
      if gruntSbawn.code == 137
        options.onSuccess.call() if options.onSuccess?
      else
        steroidsCli.debug "grunt spawn exited with code #{gruntSbawn.code}"
        options.onFailure.call() if options.onFailure?

  make: (options = {}) => # with pre- and post-make hooks

    steroidsCli.debug "Making with hooks."

    @preMake
      onSuccess: =>
        @makeOnly
          onSuccess: =>
            @postMake options

  package: (options = {}) =>
    steroidsCli.debug "Spawning steroids package"

    packageSbawn = sbawn
      cmd: steroidsCli.pathToSelf
      args: ["package"]
      stdout: true
      stderr: true

    packageSbawn.on "exit", options.onSuccess

module.exports = Project<commit_msg>fixed crash when creating a new project<commit_after>sbawn = require "./sbawn"
util = require "util"

class Project

  constructor: (@options={}) ->

  initialize: (options={}) =>
    process.chdir(@options.folder)

    @makeOnly
      onSuccess: =>
        @package(options.onSuccess)

  push: (options = {}) =>
    steroidsCli.debug "Starting push"

    @make
      onSuccess: =>
        @package
          onSuccess: () =>
            options.onSuccess.call() if options.onSuccess?
      onFailure: options.onFailure

  preMake: (options = {}) =>
    config = steroidsCli.config.getCurrent()

    if config.hooks.preMake.cmd and config.hooks.preMake.args

      util.log "preMake started"

      preMakeSbawn = sbawn
        cmd: config.hooks.preMake.cmd
        args: config.hooks.preMake.args
        stdout: true
        stderr: true

      preMakeSbawn.on "exit", =>
        util.log "preMake done"

        options.onSuccess.call() if options.onSuccess?

    else
      options.onSuccess.call() if options.onSuccess?


  postMake: (options = {}) =>
    config = steroidsCli.config.getCurrent()

    if config.hooks.postMake.cmd and config.hooks.postMake.args

      util.log "postMake started"

      postMakeSbawn = sbawn
        cmd: config.hooks.postMake.cmd
        args: config.hooks.postMake.args
        stdout: true
        stderr: true

      postMakeSbawn.on "exit", =>
        util.log "postMake done"

        options.onSuccess.call() if options.onSuccess?
    else
      options.onSuccess.call() if options.onSuccess?

  makeOnly: (options = {}) => # without hooks

    steroidsCli.debug "Spawning steroids grunt"

    gruntSbawn = sbawn
      cmd: steroidsCli.pathToSelf
      args: ["grunt"]
      stdout: true
      stderr: true

    gruntSbawn.on "exit", () =>
      if gruntSbawn.code == 137
        options.onSuccess.call() if options.onSuccess?
      else
        steroidsCli.debug "grunt spawn exited with code #{gruntSbawn.code}"
        options.onFailure.call() if options.onFailure?

  make: (options = {}) => # with pre- and post-make hooks

    steroidsCli.debug "Making with hooks."

    @preMake
      onSuccess: =>
        @makeOnly
          onSuccess: =>
            @postMake options

  package: (options = {}) =>
    steroidsCli.debug "Spawning steroids package"

    packageSbawn = sbawn
      cmd: steroidsCli.pathToSelf
      args: ["package"]
      stdout: true
      stderr: true

    packageSbawn.on "exit", options.onSuccess

module.exports = Project
{'fraction_non_alphanumeric': 0.11357229158276279, 'fraction_numerical': 0.0012082158679017317, 'mean_word_length': 2.390443686006826, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, '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': '3280502', 'n_tokens_mistral': 1596, 'n_tokens_neox': 1507, 'n_words': 347}