Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 105 lines (84 sloc) 3.165 kb
#!/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 |packagetype|
settings.packagetype = packagetype
end
end
args = opts.parse(ARGV)
if !["deb"].include?(settings.packagetype)
$stderr.puts "Unsupported output package type '#{settings.packagetype}'." \
"Only supports 'deb' right now."
exit 1
end
if !settings.name
$stderr.puts "No npm package name given (missing -n?)"
exit 1
end
builddir="#{Dir.pwd}/npm2pkg"
# Prefix package names with 'nodejs-'
PACKAGEPREFIX = "nodejs-"
Dir.mkdir(builddir) if !File.exists?(builddir)
File.open("#{builddir}/.npmrc", "w") do |file|
file.puts "root = #{builddir}/usr/lib/node"
file.puts "binroot = #{builddir}/usr/lib/node/bin"
file.puts "manroot = #{builddir}/usr/share/man"
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}/usr/lib/node/.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())
# TODO(sissel): Ideally we want to say any version with the same 'release' number, like
# So we'll specify deps of {v}-1 <= x <= {v}-999999....
depends = Dir.glob("#{path}/dependson/*@*") \
.collect { |p| PACKAGEPREFIX + File.basename(p) } \
.collect { |p| n,v = p.split("@");
["#{n} (>= #{v}-1)", "#{n} (<= #{v}-99999999999999)"]
}.flatten
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", "#{PACKAGEPREFIX}#{package["name"]}",
"-v", package["version"],
"-m", maintainer,
"-a", "all",
]
depends.each do |dep|
pkgcmd += ["-d", dep]
end
pkgcmd += ["-p", "#{PACKAGEPREFIX}#{package["name"]}-VERSION_ARCH.deb"]
pkgcmd += ["-C", builddir]
pkgcmd << "usr/lib/node/.npm/#{package["name"]}/active"
pkgcmd << "usr/lib/node/.npm/#{package["name"]}/#{package["version"]}"
pkgcmd << "usr/lib/node/#{package["name"]}"
pkgcmd << "usr/lib/node/#{package["name"]}@#{package["version"]}"
# Include bin files, install to usr/lib/node/bin
(package["bin"] or []).each do |bin, script|
pkgcmd << "usr/lib/node/bin/#{bin}"
pkgcmd << "usr/lib/node/bin/#{bin}@#{package["version"]}"
end
# TODO(sissel): We could include manpages and docs, but I don't care right
# now. If you want it, I accept patches! :)
system *pkgcmd
end
Jump to Line
Something went wrong with that request. Please try again.