Top Level Namespace

Constant Summary collapse

JRAKE_ROOT =
File.dirname(File.join __FILE__)

Instance Method Summary collapse

Instance Method Details

#build_areaObject

Get the build area path



60
61
62
# File 'lib/helpers/helpers.rb', line 60

def build_area
  "./packages/#{$package['name']}-#{version_name}#{package_tag}"
end

#build_component(name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/tasks/components.rb', line 11

def build_component(name)
  component_build_area = File.join(build_area, 'com_' + name)

  mkdir_p component_build_area

  {"/administrator" => "admin","" => "site"}.each do |context,target_context|
    # Do Languages
    language_dirs = Dir.glob(".#{context}/language/*")

    language_dirs.each do |language_dir|
      language = language_dir.split("/").last

      language_files = Rake::FileList.new(".#{context}/language/#{language}/*")

      language_files.each do |language_file|

        if language_file.include?(name)

          copy_to_dir = File.join(component_build_area, target_context, "language" , language)
          mkdir_p copy_to_dir rescue nil
          cp language_file , copy_to_dir

        end

      end
    end

    # Do the other stuff
    mkdir_p File.join(component_build_area , target_context)
    files = Rake::FileList.new(".#{context}/components/com_#{name}/**/*")

    # Copy the installer script.
    if context == '/administrator'
      cp "./administrator/components/com_#{name}/script.php" , File.join(component_build_area, 'script.php')
    end

    files.each do |file_name|
      target_file_name = file_name.gsub(".#{context}/components/com_#{name}", target_context)
      if File.directory?(file_name)
        mkdir_p File.join(component_build_area, target_file_name)
      else
        copy_to = File.join(component_build_area, File.dirname(target_file_name))
        mkdir_p copy_to unless File.exist?(copy_to)
        cp file_name, File.join(copy_to,  File.basename(target_file_name)) 
      end
    end
  end
  
  # Build the manifest
  manifest_path = File.join(component_build_area , name + '.xml')
  manifest_file = File.open(manifest_path, 'w:UTF-8')
  manifest = Builder::XmlMarkup.new(:indent => 4, :target => manifest_file)

  manifest.instruct!

  manifest.extension({
                       :type => "component" , 
                       :version => $package['package']['target_version'] , 
                       :method => "upgrade"}) do |ext|

    ext.comment! "Manifest generated by builder script at #{Time.now}"

    ext.name 'com_' + name
    ext.description"COM_#{name.upcase}_XML_DESCRIPTION"
    ext.version version_name
    ext.copyright $package['package']['copyright']
    ext.creationDate "01 Jan 2010"
    ext.author $package['package']['author']
    ext.authorEmail $package['package']['author_email']
    ext.authorUrl $package['package']['author_url']

    ext.install do |install|
      install.sql do |sql|
        sql.file({:driver => "mysql" , :charset => "utf8"}, "sql/install.mysql.utf8.sql")
      end
    end


    ext.uninstall do |uninstall|
      uninstall.sql do |sql|
        sql.file({:driver => "mysql" , :charset => "utf8"}, "sql/uninstall.mysql.utf8.sql")
      end
    end

    ext.update do |update|
      update.schemas do |schema|
        schema.schemapath({:type => "mysql"}, "sql/updates")
      end
    end


    ext.scriptfile "script.php" if File.exist?( File.join(component_build_area , 'admin' , 'script.php') )
    
    ext.administration({:folder => 'admin'}) do |admin|
      admin.menu({:img => "components/com_#{name}/assets/menu_icon.png"}, "COM_#{name.upcase}_MENUTITLE")

      admin.languages({:folder => 'admin'}) do |languages|
        language_dirs = Dir.glob( File.join(component_build_area, 'admin', 'language', '*') )
        language_dirs.each do |language_dir|

          language_code = language_dir.split('/').last
          language_files = Dir.glob(File.join(language_dir , '*.ini'))

          language_files.each do |language_file|
            language_path = File.join('language', language_code, (File.basename language_file))
            languages.language({:tag => language_code}, language_path)
          end # language_files.each
        end # language_dir.each
      end # admin.languages
                            

      admin.files({:folder => "admin"}) do |files|
        Dir.glob(File.join(component_build_area , 'admin' , '*')).each do |f|
          if File.directory? f
            files.folder File.basename( f )
          else
            files.filename File.basename( f )
          end
        end
      end # Admin files
    end   # Admin

    ext.languages({:folder => 'site'}) do |languages|

        language_dirs = Dir.glob( File.join(component_build_area, 'site', 'language', '*') )
        language_dirs.each do |language_dir|

          language_code = language_dir.split('/').last
          language_files = Dir.glob(File.join(language_dir , '*.ini'))

          language_files.each do |language_file|
            language_path = File.join('language', language_code, (File.basename language_file))
            languages.language({:tag => language_code}, language_path)
          end # language_files.each
        end # language_dir.each
    end   # Admin

    ext.files({:folder => "site"}) do |files|
      Dir.glob(File.join(component_build_area, 'site' , '*')).each do |f|
        if File.directory? f
          files.folder File.basename( f )
        else
          files.filename File.basename( f )
        end # IF
      end # Files.each
    end   # Files
  end     # Manifest

  manifest.target!
  manifest_file.flush
  manifest_file.close

  chdir(component_build_area) do
    sh %{zip -r ../com_#{name}.zip *}
  end

end

#build_library(name) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/tasks/libraries.rb', line 8

def build_library(name)
  lib_build_area = File.join(build_area , 'lib_' + name)
    
  mkdir_p lib_build_area
  files = Rake::FileList.new("./libraries/#{name}/**/*")
  
  files.each do |file_name|
    new_file_name = file_name.gsub("./libraries/#{name}/",'')
    if File.directory?(file_name)
      mkdir_p File.join(lib_build_area, new_file_name)
    else
      copy_to = File.join(lib_build_area , File.dirname(new_file_name))
      mkdir_p copy_to unless File.exist?(copy_to)
      cp file_name, File.join(copy_to , File.basename(file_name))
    end
  end

  manifest_path = File.join(lib_build_area, name + '.xml')
  manifest_file = File.open(manifest_path , 'w')
  manifest = Builder::XmlMarkup.new(:indent => 2, :target => manifest_file)
  
  manifest.instruct!

  manifest.extension({
                       :type => "library",
                       :version => $package['package']['target_version'],
                       :method => "upgrade"}) do |ext|
    ext.name "#{name.capitalize} Library"
    ext.libraryname name
    ext.version version_name
    ext.copyright $package['package']['copyright']
    ext.creationDate "01 Jen 2010"
    ext.author $package['package']['author']
    ext.authorEmail $package['package']['author_email']
    ext.authorUrl $package['package']['author_url']
    
    ext.files do |files|
      chdir(lib_build_area) do
        Dir.glob('*').each do |f|
          if File.directory? f
            files.folder f
          else
            files.file f
          end # File.directory?
        end # Dir.glob.each
      end # chdir
    end # ext.files
  end # ext

  if $package['js'].keys.include? "libraries/#{name}"
    compile_js_sources(lib_build_area, $package['js']["libraries/#{name}"])
  end

  manifest.target!
  manifest_file.flush
  manifest_file.close

  chdir(lib_build_area) do
    sh %{zip -r ../lib_#{name}.zip *}
  end
end

#build_module(module_name) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/tasks/modules.rb', line 8

def build_module(module_name)
  module_build_area = File.join(build_area, 'mod_' + module_name)
  
  mkdir_p module_build_area
  
  files = Rake::FileList.new("./modules/mod_#{module_name}/**/*")

  files.each do |file_name|
    new_file_name = file_name.gsub("./modules/mod_#{module_name}", '')
    
    if File.directory? file_name
      mkdir_p File.join(module_build_area, new_file_name)
    else
      copy_to = File.join(module_build_area, File.dirname(new_file_name))
      mkdir_p copy_to unless File.exist? copy_to
      cp file_name, File.join(copy_to, File.basename(new_file_name))
    end
  end

  # Handle language files
  language_dirs = Dir.glob("./language/*")
  language_dirs.each do |language_dir|
    language_code = File.basename(language_dir)
    
    language_files = Rake::FileList.new(File.join(language_dir, "#{language_code}.mod_#{module_name}.*ini"))
    language_files.each do |f|
      cp f , File.join(module_build_area , File.basename(f))
    end
  end

  chdir(module_build_area) do
    sh %{zip -r ../mod_#{module_name}.zip *}
  end

end

#build_plugin(group, name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/tasks/plugins.rb', line 11

def build_plugin(group, name)

  plugin_build_area = File.join(build_area , 'plg_'+ group + '_' + name)
  
  mkdir_p plugin_build_area

  files = Rake::FileList.new("./plugins/#{group}/#{name}/**/*")
  
  files.each do |file_name|
    new_file_name = file_name.gsub("./plugins/#{group}/#{name}",'')
    if File.directory? file_name
      mkdir_p File.join(plugin_build_area, new_file_name)
    else
      copy_to = File.join(plugin_build_area , File.dirname(new_file_name))
      mkdir_p copy_to unless File.exist? copy_to
      cp file_name, File.join( copy_to, File.basename(new_file_name))
    end
  end

  # Handle language files
  language_dirs = Dir.glob("./language/*")
  language_dirs.each do |language_dir|
    language_code = File.basename(language_dir)
    
    language_files = Rake::FileList.new(File.join(language_dir, "#{language_code}.plg_#{group}_#{name}.*ini"))
    language_files.each do |f|
      cp f , File.join(plugin_build_area , File.basename(f))
    end
  end

  # Update the manifest meta data:
  manifest_file = "#{plugin_build_area}/#{name}.xml"
  manifest = ''

  File.open(manifest_file, "r") do |file|
    manifest = file.read()
    manifest = template(manifest, { 
      'release.version' => version_name,
      'project.creation.date' => '01 Jan 2010',
      'project.author' => $package['package']['author'],
      'project.licence' => $package['package']['licence'],
      'project.copyright' => $package['package']['copyright'],
      'project.author.email' => $package['package']['author_email'],
      'project.author.url' => $package['package']['author_url']
    })
  end
  File.open(manifest_file, "w") do |file|
    file.puts manifest
  end

  chdir(plugin_build_area) do
    sh %{zip -r ../plg_#{group}_#{name}.zip *}
  end
end

#build_template(template_name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/tasks/templates.rb', line 11

def build_template(template_name)
  template_build_area = File.join(build_area, 'tpl_' + template_name)

  # Copy Files
  mkdir_p template_build_area

  template_files = Rake::FileList.new("./templates/#{template_name}/**/*")

  template_files.each do |file_name|
    target_file_name = file_name.gsub("./templates/#{template_name}", '')

    if File.directory? file_name
      mkdir_p File.join(template_build_area, target_file_name)
    else
      copy_to = File.join(template_build_area, File.dirname(target_file_name))
      mkdir_p copy_to unless File.exist?(copy_to)
      cp file_name, File.join(copy_to, File.basename(target_file_name))
    end
  end

  # Copy Language Files
  language_codes = Dir.glob("./languages/*").each { |d| File.basename d }
  
  language_codes.each do |language|
    language_files = Rake::FileList.new("./languages/#{language}/*.ini")
    
    language_files.each do |language_file|
      if language_file.include? template_name
        cp language_file , File.join(template_build_area, File.basename(language_file) )
      end
    end

  end

  # Process any LESS files
  $package['less'].keys.each do |file|
    compile_less_styles(template_build_area, $package['less'][file])
  end

  chdir(template_build_area) do
    sh %{zip -r ../tpl_#{template_name}.zip *}
  end

end

#commit_countString

Get the commit count

Uses the git CLI to get the commit count

Returns:

  • (String)

    Commit Count



32
33
34
35
# File 'lib/helpers/helpers.rb', line 32

def commit_count
  v = `git rev-list HEAD --count`
  v.strip!
end

#compile_js_sources(base_dir, definitions) ⇒ Object

Compile JS into minified sources

Compiles JS sources defined in definitions



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/tasks/jsminify.rb', line 9

def compile_js_sources(base_dir, definitions)
  chdir(base_dir) do
    definitions.each do |definition|

      jscompressor = :uglifyjs

      sources = definition['inputs'].join(' ')

      sh %{cat #{sources} > #{definition['output']}.tmp}
      sh %{#{jscompressor} #{definition['output']}.tmp > #{definition['output']}}
      rm definition['output'] + '.tmp'
    end
  end
end

#compile_less_styles(base_dir, definitions) ⇒ Object

Compile less styles

Compiles less styles defined in definition

Parameters:

  • definitions (array)

    file definitions



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/tasks/less.rb', line 12

def compile_less_styles(base_dir, definitions)

  chdir(base_dir) do
    definitions.each do |definition|

      lessc = 'lessc'
      flags = []

      if definition['optimize']
        case definition['optimize']
          when TrueClass then
          flags << '-O2'
          else
          flags << '-O' + definition['optimize']
        end
      end

      if definition['include']
        flags << "--include-path=" + definition['include'].join(':')
      end

      sources = definition['inputs'].join(' ')

      sh %{#{lessc} #{flags.join(' ')} #{sources} #{definition['output']}}

    end
  end
end

#generate_release_notesObject



1
2
3
4
5
6
7
8
9
10
11
# File 'lib/tasks/package.rb', line 1

def generate_release_notes

  require 'redcarpet'

  renderer = Redcarpet::Render::HTML.new({with_toc_data: true, hard_wrap: true})
  markdown = Redcarpet::Markdown.new(renderer, {no_intra_emphasis: true, tables: true})

  release_note_source = File.read("./release_notes.md")

  markdown.render(release_note_source)
end

#get_js_filesObject



14
15
16
17
18
# File 'lib/tasks/codesniff.rb', line 14

def get_js_files
  
  Dir["**/*.js"]

end

#get_php_filesObject

Helpers for Codesniffing



7
8
9
10
11
# File 'lib/tasks/codesniff.rb', line 7

def get_php_files

  Dir["**/*.php"]

end

#package_file_pathObject

Path file Location



46
47
48
# File 'lib/helpers/helpers.rb', line 46

def package_file_path
  "./packages/#{$package['name']}/#{package_name}.zip"
end

#package_filesObject

Deprecated.

Get files to (not) be packaged



52
53
54
55
56
57
# File 'lib/helpers/helpers.rb', line 52

def package_files
  package_files = Rake::FileList.new "**/*"
  package_files.exclude(/^(packages\/.*|Rakefile|\.git|README\.md)/)

  package_files
end

#package_nameString

Get the package name

Returns:

  • (String)

    Package Name



40
41
42
# File 'lib/helpers/helpers.rb', line 40

def package_name
  "pkg_#{$package['name']}-#{version_name}#{package_tag}"
end

#package_tagObject



74
75
76
77
78
79
80
# File 'lib/helpers/helpers.rb', line 74

def package_tag
  branch = `git rev-parse --abbrev-ref HEAD`

  return '' if branch == 'master'

  '-' + branch.strip!
end

#s3_bucketObject



87
88
89
90
# File 'lib/helpers/helpers.rb', line 87

def s3_bucket
  $package['s3']['test_bucket'] if package_tag
  $package['s3']['bucket']
end

#s3_credentialsObject

Get the S3 Credentials



6
7
8
9
10
11
12
13
14
# File 'lib/tasks/s3_upload.rb', line 6

def s3_credentials

  {
    :access_key_id => ENV['AWS_ACCESS_KEY_ID'] || $package['s3']['access_key_id'],
    :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'] || $package['s3']['secret_access_key'],
    :region => ENV['AWS_REGION'] || $package['s3']['region']
  }

end

#template(template, values) ⇒ Object

Replace template values



65
66
67
68
69
70
71
# File 'lib/helpers/helpers.rb', line 65

def template( template, values )
  output = template.clone()
  values.keys.each { |key|
    output.gsub!( /{{#{key}}}/, values[ key ].to_s )
  }
  output
end

#update_manifestObject

Get the update manifest



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/helpers/manifest_generators.rb', line 2

def update_manifest
  document = Builder::XmlMarkup.new(:indent => 2)
  
  document.updates do |updates|
    updates.comment! "Update manifest: Generated by Builder Script at #{Time.now}"
    updates.update do |u|
      u.name $package['package']['name']
      u.description $package['package']['description']
      u.element "pkg_#{$package['name']}"
      u.type 'package'
      u.version version_name
      u.downloads do |d|
        d.downloadurl({:type => "full" , :format => "zip"}, "#{update_site}/#{package_name}.zip")
      end
      u.tags do |t|
        t.tag 'stable'
      end
      u.infourl $package['package']['info_url'] || "http://www.mrzen.com/travelzen"
      u.maintainer $package['package']['maintainer'] || 'MrZen Ltd'
      u.maintainerurl $package['package']['maintainer_url'] || 'http://www.mrzen.com'
      u.targetplatform({:name => 'joomla', :version => $package['package']['target_version']})
      u.section 'Updates'
      u.client 'administrator'
    end
  end

  document.target!
end

#update_siteObject



82
83
84
85
# File 'lib/helpers/helpers.rb', line 82

def update_site
  $package['package']['test_update_site'] if package_tag
  $package['package']['update_site']
end

#version_nameString

Get Version Name.

Version name is taken from the package description.

Returns:

  • (String)

    Verison Name



18
19
20
21
22
23
24
# File 'lib/helpers/helpers.rb', line 18

def version_name
  version = $package['package']['version'].to_s + '.' + commit_count

  ENV['JR_PACKAGE_VERSION'] ||= version

  version
end