<commit_before>fs = require 'fs'
mkdirp = require 'mkdirp'
logger = require '../libs/logger.js'
{run} = require '../libs/run.js'
{runSync} = require '../libs/run.js'
runc = require '../libs/run.js'
exports.script = (lang, parsed, options, dirw) ->
  # Main stuff
  @sharray = '#!/usr/bin/bash\necho Preparing to run web-app...\n'
  @id = Math.floor Math.random() * 9999999999999999 + 1
  @con = '.tubs/tub'+@id+'/start.sh'
  logger.logback({id: @id, name: parsed.name, status: 'Preparing', code: '200'}, 'http://localhost:8080/api/container/status/update', 'POST', 'python')
  # Dir for files
  if fs.existsSync '.tubs' != true
    fs.mkdirSync('./.tubs')
  fs.mkdirSync('./.tubs/tub'+@id)
  # Open script
  fs.openSync @con, 'w'
  # Chmod
  fs.chmodSync @con, '700'
  fs.chmodSync @con, '777'
  # Write shebang
  fs.writeFileSync @con, @sharray, 'utf8'
  # env
  if parsed.env != undefined
    fs.appendFileSync @con, 'echo Exporting Enviroment...\necho Setting default env...\n'
    fs.appendFileSync @con, 'export CONTAINER_ID='+@id+'\n'
    fs.appendFileSync @con, 'export CONTAINER_NAME='+parsed.name+'\n'
    fs.appendFileSync @con, 'export PORT='+parsed.port+'\n'
    if parsed.public == undefined && isNaN parsed.port
      fs.appendFileSync @con, 'export PUBLIC_PORT=3030\n'
    else
      fs.appendFileSync @con, 'export PUBLIC_PORT='+parsed.public+'\n'
    fs.appendFileSync @con, 'echo Setting enviroment varibles from .web.yml...\n'
    v = 0
    while v < parsed.env.length
      fs.appendFileSync @con, 'export '+parsed.env[v]+'\n'
      v++

  # Update Nodejs/ruby/python
  if lang == 'nodejs'
    if parsed.nodejs == 'latest'
      @array = 'echo Updating nodejs...\n. ~/.nvm/nvm.sh\nnvm install stable\n'
      fs.appendFileSync @con, @array
    else
      @array = 'echo Updating nodejs...\nnvm install '+parsed.nodejs+'\n'
      fs.appendFileSync @con, @array
    # Required
    if parsed.require != undefined
      i = 0
      while i < parsed.require.length
        if parsed.require[i] == 'ruby'
          @ruby = 'echo Installing ruby...\nsudo apt-get install -y ruby\necho Installing bundle...\ngem install bundle\n'
          fs.appendFileSync @con, @ruby
        i++
    # Global deps
    @cd = '\ncd ./app\n'
    @global = parsed.global
    @enter = '\n'
    if parsed.global != undefined
      if global.npm != undefined
        # body...
        @npm = 'echo Installing global npm modules...\nnpm install -g '
        fs.appendFileSync @con, @npm
        n = 0
        while n < global.npm.length
          fs.appendFileSync @con, global.npm[n]+' '
          n++
        fs.appendFileSync @con, @enter
      if global.gem != undefined
        # body...
        @gem = 'echo Installing gems...\ngem install '
        fs.appendFileSync @con, @gem
        g = 0
        while g < global.npm.length
          if global.gem[g] != undefined
            # body...
            fs.appendFileSync @con, global.gem[g]+' '
          g++
      # if parsed.global
    fs.appendFileSync @con, @cd
    # Install
    if parsed.build != undefined
      # body...
      @build = parsed.build
      @install = parsed.build
      fs.appendFileSync @con, 'echo Building Web-app...\necho Installing dependencies...\n'
      inc = 0
      while inc < install.length
        fs.appendFileSync @con, 'echo '+build.script[b]+@enter
        fs.appendFileSync @con, build.script[b]+@enter
        b++
      fs.appendFileSync @con, 'echo Building...\n'
      b = 0
      while b < build.script.length
        fs.appendFileSync @con, build.script[b]+@enter
        b++
    # if
    fs.appendFileSync @con, 'echo Starting Web-app...\n'
    if parsed.port != undefined
      fs.appendFileSync @con, 'export PORT='+parsed.port+@enter
    fs.appendFileSync @con, parsed.start
    console.log '\nStart script Generated'
  if lang =='ruby'
    console.log 'h'<commit_msg>Fix bug where build would be written 2<commit_after>fs = require 'fs'
