Add check for missing dependency files

This commit is contained in:
syeopite 2024-02-18 14:15:44 -08:00
parent 392e447969
commit 9c0cb2a513
No known key found for this signature in database
GPG Key ID: A73C186DA3955A1A
1 changed files with 29 additions and 11 deletions

View File

@ -58,27 +58,45 @@ end
# different or the requested dependency just isn't present, then it needs to be # different or the requested dependency just isn't present, then it needs to be
# installed. # installed.
# Since we can't know when videojs-youtube-annotations is updated, we'll just always fetch
# a new copy each time.
dependencies_to_install = [] of String dependencies_to_install = [] of String
required_dependencies.keys.each do |dep| required_dependencies.keys.each do |dep|
dep = dep.to_s dep = dep.as_s
path = "assets/videojs/#{dep}" path = "assets/videojs/#{dep}"
# Check for missing dependencies # Check for missing dependencies
#
# Does the directory exist?
# Does the Javascript file exist?
# Does the CSS file exist?
#
# videojs-contrib-quality-levels.js is the only dependency that does not come with a CSS file so
# we skip the check there
if !Dir.exists?(path) if !Dir.exists?(path)
Dir.mkdir(path) Dir.mkdir(path)
dependencies_to_install << dep next dependencies_to_install << dep
else elsif !(File.exists?("#{path}/#{dep}.js") || File.exists?("#{path}/versions.yml"))
next dependencies_to_install << dep
elsif dep != "videojs-contrib-quality-levels" && !File.exists?("#{path}/#{dep}.css")
next dependencies_to_install << dep
end
# Check if we need to update the dependency
config = File.open("#{path}/versions.yml") do |file| config = File.open("#{path}/versions.yml") do |file|
YAML.parse(file).as_h YAML.parse(file).as_h
end end
if config["version"].as_s != required_dependencies[dep]["version"].as_s || config["minified"].as_bool != minified if config["version"].as_s != required_dependencies[dep]["version"].as_s || config["minified"].as_bool != minified
`rm -rf #{path}/*.js #{path}/*.css` # Clear directory
dependencies_to_install << dep {"*.js", "*.css"}.each do |file_types|
Dir.glob("#{path}/#{file_types}").each do |file_path|
File.delete(file_path)
end end
end end
dependencies_to_install << dep
end
end end
# Now we begin the fun part of installing the dependencies. # Now we begin the fun part of installing the dependencies.