Skip to content

Instantly share code, notes, and snippets.

@kaikoga
Last active January 27, 2024 10:49
Show Gist options
  • Save kaikoga/452569e1e3b3470d386123e3d4d20b10 to your computer and use it in GitHub Desktop.
Save kaikoga/452569e1e3b3470d386123e3d4d20b10 to your computer and use it in GitHub Desktop.
vrc-bundle
#!/usr/bin/env ruby
# How to use:
# $ cd /path/to/vpm.package
# $ vrc-bundle
# $ mv *.zip /path/to/vpm.repository
# $ cd /path/to/vpm.repository
# $ vrc-bundle
def package
require "json"
require "fileutils"
require "shellwords"
pack = JSON.parse(File.read("package.json"))
pack_name = pack["name"]
pack_version = pack["version"]
filename = "#{pack_name}-#{pack_version}.zip"
files = Dir.glob("**/*") - [".DS_store"]
FileUtils.rm_f filename
`zip #{filename} #{files.shelljoin}`
File.write("package.json", JSON.pretty_generate(pack))
end
def listing
require "json"
index = JSON.parse(File.read("index.json"))
url_base = File.dirname(index["url"])
packs = Dir.glob("**/*.zip").map do |filename|
next unless filename.include? "/"
json = `unzip -p #{filename} package.json`
pack = JSON.parse(json)
pack['url'] = File.join(url_base, filename)
pack
end
index['packages'] = packs
.group_by{|pack| pack["name"]}
.transform_values{|group| {"versions" => group.group_by{|pack| pack["version"] }.transform_values(&:first) }}
File.write("index.json", JSON.pretty_generate(index))
end
if File.exist?("package.json")
package
elsif File.exist?("index.json")
listing
else
puts "Requires package.json or index.json"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment