engine_pack 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf2940d263522b251ee9a753d772e23d2b193284a5c5451344e79aad4a907792
4
- data.tar.gz: 4292d238be20c2360efed5dd619880ac5fa802744f6f90814bce0339bc3b23e0
3
+ metadata.gz: b4188c100677625caaf64e48b753063ac5658b9cde4847a7385114a6d7ead765
4
+ data.tar.gz: d9a820070be235e792cd184826c12aa3e1c60881910a886314e37a40d519fdd5
5
5
  SHA512:
6
- metadata.gz: f7dbae3997363a42cdcd23fccbce88c62abf4c9e8279d235b7a45a2a32a760f6da8fa9e45c8f74fd1313eed85ebf6bb7dfcd37c4e7b05b6ee57cff9917197468
7
- data.tar.gz: 4bc8afa3785039d8bed6aed49ad143354dec7e3ab9f1199555cfe35f7277b09ccd0d7d32c91f625a28b98198509dc09c139abf8e6640a487898f41a027b7ace6
6
+ metadata.gz: 88ca00a0347b67233940da099871b8df3735779165c9221b74a8e1d0c77fbb9d0522fe084059d5151e53c3089b074cc6e453e6ff54f8cfb1c2cf74f3c6ec5973
7
+ data.tar.gz: 94179b0bdc6e69dbbcc93443b65355061c5b2283ee6a27200fe8e9467a1961c6a5973e1e5ce3ae5946f055c16b63c54c1f8e763365242c456036e4b789958f67
data/.gitignore CHANGED
@@ -5,6 +5,7 @@
5
5
  /doc/
