esbuilder 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +13 -0
- data/lib/esbuilder.rb +58 -0
- data/lib/esbuilder/engine.rb +30 -0
- data/lib/esbuilder/helper.rb +25 -0
- data/lib/esbuilder/version.rb +3 -0
- data/lib/tasks/esbuilder/compile.rake +17 -0
- data/lib/tasks/esbuilder_tasks.rake +4 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9ff0a163e3f4d135ac867449b2b725f33b33752e6b111ff864a0d9967cd038bc
|
4
|
+
data.tar.gz: 24959c6c840146ae7f2915ad11a17d6f005d2486e40b22736f1b993da9f8a599
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d28bf440b6a96f2db46e9b4d19bda030bb21def56364a966eaf838237be1e128a44fe9bb981ffacd194b5c29d2564ab1bbc95649ae0cb58f081972b0a492df63
|
7
|
+
data.tar.gz: 30b5a5367b9a3f8367d5ccbc1df5eb7c2edb9a47170d5a8f348867d54d3d96d0d08aaa7919e9eb236a08f7f33138de8be20868170ea0e94c0e2cf68dfa713d03
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2021 Bouke van der Bijl
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Esbuilder
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'esbuilder'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install esbuilder
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/lib/esbuilder.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require "esbuilder/version"
|
2
|
+
|
3
|
+
module Esbuilder
|
4
|
+
class UnknownEntryPointError < StandardError; end
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def entry_point_to_outputs(entry_point)
|
8
|
+
return outputs_from_manifest(entry_point) if Engine.config.use_manifest
|
9
|
+
|
10
|
+
build_entry_point(entry_point)
|
11
|
+
end
|
12
|
+
|
13
|
+
def build_entry_point(entry_point)
|
14
|
+
outdir = Engine.config.output_path
|
15
|
+
options = build_options_for(entry_point)
|
16
|
+
result = Esbuild.build(**options)
|
17
|
+
result.metafile.outputs.each_key.map { |key| "/#{Rails.root.join(key).relative_path_from(outdir)}" }
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def outputs_from_manifest(entry_point)
|
23
|
+
unless (outputs = manifest[entry_point])
|
24
|
+
raise UnknownEntryPointError, "Unknown entry point #{entry_point}"
|
25
|
+
end
|
26
|
+
outputs
|
27
|
+
end
|
28
|
+
|
29
|
+
def manifest
|
30
|
+
@manifest ||= JSON.parse(File.read(Engine.config.manifest_path))
|
31
|
+
end
|
32
|
+
|
33
|
+
def build_options_for(entry_point)
|
34
|
+
global_options = Engine.config.build_config&.fetch(:global, nil)
|
35
|
+
specific_options = Engine.config.build_config&.fetch(:entry_points, nil)&.fetch(entry_point.to_sym, nil)
|
36
|
+
|
37
|
+
assets = Engine.config.base_path
|
38
|
+
outdir = Engine.config.output_path
|
39
|
+
entry_point_file = assets.join(entry_point).to_s
|
40
|
+
options = {
|
41
|
+
outbase: assets.to_s,
|
42
|
+
entry_points: [entry_point_file],
|
43
|
+
entry_names: "[dir]/[name]-[hash]",
|
44
|
+
write: true,
|
45
|
+
bundle: true,
|
46
|
+
outdir: outdir,
|
47
|
+
public_path: "/",
|
48
|
+
metafile: true,
|
49
|
+
abs_working_dir: Rails.root.to_s,
|
50
|
+
}
|
51
|
+
options.deep_merge! global_options.deep_symbolize_keys if global_options.present?
|
52
|
+
options.deep_merge! specific_options.deep_symbolize_keys if specific_options.present?
|
53
|
+
options
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
require "esbuilder/engine"
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "rails/railtie"
|
2
|
+
|
3
|
+
require "esbuilder/helper"
|
4
|
+
|
5
|
+
module Esbuilder
|
6
|
+
class Engine < ::Rails::Engine
|
7
|
+
config.after_initialize do |app|
|
8
|
+
config.base_path = Rails.root.join("app/javascript/packs")
|
9
|
+
config.entry_points = ["application"]
|
10
|
+
config.manifest_path = Rails.root.join("app/javascript/esbuilder-manifest.json")
|
11
|
+
config.use_manifest = Rails.env.production?
|
12
|
+
config.output_path = app.paths["public"].existent.first
|
13
|
+
end
|
14
|
+
|
15
|
+
initializer "esbuilder.config" do |app|
|
16
|
+
config_name = Pathname.new("#{app.paths["config"].existent.first}/esbuilder.yml")
|
17
|
+
config.build_config = config_name.exist? ? app.config_for(config_name) : ActiveSupport::OrderedOptions.new
|
18
|
+
end
|
19
|
+
|
20
|
+
initializer "esbuilder.helper" do
|
21
|
+
ActiveSupport.on_load :action_controller do
|
22
|
+
ActionController::Base.helper Esbuilder::Helper
|
23
|
+
end
|
24
|
+
|
25
|
+
ActiveSupport.on_load :action_view do
|
26
|
+
include Esbuilder::Helper
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "esbuild"
|
2
|
+
|
3
|
+
module Esbuilder
|
4
|
+
module Helper
|
5
|
+
def entry_point_tag(*entry_points, **options)
|
6
|
+
files = build(*entry_points)
|
7
|
+
files.map do |file|
|
8
|
+
if file.end_with?(".js")
|
9
|
+
javascript_include_tag file, **options
|
10
|
+
elsif file.end_with?(".css")
|
11
|
+
stylesheet_link_tag file, **options
|
12
|
+
else
|
13
|
+
# Ignore non-js/css files
|
14
|
+
""
|
15
|
+
end
|
16
|
+
end.join("\n").html_safe
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def build(*entry_points)
|
22
|
+
entry_points.reduce(Set.new) { |result, entry_point| result.merge Esbuilder.entry_point_to_outputs(entry_point) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "set"
|
2
|
+
|
3
|
+
namespace :esbuilder do
|
4
|
+
desc "Compile esbuilder entrypoints"
|
5
|
+
task compile: :environment do
|
6
|
+
entry_points = Esbuilder::Engine.config.entry_points
|
7
|
+
entry_point_map = {}
|
8
|
+
entry_points.each do |entry_point|
|
9
|
+
outputs = Esbuilder.build_entry_point(entry_point)
|
10
|
+
entry_point_map[entry_point] = outputs
|
11
|
+
end
|
12
|
+
|
13
|
+
File.open(Esbuilder::Engine.config.manifest_path, "w") do |f|
|
14
|
+
JSON.dump(entry_point_map, f)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: esbuilder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bouke van der Bijl
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-06-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: esbuild
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.2.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 6.1.3
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 6.1.3.1
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 6.1.3
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 6.1.3.1
|
47
|
+
description: Description of Esbuilder.
|
48
|
+
email:
|
49
|
+
- i@bou.ke
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- MIT-LICENSE
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- lib/esbuilder.rb
|
58
|
+
- lib/esbuilder/engine.rb
|
59
|
+
- lib/esbuilder/helper.rb
|
60
|
+
- lib/esbuilder/version.rb
|
61
|
+
- lib/tasks/esbuilder/compile.rake
|
62
|
+
- lib/tasks/esbuilder_tasks.rake
|
63
|
+
homepage: https://github.com/bouk/esbuilder
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata:
|
67
|
+
homepage_uri: https://github.com/bouk/esbuilder
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubygems_version: 3.2.3
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Summary of Esbuilder.
|
87
|
+
test_files: []
|