elm-compiler 0.2.0 → 0.4.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
- SHA1:
3
- metadata.gz: a22cb64058f5d0317d5eca7e70d53e0eb05819a8
4
- data.tar.gz: 66bf2ee4d3349832e6ec155fdbf2fdcf227617b5
2
+ SHA256:
3
+ metadata.gz: 850e6bbb8b9adc11e42322b89e1b61beb4c92dba7e5b9172569ef506637ce05d
4
+ data.tar.gz: e7979cac94a9b0fa3a0307d69eb1b3071f73ae1ca8859aa2e2fc1bb3071d513d
5
5
  SHA512:
6
- metadata.gz: 6cc9ae96a797f4249b066e5bd6976b823ac7129efd18fc884791b5948541d0e60c09cc6715d56cdf1675f656dcb2d2b0adc62f474ffe73a6c3b07bb14431439c
7
- data.tar.gz: 07fbb644d45b8571da8202db901ff309d2abc514edafea7c25ba67e3aebc45dfbbae1282539aa31ee9ce9aeaf6f0b66897cc3341e23e7160ae310cfe6c4d71ee
6
+ metadata.gz: cfb7aee36120a88c85ed5133b32a6ed4d57790ffd57d52313fbf07e3c7be3c33ae18c6b17e82aad30269479291332d3f2fd5e62cd9367686d4b914f3f7b8ab5c
7
+ data.tar.gz: 870870911f6e04eb1f4b31afd958627693e77c8d43ed845f6862b0feea8032a492d45a3404034e680db68bb447bba7ee512ca82671df2f4efce14525350ab3e2
@@ -0,0 +1,18 @@
1
+ name: CI
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ ruby: [ 2.7, '3.0', '3.1' ]
9
+
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: ${{ matrix.ruby }}
16
+ bundler-cache: true
17
+ - run: bundle exec rake
18
+
data/.gitignore CHANGED
@@ -10,3 +10,6 @@
10
10
  /elm-stuff/
11
11
  /elm.js
12
12
  *.gem
13
+ /.ruby-version
14
+ /.ruby-gemset
15
+ /.byebug_history
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in elm-compiler.gemspec
4
4
  gemspec
5
+
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # elm-compiler
2
2
 