6
6
  /*.gem
7
7
  /pkg/
8
+ /spec/dummy/node_modules/
8
9
  /spec/reports/
9
10
  /tmp/
10
11
 
data/Gemfile CHANGED
@@ -1,3 +1,8 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
+
5
+ gem "rails"
6
+ gem "webpacker"
7
+
8
+ gem "dummy_engine", path: "spec/dummy_engine"
data/Gemfile.lock CHANGED
@@ -1,13 +1,37 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- engine_pack (0.0.1)
4
+ engine_pack (0.1.0)
5
5
  dry-configurable (~> 0.12, >= 0.12.0)
6
6
  railties (>= 6.0.0)
7
7
 
8
+ PATH
9
+ remote: spec/dummy_engine
10
+ specs:
11
+ dummy_engine (0.1.0)
12
+
8
13
  GEM
9
14
  remote: https://rubygems.org/
10
15
  specs:
16
+ actioncable (6.1.3)
17
+ actionpack (= 6.1.3)
18
+ activesupport (= 6.1.3)
19
+ nio4r (~> 2.0)
20
+ websocket-driver (>= 0.6.1)
21
+ actionmailbox (6.1.3)
22
+ actionpack (= 6.1.3)
23
+ activejob (= 6.1.3)
24
+ activerecord (= 6.1.3)
25
+ activestorage (= 6.1.3)
26
+ activesupport (= 6.1.3)
27
+ mail (>= 2.7.1)
28
+ actionmailer (6.1.3)
29
+ actionpack (= 6.1.3)
30
+ actionview (= 6.1.3)
31
+ activejob (= 6.1.3)
32
+ activesupport (= 6.1.3)
33
+ mail (~> 2.5, >= 2.5.4)
34
+ rails-dom-testing (~> 2.0)
11
35
  actionpack (6.1.3)
12
36
  actionview (= 6.1.3)
13
37
  activesupport (= 6.1.3)
@@ -15,12 +39,33 @@ GEM
15
39
  rack-test (>= 0.6.3)
16
40
  rails-dom-testing (~> 2.0)
17
41
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
42
+ actiontext (6.1.3)
43
+ actionpack (= 6.1.3)
44
+ activerecord (= 6.1.3)
45
+ activestorage (= 6.1.3)
46
+ activesupport (= 6.1.3)
47
+ nokogiri (>= 1.8.5)
18
48
  actionview (6.1.3)
19
49
  activesupport (= 6.1.3)
20
50
  builder (~> 3.1)
21
51
  erubi (~> 1.4)
22
52
  rails-dom-testing (~> 2.0)
23
53
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
54
+ activejob (6.1.3)
55
+ activesupport (= 6.1.3)
56
+ globalid (>= 0.3.6)
57
+ activemodel (6.1.3)
58
+ activesupport (= 6.1.3)
59
+ activerecord (6.1.3)
60
+ activemodel (= 6.1.3)
61
+ activesupport (= 6.1.3)
62
+ activestorage (6.1.3)
63
+ actionpack (= 6.1.3)
64
+ activejob (= 6.1.3)
65
+ activerecord (= 6.1.3)
66
+ activesupport (= 6.1.3)
67
+ marcel (~> 0.3.1)
68
+ mimemagic (~> 0.3.2)
24
69
  activesupport (6.1.3)
25
70
  concurrent-ruby (~> 1.0, >= 1.0.2)
26
71
  i18n (>= 1.6, < 2)
@@ -39,14 +84,25 @@ GEM
39
84
  dry-core (0.5.0)
40
85
  concurrent-ruby (~> 1.0)
41
86
  erubi (1.10.0)
87
+ globalid (0.4.2)
88
+ activesupport (>= 4.2.0)
42
89
  i18n (1.8.9)
43
90
  concurrent-ruby (~> 1.0)
44
91
  loofah (2.9.0)
45
92
  crass (~> 1.0.2)
46
93
  nokogiri (>= 1.5.9)
94
+ mail (2.7.1)
95
+ mini_mime (>= 0.1.1)
96
+ marcel (0.3.3)
97
+ mimemagic (~> 0.3.2)
47
98
  method_source (1.0.0)
99
+ mimemagic (0.3.10)
100
+ nokogiri (~> 1)
101
+ rake
102
+ mini_mime (1.1.0)
48
103
  mini_portile2 (2.5.0)
49
104
  minitest (5.14.4)
105
+ nio4r (2.5.7)
50
106
  nokogiri (1.11.2)
51
107
  mini_portile2 (~> 2.5.0)
52
108
  racc (~> 1.4)
@@ -58,8 +114,25 @@ GEM
58
114
  method_source (~> 1.0)
59
115
  racc (1.5.2)
60
116
  rack (2.2.3)
117
+ rack-proxy (0.6.5)
118
+ rack
61
119
  rack-test (1.1.0)
62
120
  rack (>= 1.0, < 3)
121
+ rails (6.1.3)
122
+ actioncable (= 6.1.3)
123
+ actionmailbox (= 6.1.3)
124
+ actionmailer (= 6.1.3)
125
+ actionpack (= 6.1.3)
126
+ actiontext (= 6.1.3)
127
+ actionview (= 6.1.3)
128
+ activejob (= 6.1.3)
129
+ activemodel (= 6.1.3)
130
+ activerecord (= 6.1.3)
131
+ activestorage (= 6.1.3)
132
+ activesupport (= 6.1.3)
133
+ bundler (>= 1.15.0)
134
+ railties (= 6.1.3)
135
+ sprockets-rails (>= 2.0.0)
63
136
  rails-dom-testing (2.0.3)
64
137
  activesupport (>= 4.2.0)
65
138
  nokogiri (>= 1.6)
@@ -100,21 +173,40 @@ GEM
100
173
  rubocop-ast (1.4.1)
101
174
  parser (>= 2.7.1.5)
102
175
  ruby-progressbar (1.11.0)
176
+ semantic_range (3.0.0)
177
+ sprockets (4.0.2)
178
+ concurrent-ruby (~> 1.0)
179
+ rack (> 1, < 3)
180
+ sprockets-rails (3.2.2)
181
+ actionpack (>= 4.0)
182
+ activesupport (>= 4.0)
183
+ sprockets (>= 3.0.0)
103
184
  thor (1.1.0)
104
185
  tzinfo (2.0.4)
105
186
  concurrent-ruby (~> 1.0)
106
187
  unicode-display_width (2.0.0)
188
+ webpacker (5.3.0)
189
+ activesupport (>= 5.2)
190
+ rack-proxy (>= 0.6.1)
191
+ railties (>= 5.2)
192
+ semantic_range (>= 2.3.0)
193
+ websocket-driver (0.7.3)
194
+ websocket-extensions (>= 0.1.0)
195
+ websocket-extensions (0.1.5)
107
196
  zeitwerk (2.4.2)
108
197
 
109
198
  PLATFORMS
110
199
  ruby
111
200
 
112
201
  DEPENDENCIES
202
+ dummy_engine!
113
203
  engine_pack!
114
204
  pry
205
+ rails
115
206
  rake
116
207
  rspec
117
208
  rubocop
209
+ webpacker
118
210
 
119
211
  BUNDLED WITH
120
212
  1.17.3
data/lib/engine_pack.rb CHANGED
@@ -7,7 +7,11 @@ module EnginePack
7
7
  extend Dry::Configurable
8
8
 
9
9
  setting :package_manager, :npm
10
- setting :engines
10
+ setting :engines, []
11
+
12
+ def self.gem_specs
13
+ @gem_specs ||= Bundler.load.specs
14
+ end
11
15
  end
12
16
 
13
17
  require 'engine_pack/railtie' if defined?(Rails)
@@ -0,0 +1,27 @@
1
+ require 'fileutils'
2
+
3
+ module EnginePack
4
+ module Adaptors
5
+ class IO
6
+ def copy_files(files:, to:)
7
+ FileUtils.cp_r(
8
+ files,
9
+ to,
10
+ preserve: true
11
+ )
12
+ end
13
+
14
+ def exists?(path:)
15
+ File.exist?(path)
16
+ end
17
+
18
+ def mkdir(path:)
19
+ FileUtils.mkdir_p(path)
20
+ end
21
+
22
+ def tmpdir
23
+ Dir.tmpdir
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ module EnginePack
2
+ class CommandRunner
3
+ def initialize(io: Open3)
4
+ @io = io
5
+ end
6
+
7
+ def run(cmd, environment_variables = {})
8
+ io.popen3(
9
+ environment_variables,
10
+ "#{cmd} 2>&1"
11
+ ) do |stdin, stdout, _stderr, wait_thread|
12
+ stdin.close_write
13
+
14
+ while line = stdout.gets
15
+ puts line
16
+ end
17
+
18
+ puts wait_thread.value
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :io
25
+ end
26
+ end
@@ -0,0 +1,42 @@
1
+ require_relative 'adaptors/io'
2
+ require_relative 'package_config'
3
+
4
+ module EnginePack
5
+ class EnginePackage
6
+ def initialize(
7
+ engine,
8
+ io: Adaptors::IO.new,
9
+ package_config: PackageConfig.new(EnginePack.gem_specs.find { |s| s.name == engine }&.full_gem_path)
10
+ )
11
+ @engine = engine
12
+ @io = io
13
+ @package_config = package_config
14
+ end
15
+
16
+ def with_path
17
+ io.mkdir(path: tmp_path)
18
+ copy_specified_files(tmp_path)
19
+
20
+ yield tmp_path
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :engine, :gem_specs, :io, :package_config
26
+
27
+ def copy_specified_files(dir)
28
+ io.copy_files(
29
+ files: package_config.package_files_paths,
30
+ to: dir
31
+ )
32
+ end
33
+
34
+ def package_json?
35
+ io.exist?(path: "#{engine_path}/package.json")
36
+ end
37
+
38
+ def tmp_path
39
+ "#{io.tmpdir}/enginepack/#{engine}"
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,33 @@
1
+ require 'json'
2
+
3
+ module EnginePack
4
+ class PackageConfig
5
+ attr_reader :path
6
+
7
+ def initialize(package_path)
8
+ @path = package_path
9
+
10
+ raise ArgumentError, "#{package_path} does not have a package.json file." unless File.exist?(config_path)
11
+
12
+ @config = JSON.parse(File.read(config_path))
13
+ end
14
+
15
+ def package_files_paths
16
+ specified_files.map { |f| "#{path}/#{f}" }.tap do |paths|
17
+ paths << config_path unless paths.include?(config_path)
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :config
24
+
25
+ def config_path
26
+ "#{path}/package.json"
27
+ end
28
+
29
+ def specified_files
30
+ config.fetch('files', [])
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ require_relative 'package_managers/npm'
2
+ require_relative 'package_managers/yarn'
3
+
4
+ module EnginePack
5
+ class PackageManagerFactory
6
+ class << self
7
+ def build(name)
8
+ case name
9
+ when :npm then PackageManagers::Npm.new
10
+ when :yarn then PackageManagers::Yarn.new
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module EnginePack
2
+ module PackageManagers
3
+ class Npm
4
+ INSTALL_COMMAND = 'npm install %<engine_path>s'.freeze
5
+
6
+ def install_command(engine_path)
7
+ format(INSTALL_COMMAND, engine_path: engine_path)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module EnginePack
2
+ module PackageManagers
3
+ class Yarn
4
+ INSTALL_COMMAND = 'yarn add file:%<engine_path>s'.freeze
5
+
6
+ def install_command(engine_path)
7
+ format(INSTALL_COMMAND, engine_path: engine_path)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -2,62 +2,47 @@
2
2
 
3
3
  require 'open3'
4
4
 
5
+ require_relative 'command_runner'
6
+ require_relative 'engine_package'
7
+ require_relative 'package_manager_factory'
8
+
5
9
  module EnginePack
6
10
  class Preinstall
7
11
  ENV_VARIABLE_NAME = 'EP_PREINSTALL'
8
- PACKAGE_MANAGER_COMMANDS = {
9
- npm: 'npm install %<engine_path>s',
10
- yarn: 'yarn add file:%<engine_path>s'
11
- }.freeze
12
12
 
13
13
  class << self
14
- def call
15
- new.call
14
+ def call(engines:)
15
+ new.call(engines: engines)
16
16
  end
17
17
  end
18
18
 
19
- def initialize(command_runner: Open3, gem_spec_set: Bundler.load.specs)
19
+ def initialize(
20
+ command_runner: CommandRunner.new,
21
+ package_manager: PackageManagerFactory.build(EnginePack.config.package_manager)
22
+ )
20
23
  @command_runner = command_runner
21
- @gem_spec_set = gem_spec_set
24
+ @package_manager = package_manager
22
25
  end
23
26
 
24
- def call
27
+ def call(engines:)
25
28
  return if ENV.fetch(ENV_VARIABLE_NAME, nil)
26
29
 
27
- EnginePack.config.engines.each(&method(:install_engine))
30
+ engines.each(&method(:install_engine))
28
31
  end
29
32
 
30
33
  private
31
34
 
32
- attr_reader :command_runner, :gem_spec_set
35
+ attr_reader :command_runner, :package_manager
33
36
 
34
37
  def install_engine(engine)
35
- command = package_manager_command(engine)
36
-
37
- return unless command
38
-
39
- command_runner.popen3(
40
- { ENV_VARIABLE_NAME => '1' },
41
- command
42
- ) do |stdin, stdout, stderr, _thread|
43
- stdin.close_write
44
-
45
- while line = stdout.gets
46
- puts line
47
- end
38
+ engine_package = EnginePackage.new(engine)
48
39
 
49
- while line = stderr.gets
50
- puts line
51
- end
40
+ engine_package.with_path do |path|
41
+ command_runner.run(
42
+ package_manager.install_command(path),
43
+ { ENV_VARIABLE_NAME => '1' }
44
+ )
52
45
  end
53
46
  end
54
-
55
- def package_manager_command(engine)
56
- engine_path = gem_spec_set.find { |s| s.name == engine }&.full_gem_path
57
-
58
- return unless engine_path
59
-
60
- format(PACKAGE_MANAGER_COMMANDS[EnginePack.config.package_manager], engine_path: engine_path)
61
- end
62
47
  end
63
48
  end
@@ -7,6 +7,6 @@ namespace :engine_pack do
7
7
  task preinstall: :environment do
8
8
  exit 0 if ENV.fetch(EnginePack::Preinstall::ENV_VARIABLE_NAME, nil) == '1'
9
9
 
10
- EnginePack::Preinstall.call
10
+ EnginePack::Preinstall.call(engines: EnginePack.config.engines)
11
11
  end
12
12
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EnginePack
4
- VERSION = '0.0.1'
4
+ VERSION = '0.1.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: engine_pack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaric Pittman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-11 00:00:00.000000000 Z
11
+ date: 2021-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable
@@ -124,6 +124,13 @@ files:
124
124
  - docker-compose.yml
125
125
  - engine_pack.gemspec
126
126
  - lib/engine_pack.rb
127
+ - lib/engine_pack/adaptors/io.rb
128
+ - lib/engine_pack/command_runner.rb
129
+ - lib/engine_pack/engine_package.rb
130
+ - lib/engine_pack/package_config.rb
131
+ - lib/engine_pack/package_manager_factory.rb
132
+ - lib/engine_pack/package_managers/npm.rb
133
+ - lib/engine_pack/package_managers/yarn.rb
127
134
  - lib/engine_pack/preinstall.rb
128
135
  - lib/engine_pack/railtie.rb
129
136
  - lib/engine_pack/tasks/preinstall.rake