Migrate npm run scripts to Rakefile tasks

Rakefile is like Makefile - it has dependency management,
while npm run scripts do not.

Aside from that, this also allows us to drop literally all Node.js packages,
as uglify-js is self-contained and has no dependencies.
Reduced node_modules from 17M to 374K.
This commit is contained in:
iBug
2024-05-05 04:03:07 +08:00
parent 6165d896a0
commit 0b8b5230f9
6 changed files with 39 additions and 1783 deletions
+31 -3
View File
@@ -3,10 +3,11 @@ require "jekyll"
require "json"
require "listen"
require "rake/clean"
require "shellwords"
require "time"
require "yaml"
task :default => [:copyright, :changelog]
task :default => [:copyright, :changelog, :js]
package_json = JSON.parse(File.read("package.json"))
@@ -73,8 +74,7 @@ task :preview do
puts " Halting auto-regeneration."
exit 0
end
loop { sleep 1000 }
sleep
end
rescue ThreadError
# You pressed Ctrl-C, oh my!
@@ -151,3 +151,31 @@ end
task :copyright => COPYRIGHT_FILES
CLEAN.include(*COPYRIGHT_FILES)
JS_FILES = Dir.glob("assets/js/plugins/*.js") + ["assets/js/_main.js"]
JS_TARGET = "assets/js/main.min.js"
task :js => JS_TARGET
file JS_TARGET => JS_FILES do |t|
sh Shellwords.join(%w[npx uglifyjs -c -m -o] + [t.name] + t.prerequisites)
sh "node banner.js"
end
task :watch_js do
listener = Listen.to(
"assets/js",
ignore: /main\.min\.js$/,
) do |modified, added, removed|
Rake::Task[:js].invoke
end
trap("INT") do
listener.stop
exit 0
end
begin
listener.start
sleep
rescue ThreadError
end
end