Class: MilkTea::PackageManifest
- Inherits:
-
Object
- Object
- MilkTea::PackageManifest
- Defined in:
- lib/milk_tea/packages/manifest.rb
Defined Under Namespace
Classes: DataView, DependencyView
Class Method Summary collapse
- .default_package_name_for_root(root_dir) ⇒ Object
- .load(path) ⇒ Object
-
.load_option(path) ⇒ Object
Best-effort manifest load for optional lookups: returns nil when no manifest applies to the path or when the manifest is invalid, instead of raising PackageManifestError.
- .manifest_exists_for?(path) ⇒ Boolean
- .snake_case_identifier(name) ⇒ Object
Instance Method Summary collapse
-
#initialize(path) ⇒ PackageManifest
constructor
A new instance of PackageManifest.
- #load ⇒ Object
Constructor Details
#initialize(path) ⇒ PackageManifest
Returns a new instance of PackageManifest.
66 67 68 |
# File 'lib/milk_tea/packages/manifest.rb', line 66 def initialize(path) @path = File.(path) end |
Class Method Details
.default_package_name_for_root(root_dir) ⇒ Object
28 29 30 |
# File 'lib/milk_tea/packages/manifest.rb', line 28 def self.default_package_name_for_root(root_dir) snake_case_identifier(File.basename(File.(root_dir))) end |
.load(path) ⇒ Object
41 42 43 |
# File 'lib/milk_tea/packages/manifest.rb', line 41 def self.load(path) new(path).load end |
.load_option(path) ⇒ Object
Best-effort manifest load for optional lookups: returns nil when no manifest applies to the path or when the manifest is invalid, instead of raising PackageManifestError.
48 49 50 51 52 |
# File 'lib/milk_tea/packages/manifest.rb', line 48 def self.load_option(path) load(path) rescue PackageManifestError nil end |
.manifest_exists_for?(path) ⇒ Boolean
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/milk_tea/packages/manifest.rb', line 54 def self.manifest_exists_for?(path) path = File.(path) current = File.directory?(path) ? path : File.dirname(path) loop do return true if File.file?(File.join(current, "package.toml")) parent = File.dirname(current) break if parent == current current = parent end false end |
.snake_case_identifier(name) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/milk_tea/packages/manifest.rb', line 32 def self.snake_case_identifier(name) name.to_s .gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr("- ", "__") .gsub(/_+/, "_") .downcase end |
Instance Method Details
#load ⇒ Object
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 |
# File 'lib/milk_tea/packages/manifest.rb', line 70 def load manifest_path, root_dir = resolve_manifest_path(@path) raise PackageManifestError, "package manifest not found for #{@path}" unless manifest_path config = parse_manifest(manifest_path) package = config.fetch("package", {}) build = config.fetch("build", {}) profile_config = config.fetch("profile", {}) platform_config = config.fetch("platform", {}) package_name = package["name"] if package_name.nil? || package_name.empty? package_name = self.class.default_package_name_for_root(root_dir) end package_version = package["version"] package_version = package_version.to_s unless package_version.nil? package_version = nil if package_version == "" package_kind = normalize_package_kind(package["kind"] || build["type"] || default_package_kind(build)) source_root_value = package["source_root"] || default_source_root(root_dir) source_root = File.(source_root_value.to_s, root_dir) unless File.directory?(source_root) raise PackageManifestError, "package.source_root not found: #{source_root_value} (resolved to #{source_root})" end profile_name = normalize_profile_name(build["profile"] || profile_config["default"]) platform_name = normalize_platform_name(build["platform"] || platform_config["default"]) source_path = resolve_source_path(root_dir, build, package_kind) output_path = build["output"] output_path = File.(output_path.to_s, root_dir) if output_path assets_paths = parse_assets_paths(build["assets"], root_dir) html_template_path = build["html_template"] if html_template_path html_template_path = File.(html_template_path.to_s, root_dir) unless File.file?(html_template_path) raise PackageManifestError, "build.html_template not found: #{build["html_template"]} (resolved to #{html_template_path})" end end dependencies = parse_dependencies(config.fetch("dependencies", {}), root_dir:, manifest_path:) DataView.new( root_dir:, manifest_path:, package_name:, package_version:, package_kind:, source_root:, source_path:, profile: profile_name, platform: platform_name, output_path:, assets_paths:, html_template_path:, dependencies:, ) end |