Class: Releasy::Project

Inherits:
Object
  • Object
show all
Includes:
Rake::DSL, Mixins::CanExcludeEncoding, Mixins::HasPackagers, Mixins::Log
Defined in:
lib/releasy/project.rb

Overview

A description of the Ruby application that is being build for release and what packages to make from it.

Examples:

Releasy::Project.new do
  name "My Application"
  version MyApplication::VERSION

  executable "bin/my_application.rbw"
  files `git ls-files`.split("\n")
  files.exclude '.gitignore'

  exposed_files ["README.html", "LICENSE.txt"]
  add_link "http://my_application.github.com", "My Application website"
  exclude_encoding

  # Create a variety of releases, for all platforms.
  add_build :osx_app do
    url "com.github.my_application"
    wrapper "../osx_app/gosu-mac-wrapper-0.7.41.tar.gz"
    icon "media/icon.icns"
    add_package :tar_gz
  end

  add_build :source do
    add_package :"7z"
  end

  add_build :windows_folder do
    icon "media/icon.ico"
    add_package :exe
  end

  add_build :windows_installer do
    icon "media/icon.ico"
    start_menu_group "Spooner Games"
    readme "README.html" # User asked if they want to view readme after install.
    license "LICENSE.txt" # User asked to read this and confirm before installing.
    add_package :zip
  end

  add_deploy :github # Upload to a github project.
end

Constant Summary collapse

DEFAULT_PACKAGE_FOLDER =
"pkg"

Constants included from Mixins::Log

Mixins::Log::DEFAULT_LOG_LEVEL, Mixins::Log::LOG_LEVELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixins::Log

log_level, log_level=

Methods included from Mixins::CanExcludeEncoding

#exclude_encoding

Methods included from Mixins::HasPackagers

#add_package

Constructor Details

#initialize { ... } ⇒ Project #initialize {|project| ... } ⇒ Project #initializeProject

Can be used with or without a block to generate building and packaging tasks.

Overloads:

  • #initialize { ... } ⇒ Project

    Using a block, the API is more terse and the tasks are automatically generated when the block is closed (Uses a DSLWrapper). This is the preferred syntax!

    Examples:

    Releasy::Project.new do
      name "My Application"
      version "1.2.4"
      add_build :source do
        add_package :tar_gz do
          extension ".tgz"
        end
      end
    end

    Yields:

    • Block is evaluated in context of a DSLWrapper wrapping self.

  • #initialize {|project| ... } ⇒ Project

    Using a block that takes a parameter, self is passed, and so the API is similar to a Gem::Specification. The tasks are automatically generated when the block is closed

    Examples:

    Releasy::Project.new do |p|
      p.name = "My Application"
      p.version = "1.2.4"
      p.add_build :source do |b|
        b.add_package :tar_gz do |a|
          a.extension = ".tgz"
        end
      end
    end

    Yield Parameters:

    • project (Project)

      new project

  • #initializeProject

    Without using blocks, the Releasy::Project can be accessed directly. It is recommended that a block is used.

    Examples:

    project = Releasy::Project.new
    project.name = "My Application"
    project.version = "1.2.4"
    builder = project.add_build :source
    packager = builder.add_package :zip
    packager.extension = ".tgz"
    project.generate_tasks # This has to be done manually.


172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/releasy/project.rb', line 172

def initialize(&block)
  super()

  @builders = []
  @deployers = []
  @links = {}
  @files = Rake::FileList.new
  @exposed_files = Rake::FileList.new
  @output_path = DEFAULT_PACKAGE_FOLDER
  @create_md5s = false
  @name = @underscored_name = @underscored_version = nil
  @version = @executable = nil

  setup

  if block_given?
    if block.arity <= 0
      DSLWrapper.new(self, &block)
    else
      yield self
    end

    generate_tasks
  end
end

Instance Attribute Details

#executableString

Name of executable to run (defaults to ‘bin/<underscored_name>’)

Returns:

  • (String)

    the current value of executable



61
62
63
# File 'lib/releasy/project.rb', line 61

def executable
  @executable
end

#exposed_filesRake::FileList

Files which should always be copied into the archive folder root, so they are always visible to the user. e.g readme, change-log and/or license files.

Returns:

  • (Rake::FileList)

    the current value of exposed_files



61
62
63
# File 'lib/releasy/project.rb', line 61

def exposed_files
  @exposed_files
end

#filesRake::FileList

List of files to include in package.

Returns:

  • (Rake::FileList)

    the current value of files



61
62
63
# File 'lib/releasy/project.rb', line 61

def files
  @files
end

#folder_baseObject (readonly)

Base name of folders that will be created, such as “pkg/my_application” or “pkg/my_application_0_1”



61
62
63
# File 'lib/releasy/project.rb', line 61

def folder_base
  @folder_base
end

#nameString

Returns Name of the application, such as “My Application”.

Returns:

  • (String)

    Name of the application, such as “My Application”.



72
73
74
# File 'lib/releasy/project.rb', line 72

def name
  @name
end

#output_pathString

Returns Folder to output to (defaults to ‘pkg/’).

