Sha256: 319435b1b666fa9741e4121658412af259654141497a996107c57b2462c4deab
Contents?: true
Size: 1.49 KB
Versions: 2
Compression:
Stored size: 1.49 KB
Contents
require_relative "nem/version" require "json" class Nem def initialize(tty = false, *keywords) @keywords = keywords @tty = tty if @tty @gemspec_file = Dir['*.gemspec'].first unless File.file?(@gemspec_file) raise ArgumentError, "no gemspec in your current directory found" end gemspec_content = File.read(@gemspec_file) else @gemspec_file = '-' gemspec_content = $stdin.read end @gemspec = eval gemspec_content, binding, @gemspec_file end def validate unless @gemspec.runtime_dependencies.empty? raise ArgumentError, 'dependencies are not supported' end if @gemspec.executables.empty? raise ArgumentError, "you must specify at least one executable" end end def run validate if @tty File.write "package.json", generate puts "Converted #@gemspec_file to package.json" else puts generate end end def generate JSON.pretty_generate( "name" => @gemspec.name, "version" => @gemspec.version, "description" => @gemspec.description, "homepage" => @gemspec.homepage, "author" => { "name" => @gemspec.author || Array(@gemspec.authors).first, "email" => Array(@gemspec.email).first, }, "keywords" => ["nem", *@keywords], "preferGlobal" => true, "bin" => Hash[@gemspec.executables.map{ |bin| [File.basename(bin), "bin/#{File.basename(bin)}"] }], "license" => @gemspec.license ) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
nem-1.0.1 | lib/nem.rb |
nem-1.0.0 | lib/nem.rb |