node-runner 1.0.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c6222ef23c1975d9325fbf60b6bbbd63a6ffad0c13c5249e8c1b4734f09dab9
4
- data.tar.gz: abbd491dd0894a0a2a13d8d56138ddca1c8f168b969c3dea8e31ec96bce6ab5a
3
+ metadata.gz: a733bf42b17f92ee1c91bf8a7c4ca2eff92cfbc597616194484eeacff633a3e8
4
+ data.tar.gz: '0839ed6d6df8a18edd76bffb58d91f895037dbd6919320c2385013fbcf1231fd'
5
5
  SHA512:
6
- metadata.gz: 8c4932b21e6a843e53abb1943de4062e685f8e45b12c2bcdda63765235262f2a83c31179961fd0a59ba53031393a307b0711cd39eae122e6618b4399a096a258
7
- data.tar.gz: de4c98cdd6b6be6b07e6c8c8a0e18fc8a2555a505d5dc102be72bf88830a8877c39b71be3faea208cc20b1e1e3bff79155ec6854ce1d6f5bbb68410f59cd1d41
6
+ metadata.gz: 92f31ae689bc4f5d8404e4a756a13428ec099f4a8ae0abd9e2cd43a1070192c5a5abbaa5739ee2ef1d8fe137f99cba8f14edb8d55c87bafcaef854ec85c8b43d
7
+ data.tar.gz: 31a2e69aebf9983b44bdf23e66905fbc471d0abd955035c57cc36f4079becfc07b3c77d6ad167ccbe60efc4662783f2939bd207a8c88cd16914f3ae84de2f417
data/CHANGELOG.md CHANGED
@@ -1,9 +1,21 @@
1
- # master
1
+ # Changelog
2
2
 
3
- # 1.0.1 / 2020-05-09
3
+ ## Unreleased
4
4
 
5
- Set the NODE_ENV so local modules can be found.
5
+ ...
6
6
 
7
- # 1.0.0 / 2020-04-29
7
+ ## 1.2.0 / 2024-04-05
8
8
 
