parceler 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e700061babf3bf7e9cba67f790aeb10bac52207bf3f3287eabe6cbed05654125
4
+ data.tar.gz: ef8a0f5c4060d2b7058931afa7fa2d5bf85e886ce4b308baac0f422c07967112
5
+ SHA512:
6
+ metadata.gz: 596cca5043df26bf6850deaa0d8756a7008d3d8d080a2fd5011eb467698a665047545ab221e08f89a907824e6d8baaee33945cc42dd9e41f4fd2ad34622315a9
7
+ data.tar.gz: cad3edcdc595c5525a0b1b44fcf6734729403165405e7e97cc59838b47f74e32c890f73e013c1306540930991156f7e749c1cd264e8d041dd234502a9ac079cf
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ /node_modules
2
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in parceler.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2019, Elias Gabriel
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # Parceler
2
+ [![version](https://img.shields.io/gem/v/parceler.svg?label=version&style=flat-square)
3
+ ![downloads](https://img.shields.io/gem/dt/parceler.svg?style=flat-square)](https://rubygems.org/gems/parceler)
4
+ [![license](https://img.shields.io/github/license/thearchitectoR/parceler.svg?style=flat-square)](/LICENSE)
5
+
6
+ Parceler attempts to be an alternative asset compiler and manager for [Ruby on Rails](https://rubyonrails.org/). It provides functionality similar to Rails' own [Webpacker gem](https://github.com/rails/webpacker) but is powered by [Parcel](https://parceljs.org/) instead of [Webpack](https://webpack.js.org/). As a result and at the cost of some more advanced features, it requires significantly less out-of-the-box configuration. While meant for Rails, nothing inhibits using this gem outside of a Rails context.
7
+
8
+ ## Installation
9
+ You can install this gem by adding it to your application's `Gemfile` via:
10
+
11
+ ```ruby
12
+ gem 'parceler', group: :development
13
+ ```
14
+
15
+ This gem also requires a Node.js environment set up with Yarn. You can install Node.js at https://nodejs.org/en/download/ and Yarn at https://yarnpkg.com/en/docs/install.
16
+
17
+ To install the required Node packages, run the rake task `parceler:install`:
18
+
19
+ ```sh
20
+ $ bundle exec rake parceler:install
21
+ ```
22
+
23
+ ### Configuration
24
+ Before this gem can bundle your app's assets, it must be configured. To do so, you must run `Parceler.configure` with a provided configuration block _before_ starting your app's server. The default configuration block that is packaged with this gem looks something like this:
25
+
26
+ ```rb
27
+ # Configuration options defined here have direct relations to those defined in the official documentation.
28
+ # https://parceljs.org/cli.html
29
+ Parceler.configure do |c|
30
+ c.entry_point = "app/javascript/application.js"
31
+ c.destination = "public/parcels"
32
+ c.cache = nil
33
+ c.source_maps = false
34
+ c.autoresolve = false
35
+
36
+ # The following options only have an effect in production builds. You can parcel
37
+ # your assets for production with rake tasks `parceler:build` or `assets:precompile`.
38
+ c.minify = true
39
+ c.content_hashing = true
40
+ c.tree_shaking = false
41
+ end
42
+ ```
43
+
44
+ If you do not want to customize your app, you may simply copy this block and everythig should work fine. _However_, it is very likely that you will need to customize it to your particular needs.
45
+
46
+ #### Configuration on Rails
47
+ While the above steps are not explicitly required, it is _highly_ recommended that you create a config file so you can customize this gem to align with your own app. You can generate the default configuration initializer by running
48
+
49
+ ```sh
50
+ $ rails g parceler
51
+ ```
52
+
53
+ , which will place a new file at `config/initializers/parceler.rb`.
54
+
55
+ ## Origin Story
56
+ I built this gem while working on the MAIS™ business managment and information system developed by [sdbase](sdbase.com). At the time of development, we were looking at upgrading the entire stack from EOLed versions of Ruby and Rails. Throughout the process, I realized that the new asset management system (`webpacker`) was overly complicated for many of our applications. As a result, it provided a reasonably steep learning curve to many of the burgeoning developers with which we were working. To mitigate those problems and to simplify the engineering learning process, I built Parceler to require very little out-of-the-box configuration while maintaining very transparent functionality.
57
+
58
+ ## License
59
+ This gem is released and published under the [3-Clause BSD License](https://opensource.org/licenses/BSD-3-Clause) by Elias Gabriel (@thearchitector).
@@ -0,0 +1,7 @@
1
+ class ParcelerGenerator < Rails::Generators::Base
2
+ source_root File.expand_path("../templates", __FILE__)
3
+
4
+ def create_initializer_file
5
+ copy_file "config.rb", "config/initializers/parceler.rb"
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ # Configuration options defined here have direct relations to those defined in the official documentation.
2
+ # https://parceljs.org/cli.html
3
+ Parceler.configure do |c|
4
+ c.entry_point = "app/javascript/application.js"
5
+ c.destination = "public/parcels"
6
+ c.cache = nil
7
+ c.source_maps = false
8
+ c.autoresolve = false
9
+
10
+ # The following options only have an effect in production builds. You can parcel
11
+ # your assets for production with rake tasks `parceler:build` or `assets:precompile`.
12
+ c.minify = true
13
+ c.content_hashing = true
14
+ end
@@ -0,0 +1,20 @@
1
+ module Parceler
2
+ class Engine
3
+ def initialize(config)
4
+ @args = [config.entry_point, "--out-dir", config.destination]
5
+ @args.append("--cache-dir") if config.cache.present?
6
+ @args.append("--no-source-maps") if !config.source_maps
7
+ @args.append("--no-content-hash") if !config.content_hashing
8
+ @args.append("--no-autoinstall") if !config.autoresolve
9
+ @args.append("--no-minify") if !config.minify
10
+ end
11
+
12
+ def getcmd(cmd = '')
13
+ return "yarn run parcel #{cmd} #{@args.join(' ')}"
14
+ end
15
+
16
+ def execute(cmd = '')
17
+ exec(self.getcmd(cmd))
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,41 @@
1
+ require 'posix/spawn'
2
+
3
+ module Parceler
4
+ class Railtie < ::Rails::Railtie
5
+ railtie_name :parceler
6
+
7
+ rake_tasks do
8
+ load 'parceler/tasks.rake'
9
+ end
10
+
11
+ # Parcel's HMR server should only be used in development mode, so we restrict it
12
+ if Rails.env.development? && defined?(Rails::Server)
13
+ initializer "parceler.start_hmr" do |app|
14
+ app.config.after_initialize do
15
+ puts "\033[36m~~~ Launching a Parcel server for hot compliation ~~~\033[0m"
16
+
17
+ if Parceler.engine.nil?
18
+ Parceler.configure do |c|
19
+ puts "\033[31m -> No configuration found. Falling back to defaults...\033[0m"
20
+ end
21
+ end
22
+
23
+ pid = POSIX::Spawn::spawn(Parceler.engine.getcmd(:watch))
24
+
25
+ # Wait for the parent (Rails server) to die, and then kill the child process
26
+ #
27
+ # NOTE: We cannot use Signal.trap here because it does not automatically respect
28
+ # previously defined handlers, and thus Rails does not pass the event onto Parceler.
29
+ at_exit do
30
+ puts "\033[1m~~~ Gracefully stopping the Parcel watch server ~~~\033[0m"
31
+ Process.kill("SIGKILL", pid)
32
+ Process.waitpid(pid)
33
+ puts "=== parceler shutdown: #{Time.now.strftime("%Y-%m-%d %H:%M:%S %z")} ==="
34
+ puts "\033[36mAu revoir!\033[0m"
35
+ exit
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,24 @@
1
+ namespace :parceler do
2
+ desc 'Installs the Parcel dependency with Yarn'
3
+ task install: :environment do
4
+ exec("yarn add parcel-bundler --dev")
5
+ end
6
+
7
+ desc 'Launches a Parcel process for proactive compilation'
8
+ task watch: :environment do
9
+ Parceler.engine.execute(:watch)
10
+ end
11
+
12
+ desc 'Builds a production-ready asset package using Parcel'
13
+ task build: :environment do
14
+ Parceler.engine.execute(:build)
15
+ end
16
+ end
17
+
18
+ Rake::Task['assets:precompile'].enhance do
19
+ Rake::Task['parceler:compile'].invoke
20
+ end
21
+
22
+ Rake::Task['assets:clobber'].enhance do
23
+ Rake::Task['parceler:clobber'].invoke
24
+ end
data/lib/parceler.rb ADDED
@@ -0,0 +1,32 @@
1
+ require "parceler/engine"
2
+ require "parceler/railtie" if defined?(Rails)
3
+
4
+ module Parceler
5
+ class Error < StandardError; end
6
+ class << self
7
+ attr_accessor :configuration
8
+ attr_accessor :engine
9
+ end
10
+
11
+ def self.configure
12
+ self.configuration ||= Configuration.new
13
+ yield(configuration)
14
+ self.engine = Parceler::Engine.new(self.configuration)
15
+ end
16
+
17
+ # Configuration options defined here have direct relations to those defined in the official documentation
18
+ # https://parceljs.org/cli.html
19
+ class Configuration
20
+ attr_accessor :entry_point, :destination, :cache, :source_maps, :minify, :content_hashing, :autoresolve
21
+
22
+ def initialize
23
+ @entry_point = "app/javascript/application.js"
24
+ @destination = "public/parcels"
25
+ @cache = nil
26
+ @source_maps = false
27
+ @minify = true
28
+ @content_hashing = true
29
+ @autoresolve = false
30
+ end
31
+ end
32
+ end
data/package.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "private": true,
3
+ "name": "parceler",
4
+ "version": "1.0.3",
5
+ "description": "A Parcel-based asset manager",
6
+ "devDependencies": {
7
+ "parcel-bundler": "^1.12.3"
8
+ }
9
+ }
data/parceler.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "parceler"
6
+ spec.version = "1.0.3"
7
+ spec.platform = Gem::Platform::RUBY
8
+ spec.author = "Elias Gabriel"
9
+ spec.email = "me@eliasfgabriel.com"
10
+ spec.summary = "A Parcel-based asset manager"
11
+ spec.description = "An alternative Parcel-powered asset manager and compiler, meant for Rails but built for Ruby."
12
+ spec.homepage = "https://github.com/thearchitector/parceler"
13
+ spec.license = "BSD-3-Clause"
14
+
15
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
+ spec.metadata["homepage_uri"] = spec.metadata["source_code_uri"] = spec.homepage
17
+ spec.extra_rdoc_files = ["README.md"]
18
+
19
+ spec.requirements = ["Node.js", "Yarn"]
20
+
21
+ spec.require_paths = ["lib"]
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0")
24
+ end
25
+
26
+ spec.required_ruby_version = '>= 1.9'
27
+
28
+ spec.add_runtime_dependency "posix-spawn", '~> 0.3'
29
+ spec.add_development_dependency "bundler", '~> 2.0'
30
+ spec.add_development_dependency "rake", '~> 10.0'
31
+ end