Skip to content

Commit 646865a

Browse files
authored
Use manifest to declare input values (#27)
1 parent 73a650b commit 646865a

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,13 @@ package = "netlify-plugin-nimbella"
6969
You may provide additional configuration in the `netlify.toml` file to configure the resources available to your serverless functions, or to configure the API path for your functions. Here is an example.
7070

7171
```toml
72-
[nimbella]
72+
[[plugins]]
73+
package = "netlify-plugin-nimbella"
74+
[plugins.inputs]
7375
functions = "functions" # Functions source directory. Use this if you would like to use Nimbella to deploy your functions.
74-
timeout = 6000 # Function timeout limit in milliseconds.
7576
memory = 256 # Function memory limit in MB.
7677
path = "/api/" # The prefix path to access your deployed packages.
78+
timeout = 6000 # Function timeout limit in milliseconds.
7779
```
7880

7981
## Usage
@@ -112,13 +114,13 @@ You will invoke the function `auth/login.js` via the API end point `https://your
112114

113115
You can deploy your existing Netlify Functions to Nimbella Cloud with very minimal changes.
114116

115-
Move the `functions` property under `build` to `nimbella` inside `netlify.toml`.
117+
Specify the `functions` input value under `[plugins.inputs]` inside `netlify.toml`.
116118

117119
```diff
118-
[build]
119-
-functions = './functions'
120-
+[nimbella]
121-
+functions = './functions' # Source directory
120+
[[plugins]]
121+
package = "netlify-plugin-nimbella"
122+
+ [plugins.inputs]
123+
+ functions = "functions" # Functions source directory. Use this if you would like to use Nimbella to deploy your functions.
122124
```
123125

124126
This plugin builds your functions using a modified version of [netlify-lambda](https://github.com/netlify/netlify-lambda). You can get rid of any build steps you're performing on functions since the plugin handles it for you.

index.js

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ const functionsBuildDir = `functions-build-${Date.now()}`;
99
let netlifyToml = {};
1010
let isProject = false;
1111
let isActions = false;
12-
let options = {
13-
functions: '',
14-
timeout: 6000,
15-
memory: 256,
16-
path: '/api/'
17-
};
1812

1913
// Disable auto updates of nim.
2014
process.env.NIM_DISABLE_AUTOUPDATE = '1';
@@ -62,7 +56,7 @@ async function deployActions({run, functionsDir, timeout, memory}) {
6256

6357
module.exports = {
6458
// Execute before build starts.
65-
onPreBuild: async ({utils, constants}) => {
59+
onPreBuild: async ({utils, constants, inputs}) => {
6660
try {
6761
if (!process.env.NIMBELLA_LOGIN_TOKEN) {
6862
utils.build.failBuild(
@@ -89,34 +83,30 @@ module.exports = {
8983

9084
if (constants.CONFIG_PATH && existsSync(constants.CONFIG_PATH)) {
9185
netlifyToml = toml.parse(await readFile(constants.CONFIG_PATH));
92-
93-
if (netlifyToml.nimbella) {
94-
options = {...options, ...netlifyToml.nimbella};
95-
}
9686
}
9787

98-
isActions = options.functions ? existsSync(options.functions) : false;
88+
isActions = inputs.functions ? existsSync(inputs.functions) : false;
9989
isProject = existsSync('packages');
10090
} catch (error) {
10191
utils.build.failBuild(error.message);
10292
}
10393
},
10494
// Build the functions
105-
onBuild: async ({utils}) => {
95+
onBuild: async ({utils, inputs}) => {
10696
try {
10797
if (isActions) {
108-
// Here we're passing the build directory instead of source because source is extracted from options.functions.
98+
// Here we're passing the build directory instead of source because source is extracted from inputs.functions.
10999
const stats = await build.run(functionsBuildDir);
110100
console.log(stats.toString(stats.compilation.options.stats));
111101
// Copy any files that do not end with .js. T
112-
cpx.copy(options.functions + '/**/*.!(js)', functionsBuildDir);
102+
cpx.copy(inputs.functions + '/**/*.!(js)', functionsBuildDir);
113103
}
114104
} catch (error) {
115105
utils.build.failBuild(error.message);
116106
}
117107
},
118108
// Execute after build is done.
119-
onPostBuild: async ({constants, utils}) => {
109+
onPostBuild: async ({constants, utils, inputs}) => {
120110
try {
121111
const {stdout: namespace} = await utils.run.command(
122112
`npx nim auth current`
@@ -131,8 +121,8 @@ module.exports = {
131121
await deployActions({
132122
run: utils.run,
133123
functionsDir: functionsBuildDir,
134-
timeout: options.timeout, // Default is 6 seconds
135-
memory: options.memory // Default is 256MB (max for free tier)
124+
timeout: inputs.timeout, // Default is 6 seconds
125+
memory: inputs.memory // Default is 256MB (max for free tier)
136126
});
137127
}
138128
} else {
@@ -175,7 +165,7 @@ module.exports = {
175165
}
176166
}
177167

178-
let {path: redirectPath} = options;
168+
let {path: redirectPath} = inputs;
179169
redirectPath = redirectPath.endsWith('/')
180170
? redirectPath
181171
: redirectPath + '/';

manifest.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
11
name: netlify-plugin-nimbella
2+
inputs:
3+
- name: functions
4+
description: The source directory of the functions.
5+
- name: timeout
6+
description: Timeout LIMIT in milliseconds after which the function is terminated (functions input value is required to utilize this option).
7+
default: 6000
8+
- name: memory
9+
description: Maximum memory LIMIT in MB for the function (functions input value is required to utilize this option).
10+
default: 256
11+
- name: path
12+
description: The API prefix path you would like to use to access your functions.
13+
default: '/api/'

0 commit comments

Comments
 (0)