mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-16 22:26:22 +00:00
59 lines
1.1 KiB
Ruby
59 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'zip'
|
|
|
|
# Genera un ZIP a partir del sitio ya construido
|
|
#
|
|
# TODO: Firmar con minisign
|
|
class DeployZip < Deploy
|
|
store :values, accessors: %i[], coder: JSON
|
|
|
|
# Una vez que el sitio está generado, tomar todos los archivos y
|
|
# y generar un zip accesible públicamente.
|
|
#
|
|
# rubocop:disable Metrics/MethodLength
|
|
def deploy(**)
|
|
FileUtils.rm_f path
|
|
|
|
time_start
|
|
Dir.chdir(destination) do
|
|
Zip::File.open(path, Zip::File::CREATE) do |z|
|
|
Dir.glob('./**/**').each do |f|
|
|
File.directory?(f) ? z.mkdir(f) : z.add(f, f)
|
|
end
|
|
end
|
|
end
|
|
time_stop
|
|
|
|
build_stats.create action: 'zip',
|
|
seconds: time_spent_in_seconds,
|
|
bytes: size
|
|
|
|
File.exist? path
|
|
end
|
|
# rubocop:enable Metrics/MethodLength
|
|
|
|
def limit
|
|
1
|
|
end
|
|
|
|
def size
|
|
File.size path
|
|
end
|
|
|
|
def destination
|
|
File.join(Rails.root, '_deploy', site.hostname)
|
|
end
|
|
|
|
def file
|
|
"#{site.hostname}.zip"
|
|
end
|
|
|
|
def url
|
|
"#{site.url}#{file}"
|
|
end
|
|
|
|
def path
|
|
File.join(destination, file)
|
|
end
|
|
end
|