elm-compiler 0.3.0 → 0.5.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: 6e604d6187008d8edbe57c58f5c50b0ae6a161e1
4
- data.tar.gz: 8006d7cc87b27a3c96e996ad20ec09543f697ab1
2
+ SHA256:
3
+ metadata.gz: 28756a5b0cde783ca8b032103fe8c49fe31002f4c9a5cfa1b8f2645b867f63d7
4
+ data.tar.gz: 16cdc3ab15baa7995c9d2446cadbc4d1e37f744749c763b57c584b3b58cceb29
5
5
  SHA512:
6
- metadata.gz: 02ae3eeeeaaf8531cd45aceaec1f3a3b114b34bbeea855df3630cac43c1d6443e0e447213a9a31416a09df857e8512640c70ea7e8ad399ee3aa7006cec8d2060
7
- data.tar.gz: 3320a10a805fc847cf128a73c0e84a47b86aa3b0372474777ab0d5ff6b2c1682f5a1b30426463b61ac9517de8197781f91f301859f584d89013585aa103e9a5a
6
+ metadata.gz: 966a4f9d92b274ba0dd678deb558174852d35c5050a6a4d49e85fdb86b28fcf382324533a3721b6067737885f0ba9114a45d7481428d0a226c75c199fe3adf1e
7
+ data.tar.gz: ead2697e36189e12694db5c227c69c72401b8987ab7793a2a7047e03edb2d360a74a0670cb2e6e031b5f388371101816e7e4fdb9f1c9a61b477a602a4436ebc7
@@ -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@v3
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,17 @@ 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, esm: 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
+ * `esm`: Whether or not to rewrite the compilation result into ESM format. Default is false. Can also be set on a global basis by `Elm::Compiler.elm = true`
41
42
 
42
43
 
43
44
  ## 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.3.0'
3
+ VERSION = '0.5.0'
4
4
  end
5
5
  end
data/lib/elm/compiler.rb CHANGED
@@ -5,37 +5,78 @@ require 'tempfile'
5
5
  module Elm
6
6
  class Compiler
7
7
  class << self
8
- def compile(elm_files, output_path: nil, elm_make_path: "elm-make", debug: false)
9
- fail ExecutableNotFound unless elm_executable_exists?(elm_make_path)
8
+ attr_writer :elm_path
9
+ def elm_path
10
+ @elm_path ||= elm_from_env_path || our_elm_path
11
+ end
12
+
13
+ attr_accessor :esm
10
14
 
15
+ def compile(elm_files, output_path: nil, elm_path: self.elm_path, debug: false, esm: self.esm)
16
+ fail ExecutableNotFound unless elm_executable_exists?(elm_path)
11
17
  if output_path
12
- elm_make(elm_make_path, elm_files, output_path, debug)
18
+ elm_make(elm_path, elm_files, output_path, debug, esm)
13
19
  else
14
- compile_to_string(elm_make_path, elm_files, debug)
20
+ compile_to_string(elm_path, elm_files, debug, esm)
15
21
  end
16
22
  end
17
23
 
18
24
  private
19
25
 
20
- def elm_executable_exists?(elm_make_path)
21
- Open3.popen2(elm_make_path){}.nil?
22
- rescue Errno::ENOENT, Errno::EACCES
23
- false
24
- end
25
-
26
- def compile_to_string(elm_make_path, elm_files, debug)
26
+ def compile_to_string(elm_path, elm_files, debug, esm)
27
27
  Tempfile.open(['elm', '.js']) do |tempfile|
28
- elm_make(elm_make_path, elm_files, tempfile.path, debug)
28
+ elm_make(elm_path, elm_files, tempfile.path, debug, esm)
29
29
  return File.read tempfile.path
30
30
  end
31
31
  end
32
32
 
33
- def elm_make(elm_make_path, elm_files, output_path, debug)
34
- args = [{"LANG" => "en_US.UTF8" }, elm_make_path, *elm_files, '--yes', '--output', output_path]
35
- args << "--debug" if debug
33
+ def elm_make(elm_path, elm_files, output_path, debug, esm)
34
+ args = [
35
+ {"LANG" => "en_US.UTF8" },
36
+ elm_path,
37
+ "make",
38
+ *elm_files,
39
+ "--output=#{output_path}",
40
+ debug ? "--debug" : "--optimize",
41
+ ]
36
42
  Open3.popen3(*args) do |_stdin, _stdout, stderr, wait_thr|
37
43
  fail CompileError, stderr.gets(nil) if wait_thr.value.exitstatus != 0
38
44
  end
45
+ convert_file_to_esm!(output_path) if esm
46
+ end
47
+
48
+ def convert_file_to_esm!(path)
49
+ contents = File.read(path)
50
+ exports = contents[/^\s*_Platform_export\((.*)\)\;\n?\}\(this\)\)\;/, 1]
51
+ contents.gsub!(/\(function\s*\(scope\)\s*\{$/, '// -- \1')
52
+ contents.gsub!(/['"]use strict['"];$/, '// -- \1')
53
+ contents.gsub!(/function _Platform_export(.*?)\}\n/, '/*\n\1\n*/')
54
+ contents.gsub!(/function _Platform_mergeExports(.*?)\}\n\s*}/, '/*\n\1\n*/')
55
+ contents.gsub!(/^\s*_Platform_export\((.*)\)\;\n?}\(this\)\)\;/, '/*\n\1\n*/')
56
+ contents << "\nexport default #{exports};"
57
+ File.write(path, contents)
58
+ end
59
+
60
+ def elm_executable_exists?(path)
61
+ `#{path} --version`.strip == "0.19.1"
62
+ rescue
63
+ false
64
+ end
65
+
66
+ def elm_from_env_path
67
+ `which elm`.chomp.tap { |p| return nil if p == "" }
68
+ end
69
+
70
+ def our_elm_path
71
+ path = "/tmp/elm-0.19.1"
72
+ unless elm_executable_exists?(path)
73
+ system """
74
+ curl -sfLo #{path}.gz https://github.com/elm/compiler/releases/download/0.19.1/binary-for-linux-64-bit.gz
75
+ gunzip -f #{path}.gz
76
+ chmod +x #{path}
77
+ """
78
+ end
79
+ path
39
80
  end
40
81
  end
41
82
  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.3.0
4
+ version: 0.5.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: 2017-02-10 00:00:00.000000000 Z
11
+ date: 2023-03-25 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.5.1
97
+ rubygems_version: 3.2.32
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
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": "5.0.0 <= v < 6.0.0",
12
- "elm-lang/html": "2.0.0 <= v < 3.0.0"
13
- },
14
- "elm-version": "0.18.0 <= v < 0.19.0"
15
- }