elm-compiler 0.4.0 → 0.5.1

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: 850e6bbb8b9adc11e42322b89e1b61beb4c92dba7e5b9172569ef506637ce05d
4
- data.tar.gz: e7979cac94a9b0fa3a0307d69eb1b3071f73ae1ca8859aa2e2fc1bb3071d513d
3
+ metadata.gz: 0f23ecd935d96dd75433e1f54c93a6401ee18ecc6f6afb4693f55f489aaafc64
4
+ data.tar.gz: eccb9d81d4685e28283006f3a0c7b87518930f60b820ea8a8e3aeb06e0c3c634
5
5
  SHA512:
6
- metadata.gz: cfb7aee36120a88c85ed5133b32a6ed4d57790ffd57d52313fbf07e3c7be3c33ae18c6b17e82aad30269479291332d3f2fd5e62cd9367686d4b914f3f7b8ab5c
7
- data.tar.gz: 870870911f6e04eb1f4b31afd958627693e77c8d43ed845f6862b0feea8032a492d45a3404034e680db68bb447bba7ee512ca82671df2f4efce14525350ab3e2
6
+ metadata.gz: d85540f123294b557dba0d241fb585fad3a50d250f31a7eb8eeb13450337d25d23cb6f46ff1a21dbe1905258a4f23b201f03632e881a9f8b17e857f5a25b8a76
7
+ data.tar.gz: fd1b989aac484058ef6405c6028a1c057199fe601ceedaa4adaef42b767d6a4599cdc8b56bc30e7b89afa98e2605353380ddcb553d869edfa7f78876f67cf8f3
@@ -9,7 +9,7 @@ jobs:
9
9
 
10
10
  runs-on: ubuntu-latest
11
11
  steps:
12
- - uses: actions/checkout@v2
12
+ - uses: actions/checkout@v3
13
13
  - uses: ruby/setup-ruby@v1
14
14
  with:
15
15
  ruby-version: ${{ matrix.ruby }}
data/README.md CHANGED
@@ -31,13 +31,14 @@ Or install it yourself as:
31
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_path: nil, debug: false)
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
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
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
@@ -1,5 +1,5 @@
1
1
  module Elm
2
2
  class Compiler
3
- VERSION = '0.4.0'
3
+ VERSION = '0.5.1'
4
4
  end
5
5
  end
data/lib/elm/compiler.rb CHANGED
@@ -10,25 +10,27 @@ module Elm
10
10
  @elm_path ||= elm_from_env_path || our_elm_path
11
11
  end
12
12
 
13
- def compile(elm_files, output_path: nil, elm_path: self.elm_path, debug: false)
13
+ attr_accessor :esm
14
+
15
+ def compile(elm_files, output_path: nil, elm_path: self.elm_path, debug: false, esm: self.esm)
14
16
  fail ExecutableNotFound unless elm_executable_exists?(elm_path)
15
17
  if output_path
16
- elm_make(elm_path, elm_files, output_path, debug)
18
+ elm_make(elm_path, elm_files, output_path, debug, esm)
17
19
  else
18
- compile_to_string(elm_path, elm_files, debug)
20
+ compile_to_string(elm_path, elm_files, debug, esm)
19
21
  end
20
22
  end
21
23
 
22
24
  private
23
25
 
24
- def compile_to_string(elm_path, elm_files, debug)
26
+ def compile_to_string(elm_path, elm_files, debug, esm)
25
27
  Tempfile.open(['elm', '.js']) do |tempfile|
26
- elm_make(elm_path, elm_files, tempfile.path, debug)
28
+ elm_make(elm_path, elm_files, tempfile.path, debug, esm)
27
29
  return File.read tempfile.path
28
30
  end
29
31
  end
30
32
 
31
- def elm_make(elm_path, elm_files, output_path, debug)
33
+ def elm_make(elm_path, elm_files, output_path, debug, esm)
32
34
  args = [
33
35
  {"LANG" => "en_US.UTF8" },
34
36
  elm_path,
@@ -40,6 +42,17 @@ module Elm
40
42
  Open3.popen3(*args) do |_stdin, _stdout, stderr, wait_thr|
41
43
  fail CompileError, stderr.gets(nil) if wait_thr.value.exitstatus != 0
42
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\)\)\;/m, 1]
51
+ contents.gsub!(/\(function\s*\(scope\)\s*\{$/m, '// -- \1')
52
+ contents.gsub!(/['"]use strict['"];$/, '// -- \1')
53
+ contents.gsub!(/^\s*_Platform_export\((.*)\)\;\n?\}\(this\)\)\;/m, '/*\n\1\n*/')
54
+ contents << "\nexport default #{exports};"
55
+ File.write(path, contents)
43
56
  end
44
57
 
45
58
  def elm_executable_exists?(path)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elm-compiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Bonetti
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-26 00:00:00.000000000 Z
11
+ date: 2023-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
96
  requirements: []
97
- rubygems_version: 3.1.6
97
+ rubygems_version: 3.2.32
98
98
  signing_key:
99
99
  specification_version: 4
100
100
  summary: Ruby wrapper for the Elm compiler