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

⌈⌋ ⎇ branch:  cross package maker


Artifact [45fa297138]

Artifact 45fa297138b3e473a0d6fd18f4476362fba599e0:

  • File bin/fpm-npm — part of check-in [dc35e39ed8] at 2011-01-04 02:52:43 on branch trunk — - make fpm-npm a toplevel tool (user: jls@semicomplete.com size: 2331)

#!/usr/bin/env ruby
#

require "optparse"
require "ostruct"
require "json"

settings = OpenStruct.new
opts = OptionParser.new do |opts|
  opts.on("-n PACKAGENAME", "--name PACKAGENAME",
          "What name to give to the package") do |name|
    settings.name = name
  end

  opts.on("-v VERSION", "--version VERSION",
          "version to give the package") do |version|
    settings.version = version
  end

  opts.on("-t OUTPUTTYPE", "--type OUTPUTTYPE",
          "what kind of package you want as output (deb, etc)") do |type|
    settings.type = type
  end
end

args = opts.parse(ARGV)

if !["deb"].include?(settings.type)
  $stderr.puts("Unsupported output package type '#{settings.type}'."
               "Only supports 'deb' right now.")
  exit 1
end

builddir="#{Dir.pwd}/npm2pkg"

INSTALLPATH="/usr/lib/node"
Dir.mkdir(builddir) if !File.exists?(builddir)
File.open("#{builddir}/.npmrc", "w") do |file|
  file.puts "root = #{builddir}#{INSTALLPATH}"
end

## Trick npm into using a custom .npmrc
system("env - PATH=$PATH HOME=#{builddir} npm install #{settings.name} #{settings.version}")

# Find all installed npms in builddir, make packages.
Dir.glob("#{builddir}#{INSTALLPATH}/.npm/*/*") do |path|
  next if File.symlink?(path)
  puts path

  # Load the package.json and glean any information from it, then invoke pkg.rb
  package = JSON.parse(File.new("#{path}/package/package.json").read())
  depends = Dir.glob("#{path}/dependson/*@*").collect { |p| File.basename(p) }\
    .collect { |p| n,v = p.split("@"); "#{n} (= #{v})" }

  if package["author"]
    maintainer = package["author"]
  else
    m = package["maintainers"][0] \
      rescue { "name" => "missing upstream author", "email" => ENV["USER"] }
    maintainer = "#{m["name"]} <#{m["email"]}>"
  end

  pkgcmd = [ "fpm", 
    "-n", "nodejs-#{package["name"]}",
    "-v", package["version"],
    "-m", maintainer,
    "-a", "all",
  ]

  depends.each do |dep|
    pkgcmd += ["-d", dep]
  end

  pkgcmd += ["-p", "nodejs-#{package["name"]}-VERSION_ARCH.deb"]
  pkgcmd += ["-C", builddir]
  pkgcmd << "#{INSTALLPATH[1..-1]}/.npm/#{package["name"]}/active"
  pkgcmd << "#{INSTALLPATH[1..-1]}/#{package["name"]}"
  pkgcmd << "#{INSTALLPATH[1..-1]}/#{package["name"]}@#{package["version"]}"

  puts pkgcmd.map { |x| "\"#{x}\"" }.join(" ")
  system *pkgcmd
end