mirror of
https://0xacab.org/sutty/sutty
synced 2024-07-01 12:36:08 +00:00
80 lines
1.6 KiB
Ruby
80 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'zip'
|
|
|
|
# Genera un ZIP a partir del sitio ya generado y lo coloca para descarga
|
|
# dentro del sitio público.
|
|
#
|
|
# TODO: Firmar con minisign
|
|
class DeployZip < Deploy
|
|
# El hostname es el nombre del archivo.
|
|
validates :hostname, format: { with: /\.zip\z/ }
|
|
|
|
# Una vez que el sitio está generado, tomar todos los archivos y
|
|
# y generar un ZIP accesible públicamente.
|
|
#
|
|
# @return [Boolean]
|
|
def deploy
|
|
remove_destination!
|
|
|
|
time_start
|
|
Dir.chdir(destination) do
|
|
Zip::File.open(hostname, 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
|
|
|
|
# La URL de descarga del archivo.
|
|
#
|
|
# @return [String]
|
|
def url
|
|
"#{site.deploy_local.url}/#{hostname}"
|
|
end
|
|
|
|
# Devuelve el tamaño del ZIP en bytes
|
|
#
|
|
# @return [Integer]
|
|
def size
|
|
File.size path
|
|
end
|
|
|
|
# El archivo ZIP se guarda dentro del sitio local para poder
|
|
# descargarlo luego.
|
|
#
|
|
# @return [String]
|
|
def destination
|
|
site.deploy_local.destination
|
|
end
|
|
|
|
# El "hostname" es la ubicación del archivo.
|
|
#
|
|
# @return [String]
|
|
def default_hostname
|
|
"#{site.deploy_local.hostname}.zip"
|
|
end
|
|
|
|
def path
|
|
File.join(destination, hostname)
|
|
end
|
|
|
|
private
|
|
|
|
def remove_destination!
|
|
FileUtils.rm_f path
|
|
end
|
|
|
|
def implements_hostname_validation?
|
|
true
|
|
end
|
|
end
|