3
- [![Build Status](https://travis-ci.org/fbonetti/ruby-elm-compiler.svg?branch=master)](https://travis-ci.org/fbonetti/ruby-elm-compiler)
3
+ [![Build Status](https://github.com/fbonetti/ruby-elm-compiler/actions/workflows/ci.yml/badge.svg)](https://github.com/fbonetti/ruby-elm-compiler/actions/workflows/ci.yml)
4
4
 
5
5
  Ruby wrapper for the [Elm language compiler](https://github.com/elm-lang/elm-compiler).
6
6
 
@@ -28,16 +28,16 @@ Or install it yourself as:
28
28
 
29
29
  ## Usage
30
30
 
31
- > NOTE: Make sure [Elm](http://elm-lang.org/install) is installed. If the `elm-make` executable can't be found in the current `PATH` or via the `elm_make_path` option, the exception `Elm::Compiler::ExecutableNotFound` will be thrown.
31
+ > NOTE: Make sure [Elm](http://elm-lang.org/install) is installed. If the `elm` executable can't be found in the current `PATH` or via the `elm_path` option, the exception `Elm::Compiler::ExecutableNotFound` will be thrown.
32
32
 
33
33
  ```ruby
34
- Elm::Compiler.compile(elm_files, output_path: nil, elm_make_path: nil)
34
+ Elm::Compiler.compile(elm_files, output_path: nil, elm_path: nil, debug: false)
35
35
  ```
36
36
 
37
37
  * `elm_files`: Accepts a single file path or an array of file paths.
38
38
  * `output_path`: Path to the output file. If left blank, the compiled Javascript will be returned as a string.
39
- * `elm_make_path`: Path to the `elm-make` executable. If left blank, the executable will be looked up in the current `PATH`.
40
-
39
+ * `elm_path`: Path to the `elm` executable. If left blank, the executable will be looked up in the current `PATH`, if that cannot be found, it will download elm to /tmp/elm-0.19.1 and use that.
40
+ * `debug`: Whether or not to compile in debug mode. Default is false.
41
41
 
42
42
 
43
43
  ## Examples
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ require 'bundler/setup'
1
2
  require 'bundler/gem_tasks'
2
3
  require 'rspec/core/rake_task'
3
4
 
data/elm-compiler.gemspec CHANGED
@@ -18,8 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency 'bundler', '~> 1.11'
22
- spec.add_development_dependency 'rake', '~> 10.0'
23
21
  spec.add_development_dependency 'rspec', '~> 3.0'
24
- spec.add_development_dependency 'rubocop', '~> 0.35.1'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'byebug'
25
24
  end
data/elm.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "type": "application",
3
+ "source-directories": [
4
+ "spec/fixtures"
5
+ ],
6
+ "elm-version": "0.19.1",
7
+ "dependencies": {
8
+ "direct": {
9
+ "elm/browser": "1.0.2",
10
+ "elm/core": "1.0.5",
11
+ "elm/html": "1.0.0"
12
+ },
13
+ "indirect": {
14
+ "elm/json": "1.1.3",
15
+ "elm/time": "1.0.0",
16
+ "elm/url": "1.0.0",
17
+ "elm/virtual-dom": "1.0.3"
18
+ }
19
+ },
20
+ "test-dependencies": {
21
+ "direct": {},
22
+ "indirect": {}
23
+ }
24
+ }
@@ -1,5 +1,5 @@
1
1
  module Elm
2
2
  class Compiler
3
- VERSION = '0.2.0'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
data/lib/elm/compiler.rb CHANGED
@@ -1,40 +1,68 @@
1
1
  require 'elm/compiler/exceptions'
2
2
  require 'open3'
3
3
  require 'tempfile'
4
- require 'mkmf'
5
4
 
6
5
  module Elm
7
6
  class Compiler
8
7
  class << self
9
- def compile(elm_files, output_path: nil, elm_make_path: nil)
10
- elm_executable = elm_make_path || find_executable0("elm-make")
11
- fail ExecutableNotFound unless elm_executable_exists?(elm_executable)
8
+ attr_writer :elm_path
9
+ def elm_path
10
+ @elm_path ||= elm_from_env_path || our_elm_path
11
+ end
12
12
 
13
+ def compile(elm_files, output_path: nil, elm_path: self.elm_path, debug: false)
14
+ fail ExecutableNotFound unless elm_executable_exists?(elm_path)
13
15
  if output_path
14
- elm_make(elm_executable, elm_files, output_path)
16
+ elm_make(elm_path, elm_files, output_path, debug)
15
17
  else
16
- compile_to_string(elm_executable, elm_files)
18
+ compile_to_string(elm_path, elm_files, debug)
17
19
  end
18
20
  end
19
21
 
20
22
  private
21
23
 
22
- def elm_executable_exists?(elm_executable)
23
- File.executable?(elm_executable)
24
- end
25
-
26
- def compile_to_string(elm_executable, elm_files)
24
+ def compile_to_string(elm_path, elm_files, debug)
27
25
  Tempfile.open(['elm', '.js']) do |tempfile|
28
- elm_make(elm_executable, elm_files, tempfile.path)
26
+ elm_make(elm_path, elm_files, tempfile.path, debug)
29
27
  return File.read tempfile.path
30
28
  end
31
29
  end
32
30
 
33
- def elm_make(elm_executable, elm_files, output_path)
34
- Open3.popen3({"LANG" => "en_US.UTF8" }, elm_executable, *elm_files, '--yes', '--output', output_path) do |_stdin, _stdout, stderr, wait_thr|
31
+ def elm_make(elm_path, elm_files, output_path, debug)
32
+ args = [
33
+ {"LANG" => "en_US.UTF8" },
34
+ elm_path,
35
+ "make",
36
+ *elm_files,
37
+ "--output=#{output_path}",
38
+ debug ? "--debug" : "--optimize",
39
+ ]
40
+ Open3.popen3(*args) do |_stdin, _stdout, stderr, wait_thr|
35
41
  fail CompileError, stderr.gets(nil) if wait_thr.value.exitstatus != 0
36
42
  end
37
43
  end
44
+
45
+ def elm_executable_exists?(path)
46
+ `#{path} --version`.strip == "0.19.1"
47
+ rescue
48
+ false
49
+ end
50
+
51
+ def elm_from_env_path
52
+ `which elm`.chomp.tap { |p| return nil if p == "" }
53
+ end
54
+
55
+ def our_elm_path
56
+ path = "/tmp/elm-0.19.1"
57
+ unless elm_executable_exists?(path)
58
+ system """
59
+ curl -sfLo #{path}.gz https://github.com/elm/compiler/releases/download/0.19.1/binary-for-linux-64-bit.gz
60
+ gunzip -f #{path}.gz
61
+ chmod +x #{path}
62
+ """
63
+ end
64
+ path
65
+ end
38
66
  end
39
67
  end
40
68
  end
metadata CHANGED
@@ -1,71 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elm-compiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Bonetti
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-20 00:00:00.000000000 Z
11
+ date: 2022-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.11'
19
+ version: '3.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.11'
26
+ version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: byebug
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '3.0'
55
- - !ruby/object:Gem::Dependency
56
- name: rubocop
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: 0.35.1
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
52
+ - - ">="
67
53
  - !ruby/object:Gem::Version
68
- version: 0.35.1
54
+ version: '0'
69
55
  description: Allows you compile Elm files and write to a file or stdout
70
56
  email:
71
57
  - frank.r.bonetti@gmail.com
@@ -73,20 +59,18 @@ executables: []
73
59
  extensions: []
74
60
  extra_rdoc_files: []
75
61
  files:
62
+ - ".github/workflows/ci.yml"
76
63
  - ".gitignore"
77
64
  - ".rspec"
78
- - ".rubocop.yml"
79
- - ".travis.yml"
80
65
  - Gemfile
81
66
  - LICENSE.txt
82
67
  - README.md
83
68
  - Rakefile
84
69
  - bin/console
85
70
  - bin/rspec
86
- - bin/rubocop
87
71
  - bin/setup
88
72
  - elm-compiler.gemspec
89
- - elm-package.json
73
+ - elm.json
90
74
  - lib/elm-compiler.rb
91
75
  - lib/elm/compiler.rb
92
76
  - lib/elm/compiler/exceptions.rb
@@ -110,8 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
94
  - !ruby/object:Gem::Version
111
95
  version: '0'
112
96
  requirements: []
113
- rubyforge_project:
114
- rubygems_version: 2.4.5.1
97
+ rubygems_version: 3.1.6
115
98
  signing_key:
116
99
  specification_version: 4
117
100
  summary: Ruby wrapper for the Elm compiler
data/.rubocop.yml DELETED
@@ -1,11 +0,0 @@
1
- Metrics/LineLength:
2
- Max: 120
3
-
4
- Style/Documentation:
5
- Exclude:
6
- - 'spec/**/*'
7
- - 'test/**/*'
8
- - 'lib/elm/compiler.rb'
9
- - 'lib/elm/compiler/version.rb'
10
-
11
-
data/.travis.yml DELETED
@@ -1,11 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- rvm:
4
- - 2.2.3
5
- sudo: false
6
- before_install:
7
- - gem install bundler -v 1.11.2
8
- install:
9
- - bundle install
10
- - npm install -g elm@0.17
11
- - elm-package install --yes
data/bin/rubocop DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'rubocop' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('rubocop', 'rubocop')
data/elm-package.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "version": "1.0.0",
3
- "summary": "elm-package.json for rspec test suite",
4
- "repository": "https://github.com/user/project.git",
5
- "license": "BSD3",
6
- "source-directories": [
7
- "."
8
- ],
9
- "exposed-modules": [],
10
- "dependencies": {
11
- "elm-lang/core": "4.0.0 <= v < 5.0.0",
12
- "elm-lang/html": "1.0.0 <= v < 2.0.0"
13
- },
14
- "elm-version": "0.17.0 <= v < 0.18.0"
15
- }