Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

First attempt to make this mess into a proper configurable gem. Work …

…in progress since it doesn't work now!
  • Loading branch information...
commit 82891306f3a8ae73857cdfa39758d07dd4b39f23 1 parent 7882cde
@Spooner authored
View
4 .gitignore
@@ -1 +1,3 @@
-.idea/
+.idea/
+.yardoc
+doc/
View
3  Gemfile
@@ -0,0 +1,3 @@
+source :rubygems
+
+gemspec
View
22 Gemfile.lock
@@ -0,0 +1,22 @@
+PATH
+ remote: .
+ specs:
+ release_packager (0.0.1pre2)
+ ocra (~> 1.3.0)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ ocra (1.3.0)
+ rake (0.9.2.2)
+ riot (0.12.5)
+ rr
+ rr (1.0.4)
+
+PLATFORMS
+ x86-mingw32
+
+DEPENDENCIES
+ rake
+ release_packager!
+ riot (~> 0.12.5)
View
16 Rakefile
@@ -0,0 +1,16 @@
+require 'rake/testtask'
+
+desc "Run all tests"
+task :test do
+ Rake::TestTask.new do |t|
+ t.libs << "test"
+ t.pattern = "test/**/*_test.rb"
+ t.verbose = false
+ end
+end
+
+task :yard do
+ system "yard doc"
+end
+
+task :default => :test
View
64 lib/release_packager.rb
@@ -1,62 +1,4 @@
-require 'redcloth'
+require "fileutils"
-raise "APP must be defined for release" unless defined? APP
-raise "RELEASE_VERSION must be defined for release" unless defined? RELEASE_VERSION
-
-RELEASE_FOLDER = 'pkg'
-RELEASE_FOLDER_BASE = File.join(RELEASE_FOLDER, "#{APP}_v#{RELEASE_VERSION.gsub(/\./, '_')}")
-
-README_TEXTILE = "README.textile"
-README_HTML = "README.html"
-CHANGELOG_FILE = "CHANGELOG.txt"
-
-# Grab all files to include, ignoring raw_media (which just stores work, not finished media).
-SOURCE_FOLDER_FILES = `git ls-files`.split("\n").select {|f| f =~ %r[/] and not f =~ /^raw_/ }
-SOURCE_FOLDERS = SOURCE_FOLDER_FILES.map {|f| f =~ %r[([^/]+)]; $1 }.uniq
-
-# Files in the base directory that would be nice to include :)
-EXTRA_SOURCE_FILES = `git ls-files`.split("\n").grep %r[^[^/]+$]
-
-require_relative "release_packager/win32"
-require_relative "release_packager/osx"
-require_relative "release_packager/source"
-
-CLOBBER.include(RELEASE_FOLDER, README_HTML)
-
-# Generate a friendly readme
-file README_HTML => :readme
-desc "Convert readme to HTML"
-task readme: README_TEXTILE do
- puts "Converting readme to HTML"
- File.open(README_HTML, "w") do |file|
- file.write RedCloth.new(File.read(README_TEXTILE)).to_html
- end
-end
-
-def compress(package, folder, option = '')
- puts "Compressing #{package}"
- rm package if File.exist? package
- cd 'pkg'
- puts File.basename(package)
- puts %x[7z a #{option} "#{File.basename(package)}" "#{File.basename(folder)}"]
- cd '..'
-end
-
-desc "Create release packages v#{RELEASE_VERSION} (Not OSX)"
-task release: ["release:source", "release:win32:exe", "release:win32:installer"]
-
-
-# Create archives for release.
-{ "7z" => '', :zip => '-tzip' }.each_pair do |compression, option|
- { "source" => RELEASE_FOLDER_SOURCE,
- "win32:exe" => RELEASE_FOLDER_WIN32_EXE,
- "win32:installer" => RELEASE_FOLDER_WIN32_INSTALLER,
- }.each_pair do |name, folder|
- package = "#{folder}.#{compression}"
- desc "Create #{package}"
- task "release:#{name}_#{compression}" => package
- file package => folder do
- compress(package, folder, option)
- end
- end
-end
+require_relative "release_packager/version"
+require_relative "release_packager/project"
View
8 lib/release_packager/osx.rb
@@ -1,3 +1,10 @@
+module ReleasePackager
+ module Osx
+
+ end
+end
+
+=begin
require 'bundler'
# Get a list of gems to include, ignoring those binaries in the .app already and bundler, which is not necessary.
@@ -123,3 +130,4 @@ class Encoding
#mv File.join(OSX_BUILD_DIR, seven_z_package), RELEASE_FOLDER
mv File.join(OSX_BUILD_DIR, zip_package), RELEASE_FOLDER
end
+=end
View
117 lib/release_packager/project.rb
@@ -0,0 +1,117 @@
+require_relative "osx"
+require_relative "source"
+require_relative "win32"
+
+
+module ReleasePackager
+ COMPRESSIONS = {
+ :"7z" => "7z a",
+ zip: "7z a -tzip",
+ tar_bz: "tar -jcvf"
+ }
+
+ OUTPUTS = [:osx_app, :source, :win32_exe, :win32_installer, :win32_standalone]
+
+ DEFAULT_PACKAGE_FOLDER = "pkg"
+
+ class Project
+ include Osx
+ include Source
+ include Win32
+
+ attr_reader :id
+ attr_accessor :name, :files, :name, :version, :ocra_parameters, :execute, :license, :icon, :output_path
+
+ def initialize(id)
+ @id = id
+ @name = id.to_s.split(/-|_/).map(&:capitalize).join(" ")
+ @compressions = []
+ @outputs = []
+ @links= {}
+ @files = []
+ @output_path = DEFAULT_PACKAGE_FOLDER
+
+ @ocra_parameters = @version = @execute = @license = @icon = nil
+
+ if block_given?
+ yield self
+ generate_tasks
+ end
+ end
+
+ def add_compression(type)
+ raise ArgumentError, "Unsupported compression type #{type}" unless COMPRESSIONS.has_key? type
+ @compressions << type unless @compressions.include? type
+
+ type
+ end
+
+ # Add a type of output to produce. Must define at least one of these.
+ def add_output(type)
+ raise ArgumentError, "Unsupported output type #{type}" unless OUTPUTS.include? type
+ @outputs << type unless @outputs.include? type
+
+ type
+ end
+
+ # Add a link file to be included in the win32 releases.
+ def add_link(url, description)
+ @links[url] = description
+
+ url
+ end
+
+ # The path to the folder to create. All variations will be based on extending this path.
+ def folder_base
+ File.join(@output_path, "#{id}#{version ? "_#{version.tr(".", "_")}" : ""}")
+ end
+
+ # Generates all tasks required by the user. Automatically called at the end of the block, if #new is given a block.
+ def generate_tasks
+ raise "Must specify at least one output with #add_output before tasks can be generated" if @outputs.empty?
+
+ create_source_folder if @outputs.include? :source
+
+ generate_compression_tasks
+ end
+
+ # Generates the general tasks for compressing folders.
+ protected
+ def generate_compression_tasks
+ {
+ source: SOURCE_SUFFIX,
+ win32_standalone: "WIN32_EXE",
+ win32_exe: "WIN32",
+ win32_installer: "WIN32_INSTALLER",
+ }.each_pair do |name, output_suffix|
+ next unless @outputs.include? name
+
+ COMPRESSIONS.each_pair do |compression, command|
+ next unless @compressions.include? compression
+
+ folder = "#{folder_base}_#{output_suffix}"
+ package = "#{folder}.#{compression}"
+
+ desc "Create #{package}"
+ task "release:#{name}:#{compression}" => package
+ file package => folder do
+ compress(package, folder, command)
+ end
+ end
+
+ desc "Release #{name} in all compressions"
+ task "release:#{name}" => @compressions.map {|c| "release:#{name}:#{c}" }
+ end
+ end
+
+ protected
+ def compress(package, folder, command)
+ puts "Compressing #{package}"
+ rm package if File.exist? package
+ cd @output do
+ puts File.basename(package)
+ puts %x[#{command} "#{File.basename(package)}" "#{File.basename(folder)}"]
+ end
+ end
+ end
+end
View
24 lib/release_packager/source.rb
@@ -1,12 +1,18 @@
-RELEASE_FOLDER_SOURCE = "#{RELEASE_FOLDER_BASE}_SOURCE"
+module ReleasePackager
+ module Source
+ SOURCE_SUFFIX = "SOURCE"
-desc "Create source releases v#{RELEASE_VERSION}"
-task "release:source" => ["release:source_zip"]
+ protected
+ def create_source_folder
+ folder = "#{folder_base}_#{SOURCE_SUFFIX}"
-file RELEASE_FOLDER_SOURCE => README_HTML do
- mkdir_p RELEASE_FOLDER_SOURCE
- SOURCE_FOLDERS.each {|f| cp_r f, RELEASE_FOLDER_SOURCE }
- cp EXTRA_SOURCE_FILES, RELEASE_FOLDER_SOURCE
- cp CHANGELOG_FILE, RELEASE_FOLDER_SOURCE
- cp README_HTML, RELEASE_FOLDER_SOURCE
+ desc "Create source folder"
+ task "release:source" => folder
+
+ file folder => files do
+ FileUtils.mkdir_p RELEASE_FOLDER_SOURCE
+ FileUtils.cp_r files
+ end
+ end
+ end
end
View
3  lib/release_packager/version.rb
@@ -0,0 +1,3 @@
+module ReleasePackager
+ VERSION = "0.0.1pre2"
+end
View
11 lib/release_packager/win32.rb
@@ -1,3 +1,10 @@
+module ReleasePackager
+ module Win32
+
+ end
+end
+
+=begin
WIN32_EXECUTABLE = "#{APP}.exe"
APP_WITH_VERSION = "#{APP}_v#{RELEASE_VERSION.tr(".", "-")}_WIN32"
WIN32_INSTALLER_NAME = "#{APP_WITH_VERSION}_setup"
@@ -104,4 +111,6 @@
system %[#{WIN32_INSTALLER} /SILENT /DIR=#{RELEASE_FOLDER_WIN32_EXE}]
rm File.join(RELEASE_FOLDER_WIN32_EXE, "unins000.dat")
rm File.join(RELEASE_FOLDER_WIN32_EXE, "unins000.exe")
-end
+end
+
+=end
View
26 release_packager.gemspec
@@ -0,0 +1,26 @@
+# -*- encoding: utf-8 -*-
+require_relative "release_packager/version"
+
+Gem::Specification.new do |s|
+ s.name = "release_packager"
+ s.version = ReleasePackager::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Bil Bas (Spooner)"]
+ s.email = ["bil.bagpuss@gmail.com"]
+ s.homepage = "http://github.com/Spooner/release_packager/"
+ s.summary = %q{ReleasePackager helps to make application releases simpler}
+ s.description = %q{ReleasePackager helps to make application releases simpler, by outputting source folders, win32 folders, win32 standalone executables, win32 installers}
+
+ s.rubyforge_project = "release_packager"
+ s.has_rdoc = true
+ s.required_ruby_version = "~> 1.9.2"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ s.add_dependency('ocra', '~> 1.3.0')
+ s.add_development_dependency('riot', '~> 0.12.5')
+ s.add_development_dependency('rake')
+end
View
17 test/helper.rb
@@ -0,0 +1,17 @@
+require_relative '../lib/release_packager'
+require 'riot'
+require 'riot/rr'
+
+# TODO: These "rake-mocks" should do more than just print stuff out.
+
+def task(options)
+ puts "task #{options.map {|k, v| "#{k} => #{v}"}.join(", ") }"
+end
+
+def desc(text)
+ puts "\ndesc #{text.inspect}"
+end
+
+def file(options)
+ puts "file #{options.map {|k, v| "#{k} => #{v}"}.join(", ") }"
+end
View
48 test/project_test.rb
@@ -0,0 +1,48 @@
+require_relative "helper"
+
+module ReleasePackager
+ context Project do
+
+ context "Default" do
+ setup { Project.new(:test_project) }
+
+ asserts(:id).equals :test_project
+
+ # Defaults.
+ asserts(:output_path).equals "pkg"
+
+ # Derived values.
+ asserts(:name).equals "Test Project"
+ asserts(:folder_base).equals "pkg/test_project"
+
+ asserts("Attempting to generate tasks without any outputs") { topic.generate_tasks }.raises(RuntimeError)
+
+ asserts(:add_compression, :zip).equals :zip
+ asserts(:add_compression, :unknown).raises(ArgumentError, /unsupported compression/i)
+
+ asserts(:add_output, :source).equals :source
+ asserts(:add_output, :unknown).raises(ArgumentError, /unsupported output/i)
+ end
+
+ context "Described" do
+ setup do
+ Project.new(:test_project) do |p|
+ p.name = "Test"
+ p.version = "v0.1.5"
+ p.output_path = "test/pkg"
+
+ p.add_compression :"7z"
+ p.add_compression :zip
+
+ p.add_output :source
+ p.add_output :win32_standalone
+
+ p.files = ["frog.rb", "fish/frog.rb"]
+ end
+ end
+
+ asserts(:name).equals "Test"
+ asserts(:folder_base).equals "test/pkg/test_project_v0_1_5"
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.