Returns:

  • (String)

    Folder to output to (defaults to ‘pkg/’)



76
77
78
# File 'lib/releasy/project.rb', line 76

def output_path
  @output_path
end

#underscored_nameString

Project name underscored (as used in file names), which will be derived from #name, but can be manually set.

Returns:

  • (String)

    the current value of underscored_name



61
62
63
# File 'lib/releasy/project.rb', line 61

def underscored_name
  @underscored_name
end

#underscored_versionString

Version number, underscored so it can be used in file names, which will be derived from #version, but can be manually set.

Returns:

  • (String)

    the current value of underscored_version



61
62
63
# File 'lib/releasy/project.rb', line 61

def underscored_version
  @underscored_version
end

#versionString

Returns Version number as a string (for example, “1.2.0”).

Returns:

  • (String)

    Version number as a string (for example, “1.2.0”).



74
75
76
# File 'lib/releasy/project.rb', line 74

def version
  @version
end

Instance Method Details

#add_build(type, &block) ⇒ Project

Add a type of build to produce. Must define at least one of these.

Parameters:

  • type (:osx_app, :source, :windows_folder, :windows_wrapped, :windows_installer, :windows_standalone)

Returns:

Raises:

  • (ArgumentError)

See Also:



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/releasy/project.rb', line 202

def add_build(type, &block)
  raise ArgumentError, "Unsupported output type #{type}" unless Builders.has_type? type
  raise ArgumentError, "Already have output #{type.inspect}" if @builders.any? {|b| b.type == type }

  builder = Builders[type].new(self)
  @builders << builder

  if block_given?
    if block.arity <= 0
      DSLWrapper.new(builder, &block)
    else
      yield builder
    end
  end

  builder
end

#add_deploy(type, &block) ⇒ Project

Add a deployment method for archived packages.

Parameters:

  • type (:github, :local, :rsync)

Returns:

Raises:

  • (ArgumentError)

See Also:



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/releasy/project.rb', line 224

def add_deploy(type, &block)
  raise ArgumentError, "Unsupported deploy type #{type}" unless Deployers.has_type? type
  raise ArgumentError, "Already have deploy #{type.inspect}" if @deployers.any? {|b| b.type == type }

  deployer = Deployers[type].new(self)
  @deployers << deployer

  if block_given?
    if block.arity <= 0
      DSLWrapper.new(deployer, &block)
    else
      yield deployer
    end
  end

  deployer
end

Add a link file to be included in the win32 releases. Will create the file title.url for you.

Parameters:

  • url (String)

    Url to link to.

  • title (String)

    Name of file to create.

Returns:



247
248
249
250
251
# File 'lib/releasy/project.rb', line 247

def add_link(url, title)
  @links[url] = title

  self
end

#create_md5snil

Create MD5 hashes for created archives.

Returns:

  • (nil)


87
# File 'lib/releasy/project.rb', line 87

def create_md5s; @create_md5s = true; nil; end

#descriptionObject

Full name of the project, including the version name E.g. “My Application” or “My Application 0.1”



291
# File 'lib/releasy/project.rb', line 291

def description; name ? "#{name}#{version ? " #{version}" : ""}" : nil; end

#generate_tasksProject

Generates all tasks required by the user. Automatically called at the end of the block, if #initialize is given a block.

Returns:

Raises:



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/releasy/project.rb', line 255

def generate_tasks
  raise ConfigError, "Must use #add_build at least once before tasks can be generated" if @builders.empty?

  # Even if there are builders specified, none may work on this platform.
  return if active_builders.empty?

  build_outputs = []
  build_groups = Hash.new {|h, k| h[k] = [] }

  active_builders.each do |builder|
    builder.send :generate_tasks
    task_name = "build:#{builder.type.to_s.tr("_", ":")}"

    if builder.type.to_s =~ /_/
      task_group = builder.send :task_group
      build_groups[task_group] << task_name
      build_outputs << "build:#{task_group}"
    else
      build_outputs << task_name
    end
  end

  build_groups.each_pair do |group, tasks|
    desc "Build all #{group}"
    task "build:#{group}" => tasks
  end

  desc "Build #{description}"
  task "build" => build_outputs

  generate_archive_tasks

  self
end

#silentnil

Make the tasks give no output at all.

Returns:

  • (nil)


83
# File 'lib/releasy/project.rb', line 83

def silent; Mixins::Log.log_level = :silent; end

#to_sString

Returns:

  • (String)


98
# File 'lib/releasy/project.rb', line 98

def to_s; "<#{self.class}#{name ? " #{name}" : ""}#{version ? " #{version}" : ""}>"; end

#underscored_descriptionObject

Full underscored name of the project. E.g. “my_application” or “my_application_0_1”



293
# File 'lib/releasy/project.rb', line 293

def underscored_description; underscored_name ? "#{underscored_name}#{version ? "_#{underscored_version}" : ""}" : nil; end

#verbosenil

Make the tasks give more detailed output.

Returns:

  • (nil)


80
# File 'lib/releasy/project.rb', line 80

def verbose; Mixins::Log.log_level = :verbose; end