<commit_before>#
# Updates all the locally installed packages
#
# Copyright (C) 2011 <NAME>
#

#
# Reads a file content in the current directory
#
# @param {String} filename
# @return {String} file content
#
read = (filename)->
  fs       = require('fs')
  path     = require('path')
  filename = process.cwd() + "/" + filename

  if path.existsSync(filename)
    fs.readFileSync(filename).toString()
  else
    ''

#
# Reading the images list
#
# @return {Object} images
#
read_images = (build)->
  fs     = require('fs')
  path   = require('path')
  folder = "#{process.cwd()}/images/"
  images = {}

  if match = build.match(/('|")\/?images\/.+?\1/g)
    for file in match
      file = file.substr(1, file.length - 2)
      if file = file.split('images/')[1]
        if path.existsSync(folder + file)
          images[file] = fs.readFileSync(folder + file).toString('base64')

  return images

#
# Kicks in the command
#
exports.init = (args) ->
  pack    = require('../package')
  hosting = require('../hosting')

  sout "» Compiling the project".ljust(61)
  system "#{__dirname}/../../bin/lovely build", ->
    sout "Done\n".green

    build = read("build/#{pack.name}.js")

    sout "» Publishing #{lovelyrc.host}/packages/#{pack.name} ".ljust(61)
    hosting.send_package
      manifest: read('package.json')
      build:    build
      images:   read_images(build)
      documents:
        index:     read('README.md')
        demo:      read("demo.html") || read("index.html")
        changelog: read('CHANGELOG')

    sout "Done\n".green


#
# Prints out the command help
#
exports.help = (args) ->
  """
  Publishes the package on the lovely.io host

  Usage:
      lovely publish

  """<commit_msg>CLI the publish script fix for images uploading feature<commit_after>#
# Updates all the locally installed packages
#
# Copyright (C) 2011 <NAME>
#

#
# Reads a file content in the current directory
#
# @param {String} filename
# @return {String} file content
#
read = (filename)->
  fs       = require('fs')
  path     = require('path')
  filename = process.cwd() + "/" + filename

  if path.existsSync(filename)
    fs.readFileSync(filename).toString()
  else
    ''

#
# Reading the images list
#
# @return {Object} images
#
read_images = (build)->
  fs     = require('fs')
  path   = require('path')
  folder = "#{process.cwd()}/images/"
  images = {}

  if match = build.match(/('|"|\()\/?images\/.+?\1/g)
    for file in match
      file = file.substr(1, file.length - 2)
      file = file.substr(0, file.length - 1) if file[file.length-1] is "\\"
      if file = file.split('images/')[1]
        if path.existsSync(folder + file)
          images[file] = fs.readFileSync(folder + file).toString('base64')

  return images

#
# Kicks in the command
#
exports.init = (args) ->
  pack    = require('../package')
  hosting = require('../hosting')

  sout "» Compiling the project".ljust(61)
  system "#{__dirname}/../../bin/lovely build", ->
    sout "Done\n".green

    build = read("build/#{pack.name}.js")

    sout "» Publishing #{lovelyrc.host}/packages/#{pack.name} ".ljust(61)
    hosting.send_package
      manifest: read('package.json')
      build:    build
      images:   read_images(build)
      documents:
        index:     read('README.md')
        demo:      read("demo.html") || read("index.html")
        changelog: read('CHANGELOG')

    sout "Done\n".green


#
# Prints out the command help
#
exports.help = (args) ->
  """
  Publishes the package on the lovely.io host

  Usage:
      lovely publish

  """
{'fraction_non_alphanumeric': 0.1649251623835075, 'fraction_numerical': 0.00875458909912454, 'mean_word_length': 2.748148148148148, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1523993', 'n_tokens_mistral': 1195, 'n_tokens_neox': 1169, 'n_words': 291}