mkdirp = require 'mkdirp'
logger = require '../libs/logger.js'
{run} = require '../libs/run.js'
{runSync} = require '../libs/run.js'
runc = require '../libs/run.js'
exports.script = (lang, parsed, options, dirw) ->
  # Main stuff
  @sharray = '#!/usr/bin/bash\necho Preparing to run web-app...\n'
  @id = Math.floor Math.random() * 9999999999999999 + 1
  @con = '.tubs/tub'+@id+'/start.sh'
  logger.logback({id: @id, name: parsed.name, status: 'Preparing', code: '200'}, 'http://localhost:8080/api/container/status/update', 'POST', 'python')
  # Dir for files
  if fs.existsSync '.tubs' != true
    fs.mkdirSync('./.tubs')
  fs.mkdirSync('./.tubs/tub'+@id)
  # Open script
  fs.openSync @con, 'w'
  # Chmod
  fs.chmodSync @con, '700'
  fs.chmodSync @con, '777'
  # Write shebang
  fs.writeFileSync @con, @sharray, 'utf8'
  # env
  if parsed.env != undefined
    fs.appendFileSync @con, 'echo Exporting Enviroment...\necho Setting default env...\n'
    fs.appendFileSync @con, 'export CONTAINER_ID='+@id+'\n'
    fs.appendFileSync @con, 'export CONTAINER_NAME='+parsed.name+'\n'
    fs.appendFileSync @con, 'export PORT='+parsed.port+'\n'
    if parsed.public == undefined && isNaN parsed.port
      fs.appendFileSync @con, 'export PUBLIC_PORT=3030\n'
    else
      fs.appendFileSync @con, 'export PUBLIC_PORT='+parsed.public+'\n'
    fs.appendFileSync @con, 'echo Setting enviroment varibles from .web.yml...\n'
    v = 0
    while v < parsed.env.length
      fs.appendFileSync @con, 'export '+parsed.env[v]+'\n'
      v++

  # Update Nodejs/ruby/python
  if lang == 'nodejs'
    if parsed.nodejs == 'latest'
      @array = 'echo Updating nodejs...\n. ~/.nvm/nvm.sh\nnvm install stable\n'
      fs.appendFileSync @con, @array
    else
      @array = 'echo Updating nodejs...\nnvm install '+parsed.nodejs+'\n'
      fs.appendFileSync @con, @array
    # Required
    if parsed.require != undefined
      i = 0
      while i < parsed.require.length
        if parsed.require[i] == 'ruby'
          @ruby = 'echo Installing ruby...\nsudo apt-get install -y ruby\necho Installing bundle...\ngem install bundle\n'
          fs.appendFileSync @con, @ruby
        i++
    # Global deps
    @cd = '\ncd ./app\n'
    @global = parsed.global
    @enter = '\n'
    if parsed.global != undefined
      if global.npm != undefined
        # body...
        @npm = 'echo Installing global npm modules...\nnpm install -g '
        fs.appendFileSync @con, @npm
        n = 0
        while n < global.npm.length
          fs.appendFileSync @con, global.npm[n]+' '
          n++
        fs.appendFileSync @con, @enter
      if global.gem != undefined
        # body...
        @gem = 'echo Installing gems...\ngem install '
        fs.appendFileSync @con, @gem
        g = 0
        while g < global.npm.length
          if global.gem[g] != undefined
            # body...
            fs.appendFileSync @con, global.gem[g]+' '
          g++
      # if parsed.global
    fs.appendFileSync @con, @cd
    # Install
    if parsed.build != undefined
      # body...
      @build = parsed.build
      @install = parsed.build
      fs.appendFileSync @con, 'echo Building Web-app...\necho Installing dependencies...\n'
      inc = 0
      while inc < install.length
        fs.appendFileSync @con, 'echo '+install.script[inc]+@enter
        fs.appendFileSync @con, install.script[inc]+@enter
        b++
      fs.appendFileSync @con, 'echo Building...\n'
      b = 0
      while b < build.script.length
        fs.appendFileSync @con, build.script[b]+@enter
        b++
    # if
    fs.appendFileSync @con, 'echo Starting Web-app...\n'
    if parsed.port != undefined
      fs.appendFileSync @con, 'export PORT='+parsed.port+@enter
    fs.appendFileSync @con, parsed.start
    console.log '\nStart script Generated'
  if lang =='ruby'
    console.log 'h'
{'fraction_non_alphanumeric': 0.15307305759567066, 'fraction_numerical': 0.010694498131684061, 'mean_word_length': 2.4163732394366195, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '5646606', 'n_tokens_mistral': 2743, 'n_tokens_neox': 2575, 'n_words': 654}