0

I am working on an HTML5/JavaScript app with Ruby packaging to be used on multiple platforms including a dash display unit on a car. The code base is the same across platforms except for a single wrapper file that houses all of the API-specific calls for a single platform: i.e. "sdk.web.js" or "sdk.car.js".

I'm hoping to modify the current PackageTask to allow an input for a target platform. Depending on the target, I want the corresponding wrapper file to be renamed to "sdk.js" and included in the package, disregarding the rest to keep the zip archive as small as possible.

From terminal, I want to say something like:

rake target "web"

which would put together a package including "sdk.web.js" renamed "sdk.js". Anyone know if this is possible, and how I would modify my existing RakeFile (below) in order to accomplish this?

require 'fileutils'
require 'rake/packagetask'

VERSION = ""

task :default => [:package]

def parse_version(filename)
  f = File.open(filename, "rb")
  contents = f.read
  m = contents.match('var version = "([0-9.]+)";')
  if m
    return m[1]
  else
    return nil
  end
end

desc "Package up the app into a zip file"
Rake::PackageTask.new("myApp") do |p|
  p.version = parse_version("js/application.js")
  p.need_zip = true
  p.package_files = FileList["*", "**/*"]
  p.package_files.exclude(".git", "pkg/*", "Rakefile", ".rvmrc", "Gemfile", "Gemfile.lock", ".project", ".settings", ".gitignore", "data/store/*", "docs", "docs/*")
end
sawa
  • 165,429
  • 45
  • 277
  • 381
Danny
  • 3,615
  • 6
  • 43
  • 58

1 Answers1

1

In general, you can pass arguments to rake tasks. See for instance this page.

However, you don't have access to the package task from PackageTask. A solution would be to define your own packaging task which would add the right js script and then invoke package manually. For instance (untested):

Rake::PackageTask.new("myApp") do |p|
  [snip]
  p.package_files << "sdk.js"
end

task 'custom_packaging', :sdk do |t, args|
  # Copy the right file to sdk.js
  FileUtils.cp_f "sdk.#{args[:sdk]}.js", "sdk.js"
  Rake::Task["package"].invoke
end
sylvain.joyeux
  • 1,659
  • 11
  • 14