func_e 0.0.2 → 0.0.4

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: 7fbee8ad44a2fb1d73fbb44f397e0a2a1a599e7d4acf2112886c0fe5bff7ecf1
4
- data.tar.gz: 91191da9d2d92ad24d07b9f2fb7e5d54e7b7bc6f1efc6eba83b20d82b655f0a7
3
+ metadata.gz: 4822d7ecd0a7ced321d7c390b2b8a0a3562fc9c59ab6e7576dba6a90226c4734
4
+ data.tar.gz: c06b82eb855c0f13930f506f85fe83c879ec715cb2e1fb83061dfb1e15a96143
5
5
  SHA512:
6
- metadata.gz: 870ad1e749e17ab179ce899ebfd88191cfe10c446b2cf513469c8381ac25b4a496f3373407dbf493e131492764582082209ed74c82ccd42175cf1f3d41209809
7
- data.tar.gz: '09dd36eab3c56241acea4e18a092be1d16bb6b38f635fdb838fc3f7f2585b1a9b27d74db29d64dd4dec699fd21179f3b015b0660d7e2a1714a77f312ae7d4c54'
6
+ metadata.gz: d4ae967440ee1fda5283b350434ed3487b2f1907bc5da0fad84c1e29dd90b66f19b480192e2266904b080e5bfe8539661548277990bc238b3a5c68a2a78e5ee4
7
+ data.tar.gz: 135887a3d446190fba94da8095e51af8415f729b63b4e4063ade7979f208290bb01bfb751a2e64c5da19c0fb197bf4409d791a9d18108d8cf807d45699d92dee
data/lib/func_e/config.rb CHANGED
@@ -8,12 +8,12 @@ module FuncE
8
8
  class Config
9
9
  include Singleton
10
10
 
11
+ DEFAULT_INSTALL_DIR = 'funcs'
12
+
11
13
  attr_accessor :fn_dir_path
12
14
 
13
15
  def self.configure
14
16
  yield instance
15
-
16
- @fn_dir_path = 'funcs' if @fn_dir_path.nil?
17
17
  end
18
18
 
19
19
  def self.config
@@ -26,11 +26,11 @@ module FuncE
26
26
 
27
27
  def self.install_path
28
28
  if defined?(Rails)
29
- Rails.root.join(@fn_dir_path)
29
+ Rails.root.join(@fn_dir_path || DEFAULT_INSTALL_DIR)
30
30
  elsif defined?(Bundler)
31
- Bundler.root.join(@fn_dir_path)
31
+ Bundler.root.join(@fn_dir_path || DEFAULT_INSTALL_DIR)
32
32
  else
33
- Dir.pwd
33
+ Pathname.new(Dir.pwd).join(@fn_dir_path || DEFAULT_INSTALL_DIR)
34
34
  end
35
35
  end
36
36
  end
data/lib/func_e.js ADDED
@@ -0,0 +1,45 @@
1
+ /**
2
+ * This script is an entrypoint for the JavaScript service. It will expect a
3
+ * script name as an argument and will execute the script with the provided
4
+ * arguments. The script must be located in the node/functions directory. And
5
+ * the arguments must be provided as a JSON string to be parsed.
6
+ *
7
+ * All functions must return a value that can be serialized and exposed arguments
8
+ * as an object. The function will be executed with the provided arguments and
9
+ * always return an Promise that resolves to the result of the function. Thus
10
+ * all functions must be asynchronous.
11
+ */
12
+
13
+ /**
14
+ * Extract the arguments from the command line.
15
+ */
16
+ let args = {};
17
+
18
+ process.argv.slice(2).forEach(arg => {
19
+ if (arg.startsWith('--')) {
20
+ const split = arg.indexOf('=');
21
+ args[arg.substring(2, split)] = arg.substring(split + 1);
22
+ }
23
+ })
24
+
25
+ // If any of the required arguments are missing, throw an error.
26
+ if (!args.path) throw new Error('Missing function name (--fn=<FUNCTION_NAME>');
27
+
28
+ // If the payload is provided, parse it as JSON. Otherwise, set it to an empty object.
29
+ const jsonPayload = args.payload ? JSON.parse(args.payload) : {};
30
+
31
+ // Wrap the function in an anonymous async function and execute it.
32
+ (async (params) => {
33
+ // Execute the function.
34
+ const result = await require(args.path)(params);
35
+
36
+ // Insure the result is an object that can be serialized.
37
+ if (typeof result !== 'object') {
38
+ throw new Error('Function must return an object');
39
+ }
40
+
41
+ // Write the result to stdout.
42
+ process.stdout.write(
43
+ JSON.stringify(result)
44
+ );
45
+ })(jsonPayload);
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :func_e do
4
+ desc 'Install func_e by generating the functions directory to the root of your project'
5
+
6
+ task :install do
7
+ template = Pathname.new(__dir__).join('template')
8
+ FileUtils.cp_r "#{template}/.", FuncE::Config.install_path
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ module.exports = function helloFn({ planet }) {
2
+ return {
3
+ result: `Hello, ${planet}!`
4
+ }
5
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "func_e",
3
+ "version": "1.0.0",
4
+ "description": "Some func_e code.",
5
+ "author": "Sebastian Scholl",
6
+ "license": "ISC"
7
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: func_e
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Scholl
@@ -50,10 +50,14 @@ executables: []
50
50
  extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
53
+ - lib/func_e.js
53
54
  - lib/func_e.rb
54
55
  - lib/func_e/config.rb
55
56
  - lib/func_e/func.rb
56
57
  - lib/railtie.rb
58
+ - lib/tasks/install/install.rake
59
+ - lib/tasks/install/template/helloFn.js
60
+ - lib/tasks/install/template/package.json
57
61
  homepage: https://github.com/sebscholl/FuncE
58
62
  licenses:
59
63
  - MIT