1 | desc "Build the haml-coffee-source gem"
|
2 | task :gem do
|
3 | sh "grunt dist"
|
4 |
|
5 | require "json"
|
6 | require "fileutils"
|
7 | require "rubygems"
|
8 | require "tmpdir"
|
9 | require "rubygems/package"
|
10 |
|
11 | gemspec = Gem::Specification.new do |s|
|
12 | s.name = "haml-coffee-source"
|
13 | s.version = JSON.parse(File.read("package.json"))["version"].gsub("-", ".")
|
14 | s.date = Time.now.strftime("%Y-%m-%d")
|
15 |
|
16 | s.homepage = "https://github.com/netzpirat/haml-coffee/"
|
17 | s.summary = "Haml Coffee Compiler"
|
18 | s.description = "JavaScript source code for the Haml Coffee compiler"
|
19 |
|
20 | s.license = "MIT"
|
21 |
|
22 | s.files = [
|
23 | "lib/haml_coffee/hamlcoffee.js",
|
24 | "lib/haml_coffee/source.rb"
|
25 | ]
|
26 |
|
27 | s.authors = ["Michael Kessler"]
|
28 | s.email = "michi@netzpiraten.ch"
|
29 | end
|
30 |
|
31 |
|
32 | root = Dir.getwd
|
33 |
|
34 | Dir.mktmpdir do |tmpdir|
|
35 | Dir.chdir(tmpdir) do
|
36 | FileUtils.mkdir_p "lib/haml_coffee/"
|
37 |
|
38 | File.open "lib/haml_coffee/source.rb", "w" do |f|
|
39 | f.write <<-RB
|
40 | module HamlCoffee
|
41 | module Source
|
42 | VERSION = #{gemspec.version.to_s.inspect}
|
43 |
|
44 | def self.bundled_path
|
45 | File.expand_path("../hamlcoffee.js", __FILE__)
|
46 | end
|
47 | end
|
48 | end
|
49 | RB
|
50 | end
|
51 |
|
52 | FileUtils.copy File.join(root, "dist/compiler/hamlcoffee.min.js"), "lib/haml_coffee/hamlcoffee.js"
|
53 |
|
54 | if defined?(Gem::Builder) # Rubygems 1
|
55 | Gem::Builder.new(gemspec).build
|
56 | else # Rubygems 2
|
57 | Gem::Package.build gemspec
|
58 | end
|
59 |
|
60 | pkg = File.join(root, 'pkg')
|
61 | FileUtils.mkdirr(pkg) unless File.exists?(pkg)
|
62 | FileUtils.copy gemspec.file_name, pkg
|
63 |
|
64 | end
|
65 | end
|
66 | warn "Built #{gemspec.file_name}"
|
67 | end
|