func_e 0.0.2 → 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: 7fbee8ad44a2fb1d73fbb44f397e0a2a1a599e7d4acf2112886c0fe5bff7ecf1
4
- data.tar.gz: 91191da9d2d92ad24d07b9f2fb7e5d54e7b7bc6f1efc6eba83b20d82b655f0a7
3
+ metadata.gz: 94b7493d7e162c78e41b8325055831e56c85de17fbd83fde8eb6a09fdefa3a03
4
+ data.tar.gz: 1ea3538f4f86b34411e27f136596770f416d377da4e3fbf2cc401cc5181e5eb1
5
5
  SHA512:
6
- metadata.gz: 870ad1e749e17ab179ce899ebfd88191cfe10c446b2cf513469c8381ac25b4a496f3373407dbf493e131492764582082209ed74c82ccd42175cf1f3d41209809
7
- data.tar.gz: '09dd36eab3c56241acea4e18a092be1d16bb6b38f635fdb838fc3f7f2585b1a9b27d74db29d64dd4dec699fd21179f3b015b0660d7e2a1714a77f312ae7d4c54'
6
+ metadata.gz: 03de902a67807ee8682064230cfd4acf51e9516538c0c77eb4b860f1dc5fa1b51595dd35ba51b2d02db96bfd9dd06d54dd0ee8aee8886c80399dd6f494ffb889
7
+ data.tar.gz: 845c3d6a77fe7687ed758c36f29d8b50720db2a8ead4226d5cf999a2fce4637f9a67f4d27b279c67c32965b87fa86f5747db3a7300f304c2360769b89dc6f273
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,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.2
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