9
- Initial release of NodeRunner.
9
+ - Add support for functions returning promises
10
+
11
+ ## 1.1.0 / 2021-10-17
12
+
13
+ - fix: windows support for extensions [#1](https://github.com/bridgetownrb/node-runner/pull/1) ([bglw](https://github.com/bglw))
14
+
15
+ ## 1.0.1 / 2020-05-09
16
+
17
+ - Set the NODE_ENV so local modules can be found.
18
+
19
+ ## 1.0.0 / 2020-04-29
20
+
21
+ - Initial release of NodeRunner.
data/README.md CHANGED
@@ -12,6 +12,12 @@ Run this command to add this plugin to your project's Gemfile:
12
12
  $ bundle add node-runner
13
13
  ```
14
14
 
15
+ For [Bridgetown](https://www.bridgetownrb.com) websites, you can run an automation to install NodeRunner and set up a builder plugin for further customization.
16
+
17
+ ```shell
18
+ bin/bridgetown apply https://github.com/bridgetownrb/node-runner
19
+ ```
20
+
15
21
  ## Usage
16
22
 
17
23
  Simply create a new `NodeRunner` object and pass in the Javascript code you wish to
@@ -21,11 +27,11 @@ execute:
21
27
  require "node-runner"
22
28
 
23
29
  runner = NodeRunner.new(
24
- <<~NODE
30
+ <<~JAVASCRIPT
25
31
  const hello = (response) => {
26
- return `Hello? ${response}!`
32
+ return `Hello? ${response}`
27
33
  }
28
- NODE
34
+ JAVASCRIPT
29
35
  )
30
36
  ```
31
37
 
@@ -44,12 +50,12 @@ You can also use Node require statements in your Javascript:
44
50
 
45
51
  ```ruby
46
52
  runner = NodeRunner.new(
47
- <<~NODE
53
+ <<~JAVASCRIPT
48
54
  const path = require("path")
49
55
  const extname = (filename) => {
50
56
  return path.extname(filename);
51
57
  }
52
- NODE
58
+ JAVASCRIPT
53
59
  )
54
60
 
55
61
  extname = runner.extname("README.md")
@@ -85,7 +91,7 @@ Node Runner would be via a background job, or during a build process like when u
85
91
 
86
92
  ## Testing
87
93
 
88
- * Run `bundle exec rake` to run the test suite.
94
+ * Run `bin/rake` to run the test suite.
89
95
 
90
96
  ## Contributing
91
97
 
data/bin/rake ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rake", "rake")
@@ -0,0 +1,29 @@
1
+ run "bundle add node-runner", abort_on_failure: false
2
+
3
+ builder_file = "node_script_builder.rb"
4
+ create_builder builder_file do
5
+ <<~RUBY
6
+ require "node-runner"
7
+
8
+ class Builders::NodeScriptBuilder < SiteBuilder
9
+ def build
10
+ # access output in Liquid with {{ site.data.node_script.hello }}
11
+ add_data "node_script" do
12
+ runner = NodeRunner.new(
13
+ <<~JAVASCRIPT
14
+ const hello = (response) => {
15
+ return `Hello? ${response}`
16
+ }
17
+ JAVASCRIPT
18
+ )
19
+
20
+ {
21
+ hello: runner.hello("Goodbye!")
22
+ }
23
+ end
24
+ end
25
+ end
26
+ RUBY
27
+ end
28
+
29
+ say_status "node-runner", "Installed! Check out plugins/builders/#{builder_file} to customize your Node script"
data/lib/node-runner.rb CHANGED
@@ -117,16 +117,20 @@ class NodeRunner::Executor
117
117
 
118
118
  def locate_executable(command)
119
119
  commands = Array(command)
120
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
121
+ exts << ''
120
122
 
121
123
  commands.find { |cmd|
122
124
  if File.executable? cmd
123
125
  cmd
124
126
  else
125
- path = ENV['PATH'].split(File::PATH_SEPARATOR).find { |p|
126
- full_path = File.join(p, cmd)
127
- File.executable?(full_path) && File.file?(full_path)
127
+ path = ENV['PATH'].split(File::PATH_SEPARATOR).flat_map { |p|
128
+ exts.map { |e| File.join(p, "#{cmd}#{e}") }
129
+ }.find { |p|
130
+ File.executable?(p) && File.file?(p)
128
131
  }
129
- path && File.expand_path(cmd, path)
132
+
133
+ path && File.expand_path(path)
130
134
  end
131
135
  }
132
136
  end
data/lib/node_runner.js CHANGED
@@ -2,8 +2,10 @@
2
2
 
3
3
  try {
4
4
  const args = #{args}
5
- const output = JSON.stringify(['ok', #{func}(...args), []])
6
- process.stdout.write(output)
5
+ Promise.resolve(#{func}(...args)).then(result => {
6
+ const output = JSON.stringify(['ok', result, []])
7
+ process.stdout.write(output)
8
+ })
7
9
  } catch (err) {
8
10
  process.stdout.write(JSON.stringify(['err', '' + err, err.stack]))
9
11
  }
data/lib/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  class NodeRunner
2
- VERSION = "1.0.1"
2
+ VERSION = "1.2.0"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: node-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-10 00:00:00.000000000 Z
11
+ date: 2024-04-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description:
13
+ description:
14
14
  email: maintainers@bridgetownrb.com
15
15
  executables: []
16
16
  extensions: []
@@ -22,6 +22,8 @@ files:
22
22
  - LICENSE.txt
23
23
  - README.md
24
24
  - Rakefile
25
+ - bin/rake
26
+ - bridgetown.automation.rb
25
27
  - lib/node-runner.rb
26
28
  - lib/node_runner.js
27
29
  - lib/version.rb
@@ -30,7 +32,7 @@ homepage: https://github.com/bridgetownrb/node-runner
30
32
  licenses:
31
33
  - MIT
32
34
  metadata: {}
33
- post_install_message:
35
+ post_install_message:
34
36
  rdoc_options: []
35
37
  require_paths:
36
38
  - lib
@@ -45,8 +47,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
47
  - !ruby/object:Gem::Version
46
48
  version: '0'
47
49
  requirements: []
48
- rubygems_version: 3.0.8
49
- signing_key:
50
+ rubygems_version: 3.5.3
51
+ signing_key:
50
52
  specification_version: 4
51
53
  summary: A simple way to execute Javascript in a Ruby context via Node
52
54
  test_files: []