Cross package maker. DEB/RPM generation or conversion. Derived from jordansissel/fpm.

⌈⌋ ⎇ branch:  cross package maker


Artifact [4857c8ad71]

Artifact 4857c8ad718cf2397abd74a8265ed3de221c43e2:

  • File lib/fpm/package/filter_composer.rb — part of check-in [176a5242b0] at 2014-12-22 12:36:08 on branch trunk — Add missing update(opts) parameter. (user: mario size: 1823)

#
# api: fpm
# title: Composer.json stub
# description: injects/updates a composer.json from fpm attributes
# type: template
# depends: json
# category: meta
# doc: https://getcomposer.org/doc/04-schema.md
# version: 0.1
#
# Adapts or creates a composer.json from fpm/package attributes.
#
#  → To be used in conjunction with -t phar plugin, to craft a whole
#    composer bundle from plain scripts.
# 

require "fpm/package"
require "fpm/util"
require "json"
require "fileutils"
require "time"

# composer.json
class FPM::Package::Filter_Composer < FPM::Package
  def update(opts=nil)
    # read existing data
    dest = "#{staging_path}/#{@prefix}/composer.json"
    if File.exist?(dest)
      json = JSON.parse(File.read(dest))
      # technically it could also become an input filter now,
      # injecting known values for absent fpm attributes here
      # (only had to be transferred back to @input in command.rb then..)
    else
      # create afresh
      json = {
        "name" => "#{@name}/#{@name}",
        "description" => @description,
        "license" => @license,
        "homepage" => @url,
        "type" => "library",
        "extra" => {
          "\$packaged-by" => "xpm/fpm",
          "maintainer" => @maintainer,
          "epoch" => @epoch,
          "releases"=> []
        },
        "autoload" => {
          "shared" => ["#{@name}.phar"]
        }
      }
    end
    # update current build information
    json.merge!({        
      "version" => @version,
      "time" => Time.now.strftime("%Y-%m-%d"),
      "bin" => bin()
    })
    # save `composer.json` to staging path
    File.write(dest, JSON.pretty_generate(json))
  end

  def bin
    ::Dir.chdir(staging_path) do
      return ::Dir.glob("**").keep_if { |fn| File.executable?(fn) and not File.directory?(fn) }
    end
  end
end