Module: ZendeskAppsTools::PackageHelper

Included in:
CommandHelpers
Defined in:
lib/zendesk_apps_tools/package_helper.rb

Instance Method Summary collapse

Instance Method Details

#app_packageObject



4
5
6
7
# File 'lib/zendesk_apps_tools/package_helper.rb', line 4

def app_package
  require 'zendesk_apps_support'
  @app_package ||= ZendeskAppsSupport::Package.new(app_dir.to_s)
end

#manifestObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/zendesk_apps_tools/package_helper.rb', line 9

def manifest
  require 'zendesk_apps_support'
  require 'zendesk_apps_support/manifest/no_override_hash'
  begin
    @manifest ||= app_package.manifest
  rescue JSON::ParserError, ZendeskAppsSupport::Manifest::OverrideError => e
    say_status "error", "Manifest file is incorrectly formatted: #{e.message}", :red and exit 1
  rescue Errno::ENOENT
    say_status "error", "Manifest file cannot be found in the given path. Check you are pointing to the path that contains your manifest.json", :red and exit 1
  end
end

#zip(archive_path) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/zendesk_apps_tools/package_helper.rb', line 21

def zip(archive_path)
  require 'zip'
  Zip::File.open(archive_path, 'w') do |zipfile|
    app_package.files.each do |file|
      relative_path = file.relative_path
      path = relative_path
      say_status 'package', "adding #{path}"

      # resolve symlink to source path
      if File.symlink? file.absolute_path
        path = File.expand_path(File.readlink(file.absolute_path), File.dirname(file.absolute_path))
      end
      if file.to_s == 'app.scss'
        relative_path = relative_path.sub 'app.scss', 'app.css'
      end
      zipfile.add(relative_path, app_dir.join(path).to_s)
    end
  end
end