From 816ea05288d7b1ed7faaee0569712a7c417753af Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Fri, 18 Nov 2022 22:24:57 -0300 Subject: [PATCH] filters/: add nanoc-webpack.rb Replace lib/filters/webpack.rb with [nanoc-webpack.rb](https://github.com/0x1eef/nanoc-webpack.rb) --- Gemfile | 1 + Gemfile.lock | 7 +++++++ Rules | 1 + lib/filters/webpack.rb | 39 --------------------------------------- 4 files changed, 9 insertions(+), 39 deletions(-) delete mode 100644 lib/filters/webpack.rb diff --git a/Gemfile b/Gemfile index d896f75..00c2fb4 100644 --- a/Gemfile +++ b/Gemfile @@ -4,6 +4,7 @@ source "https://rubygems.org" gem "nanoc", "~> 4.12" gem "nanoc-live", "~> 1.0" gem "nanoc-gunzip.rb", "~> 0.1" +gem "nanoc-webpack.rb", "~> 0.1", git: "https://github.com/0x1eef/nanoc-webpack.rb" gem "rainpress", "~> 1.0" gem "sass" gem "standardrb" diff --git a/Gemfile.lock b/Gemfile.lock index 2f1ca1f..2b52245 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,9 @@ +GIT + remote: https://github.com/0x1eef/nanoc-webpack.rb + revision: 8d821be4f7d45abaaf79aa9d7656590d158f6d3f + specs: + nanoc-webpack.rb (0.1.0) + GEM remote: https://rubygems.org/ specs: @@ -141,6 +147,7 @@ DEPENDENCIES nanoc (~> 4.12) nanoc-gunzip.rb (~> 0.1) nanoc-live (~> 1.0) + nanoc-webpack.rb (~> 0.1)! paint puma rainpress (~> 1.0) diff --git a/Rules b/Rules index 4745116..c9fe6b1 100644 --- a/Rules +++ b/Rules @@ -2,6 +2,7 @@ # frozen_string_literal: true require "ryo" require "nanoc-gunzip" +require "nanoc-webpack" LOCALES = %w[ar en] SURAH_ID_TO_SLUG = Ryo.from( diff --git a/lib/filters/webpack.rb b/lib/filters/webpack.rb deleted file mode 100644 index 254245b..0000000 --- a/lib/filters/webpack.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -## -# Compiles a JavaScript / TypeScript asset with webpack. -class Nanoc::Filter::Webpack < Nanoc::Filter - include FileUtils - - identifier :webpack - type :text - always_outdated - - def run(content, options = {}) - webpack(temp_file(content)) - end - - private - - def webpack(file) - system "node", - "./node_modules/webpack/bin/webpack.js", - "--entry", File.join("./src", item.identifier.to_s), - "--output-path", File.dirname(file.path), - "--output-filename", File.basename(file.path) - if $?.success? - File.read(file.path).tap { file.tap(&:unlink).close } - else - file.tap(&:unlink).close - exit!($?.exitstatus) - end - end - - def temp_file(content) - dir = File.join(Dir.getwd, "tmp", "webpack") - mkdir_p(dir) unless Dir.exist?(dir) - file = Tempfile.new(File.basename(item.identifier.to_s), dir) - file.write(content) - file.tap(&:flush) - end -end