Sha256: 62c9efd6a55e4d0a70c51b53f4452488aace064ea6a44d7a46e50d6bd59bfe64

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

#!/usr/bin/env ruby

require 'logger'

err_log = Logger.new(STDERR)

EFF_WIRE_ROOT = File.join(__dir__, '..', '..')

EFF_PROTO_ROOT =
  begin
    ENV.fetch('EFF_PROTO_ROOT')
  rescue KeyError
    File.join(EFF_WIRE_ROOT, 'proto')
  end

proto_paths = Dir.glob("#{EFF_PROTO_ROOT}/**/*").select do |proto_path|
  next(false) if File.directory?(proto_path)
  true
end

if proto_paths.empty?
  raise <<-EOV

  
  No definitions found in #{EFF_PROTO_ROOT}!

    Either:
      1. Run ./bin/bootstrap in the project root directory, or
      2. Set EFF_PROTO_ROOT to the location of your proto definitions

  EOV
end

proto_paths.each do |proto_path|
  if File.extname(proto_path) != '.proto'
    err_log.warn("Stray file '#{File.basename(proto_path)}' " \
                 "found! Run bin/clean?")
    next
  end

  exclusion_index =
    proto_path.split('/').length - 1 == EFF_PROTO_ROOT.split('/').length ? -3
                                                                     : -2
  rel_path           = proto_path[EFF_PROTO_ROOT.length+1..-1]
  package_components =
    [
      'effigy',
      'wire',
      rel_path.split('/')[0..exclusion_index] # ditch filename.proto
    ].flatten

  package = package_components.join('.')

  puts "> Packaging #{File.basename(proto_path)} in '#{package}'." 

  cmd = "sed -i '1s/^/package #{package};\\n\\n/' #{proto_path}"
  system(cmd)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
effigy_wire-0.0.3 bin/support/30-package_proto