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

⌈⌋ branch:  cross package maker


Check-in [dc35e39ed8]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
SHA1 Hash:dc35e39ed864fe7f587fb42319a4e954b7d1bc55
Date: 2011-01-04 02:52:43
User: jls
Comment:- make fpm-npm a toplevel tool
Tags And Properties
  • sym-trunk inherited from [2b439be7d6]
Context
2011-01-04
02:53
[d09d2b8ea6] - Add fpm-npm to bin (user: jls, tags: trunk)
02:52
[dc35e39ed8] - make fpm-npm a toplevel tool (user: jls, tags: trunk)
02:49
[ed2965847a] - version bump - remove debug output (user: jls, tags: trunk, v0.1.1)
Changes

Added bin/fpm-npm.





































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/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

Deleted tools/npm2pkg.rb.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/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
end

args = opts.parse(ARGV)

#builddir="#{Dir.pwd}/npm2pkg-#{settings.name}-#{settings.version or "latest"}"
builddir="#{Dir.pwd}/npm2pkg"
#if File.exists?(builddir)
  #system("rm -r #{builddir}")
#end

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
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<