func_e 0.0.1 → 0.0.3

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: 54aa55b846ee0e8ada8a7e6c80695c1501c5808e241d0c4f70d012007caab118
4
- data.tar.gz: eb92635652cacc884d217a98fdf168638f623d68dc4f67ae60167c209476cb8c
3
+ metadata.gz: 94b7493d7e162c78e41b8325055831e56c85de17fbd83fde8eb6a09fdefa3a03
4
+ data.tar.gz: 1ea3538f4f86b34411e27f136596770f416d377da4e3fbf2cc401cc5181e5eb1
5
5
  SHA512:
6
- metadata.gz: 83d04746a06e134e3c7025e40934138720ba04dfd8668fd45a65b70c8a05729106b751cd4fd8aa603e7c03e0bf7b9b8a22e106437d75f2d219b632f8aec8b41e
7
- data.tar.gz: 51e032b985be92c10b4b42a271b875f76a6c968d5f083a6244459f68a72c4ad9296a8b6f4f6fc17aee5e7a3e2a3166453ac711db92919ffa06a21ccece06529c
6
+ metadata.gz: 03de902a67807ee8682064230cfd4acf51e9516538c0c77eb4b860f1dc5fa1b51595dd35ba51b2d02db96bfd9dd06d54dd0ee8aee8886c80399dd6f494ffb889
7
+ data.tar.gz: 845c3d6a77fe7687ed758c36f29d8b50720db2a8ead4226d5cf999a2fce4637f9a67f4d27b279c67c32965b87fa86f5747db3a7300f304c2360769b89dc6f273
data/lib/func_e/config.rb CHANGED
@@ -25,7 +25,13 @@ module FuncE
25
25
  end
26
26
 
27
27
  def self.install_path
28
- defined?(Rails) ? Rails.root.join(@fn_dir_path) : Bundler.root.join(@fn_dir_path)
28
+ if defined?(Rails)
29
+ Rails.root.join(@fn_dir_path)
30
+ elsif defined?(Bundler)
31
+ Bundler.root.join(@fn_dir_path)
32
+ else
33
+ Dir.pwd
34
+ end
29
35
  end
30
36
  end
31
37
  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);
data/lib/railtie.rb CHANGED
@@ -10,8 +10,7 @@ module FuncE
10
10
  railtie_name :func_e
11
11
 
12
12
  rake_tasks do
13
- path = File.expand_path(__dir__)
14
- Dir.glob("#{path}/tasks/**/*.rake").each { |f| load f }
13
+ Dir.glob("#{File.expand_path(__dir__)}/tasks/**/*.rake").each { |f| load f }
15
14
  end
16
15
  end
17
16
  end
@@ -0,0 +1,11 @@
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
+ Dir.mkdir(FuncE::Config.install_path)
8
+ template = Pathname.new(__dir__).join('template')
9
+ FileUtils.cp_r "#{template}/.", FuncE::Config.install_path
10
+ end
11
+ 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.1
4
+ version: 0.0.3
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