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 +4 -4
- data/.github/workflows/ci.yml +1 -1
- data/README.md +2 -1
- data/lib/elm/compiler/version.rb +1 -1
- data/lib/elm/compiler.rb +19 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f23ecd935d96dd75433e1f54c93a6401ee18ecc6f6afb4693f55f489aaafc64
|
4
|
+
data.tar.gz: eccb9d81d4685e28283006f3a0c7b87518930f60b820ea8a8e3aeb06e0c3c634
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d85540f123294b557dba0d241fb585fad3a50d250f31a7eb8eeb13450337d25d23cb6f46ff1a21dbe1905258a4f23b201f03632e881a9f8b17e857f5a25b8a76
|
7
|
+
data.tar.gz: fd1b989aac484058ef6405c6028a1c057199fe601ceedaa4adaef42b767d6a4599cdc8b56bc30e7b89afa98e2605353380ddcb553d869edfa7f78876f67cf8f3
|
data/.github/workflows/ci.yml
CHANGED
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
|
data/lib/elm/compiler/version.rb
CHANGED
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
|
-
|
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
|
+
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:
|
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.
|
97
|
+
rubygems_version: 3.2.32
|
98
98
|
signing_key:
|
99
99
|
specification_version: 4
|
100
100
|
summary: Ruby wrapper for the Elm compiler
|