Skip to content

Commit 1e2daff

Browse files
committed
Linter.
1 parent 43889f0 commit 1e2daff

File tree

3 files changed

+151
-151
lines changed

3 files changed

+151
-151
lines changed

__mocks__/netlify-lambda/lib/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
22
run: jest.fn()
3-
};
3+
}

src/index.js

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
const {existsSync} = require('fs');
2-
const {appendFile, readFile, readdir, writeFile} = require('fs').promises;
3-
const {join} = require('path');
4-
const {homedir, tmpdir} = require('os');
1+
const {existsSync} = require('fs')
2+
const {appendFile, readFile, readdir, writeFile} = require('fs').promises
3+
const {join} = require('path')
4+
const {homedir, tmpdir} = require('os')
55

6-
const toml = require('@iarna/toml');
7-
const cpx = require('cpx');
8-
const build = require('netlify-lambda/lib/build');
6+
const toml = require('@iarna/toml')
7+
const cpx = require('cpx')
8+
const build = require('netlify-lambda/lib/build')
99

10-
const functionsBuildDir = `functions-build-${Date.now()}`;
11-
const nimConfig = join(homedir(), '.nimbella');
12-
let netlifyToml = {};
13-
let isProject = false;
14-
let isActions = false;
10+
const functionsBuildDir = `functions-build-${Date.now()}`
11+
const nimConfig = join(homedir(), '.nimbella')
12+
let netlifyToml = {}
13+
let isProject = false
14+
let isActions = false
1515

1616
// Disable auto updates of nim.
17-
process.env.NIM_DISABLE_AUTOUPDATE = '1';
17+
process.env.NIM_DISABLE_AUTOUPDATE = '1'
1818

1919
/**
2020
* Deploy a Nimbella Project.
2121
* @param {*} run - function provided under utils by Netlify to build event functions.
2222
*/
2323
async function deployProject(run) {
24-
await run.command(`nim project deploy . --exclude=web`);
24+
await run.command(`nim project deploy . --exclude=web`)
2525
}
2626

2727
/**
@@ -30,36 +30,36 @@ async function deployProject(run) {
3030
* @param {string} functionsDir - Path to the actions directory.
3131
*/
3232
async function deployActions({run, functionsDir, timeout, memory, envsFile}) {
33-
const files = await readdir(functionsDir);
33+
const files = await readdir(functionsDir)
3434
if (!existsSync(envsFile)) {
35-
envsFile = false;
35+
envsFile = false
3636
}
3737

3838
await Promise.all(
3939
files.map(async (file) => {
40-
const [actionName, extension] = file.split('.');
40+
const [actionName, extension] = file.split('.')
4141
const command = [
4242
`nim action update ${actionName} ${join(functionsDir, file)}`,
4343
`--timeout=${Number(timeout)} --memory=${Number(memory)} `,
4444
`--web=raw`
45-
];
45+
]
4646

4747
if (extension === 'js') {
48-
command.push('--kind nodejs-lambda:10 --main handler');
48+
command.push('--kind nodejs-lambda:10 --main handler')
4949
}
5050

5151
if (envsFile) {
52-
command.push(`--env-file=${envsFile}`);
52+
command.push(`--env-file=${envsFile}`)
5353
}
5454

5555
const {stderr, exitCode, failed} = await run.command(command.join(' '), {
5656
reject: false,
5757
stdout: 'ignore'
58-
});
59-
const message = exitCode === 0 && !failed ? 'done.' : String(stderr);
60-
console.log(`Deploying ${file}: ${message}`);
58+
})
59+
const message = exitCode === 0 && !failed ? 'done.' : String(stderr)
60+
console.log(`Deploying ${file}: ${message}`)
6161
})
62-
);
62+
)
6363
}
6464

6565
module.exports = {
@@ -71,85 +71,85 @@ module.exports = {
7171
) {
7272
utils.build.failBuild(
7373
'Nimbella login token is not available. Please run `netlify addons:create nimbella` at the base of your local project directory linked to your Netlify site.'
74-
);
74+
)
7575
}
7676

77-
await utils.cache.restore(nimConfig);
77+
await utils.cache.restore(nimConfig)
7878

79-
const loggedIn = existsSync(nimConfig);
79+
const loggedIn = existsSync(nimConfig)
8080
// Login if not logged in before.
8181
if (loggedIn) {
8282
try {
8383
const {stdout} = await utils.run.command('nim auth current', {
8484
stdout: 'pipe'
85-
});
86-
console.log(`Using the following namespace: ${stdout}`);
85+
})
86+
console.log(`Using the following namespace: ${stdout}`)
8787
} catch (error) {
8888
utils.build.failBuild(
8989
'Failed to retrieve the current namespace from cache',
9090
{error}
91-
);
91+
)
9292
}
9393
} else {
9494
try {
9595
await utils.run.command(
9696
`nim auth login ${process.env.NIMBELLA_LOGIN_TOKEN}`
97-
);
97+
)
9898
// Cache the nimbella config to avoid logging in for consecutive builds.
99-
await utils.cache.save(nimConfig);
99+
await utils.cache.save(nimConfig)
100100
} catch (error) {
101101
utils.build.failBuild('Failed to login using the provided token', {
102102
error
103-
});
103+
})
104104
}
105105
}
106106

107107
if (constants.CONFIG_PATH && existsSync(constants.CONFIG_PATH)) {
108-
netlifyToml = toml.parse(await readFile(constants.CONFIG_PATH));
108+
netlifyToml = toml.parse(await readFile(constants.CONFIG_PATH))
109109
}
110110

111-
isActions = inputs.functions ? existsSync(inputs.functions) : false;
112-
isProject = existsSync('packages');
111+
isActions = inputs.functions ? existsSync(inputs.functions) : false
112+
isProject = existsSync('packages')
113113
},
114114
// Build the functions
115115
onBuild: async ({utils, inputs}) => {
116116
try {
117117
if (isActions) {
118118
// Here we're passing the build directory instead of source because source is extracted from inputs.functions.
119-
const stats = await build.run(functionsBuildDir, inputs.functions);
120-
console.log(stats.toString(stats.compilation.options.stats));
119+
const stats = await build.run(functionsBuildDir, inputs.functions)
120+
console.log(stats.toString(stats.compilation.options.stats))
121121
// Copy any files that do not end with .js. T
122-
cpx.copy(inputs.functions + '/**/*.!(js)', functionsBuildDir);
122+
cpx.copy(inputs.functions + '/**/*.!(js)', functionsBuildDir)
123123
}
124124
} catch (error) {
125-
utils.build.failBuild('Failed to build the functions', {error});
125+
utils.build.failBuild('Failed to build the functions', {error})
126126
}
127127
},
128128
// Execute after build is done.
129129
onPostBuild: async ({constants, utils, inputs}) => {
130-
const {stdout: namespace} = await utils.run.command(`nim auth current`);
130+
const {stdout: namespace} = await utils.run.command(`nim auth current`)
131131

132132
if (process.env.CONTEXT === 'production') {
133133
if (isProject) {
134134
try {
135-
await deployProject(utils.run);
135+
await deployProject(utils.run)
136136
} catch (error) {
137-
utils.build.failBuild('Failed to deploy the project', {error});
137+
utils.build.failBuild('Failed to deploy the project', {error})
138138
}
139139
}
140140

141141
if (isActions) {
142-
console.log('\n------------------Functions------------------\n');
142+
console.log('\n------------------Functions------------------\n')
143143
try {
144144
if (inputs.envs.length > 0) {
145-
const envs = {};
146-
let envMessage = 'Forwarded the following environment variables: ';
145+
const envs = {}
146+
let envMessage = 'Forwarded the following environment variables: '
147147
inputs.envs.forEach((env, index) => {
148-
envs[env] = process.env[env];
149-
envMessage += index === inputs.envs.length - 1 ? env : env + ', ';
150-
});
151-
await writeFile(join(tmpdir(), 'env.json'), JSON.stringify(envs));
152-
console.log(envMessage);
148+
envs[env] = process.env[env]
149+
envMessage += index === inputs.envs.length - 1 ? env : env + ', '
150+
})
151+
await writeFile(join(tmpdir(), 'env.json'), JSON.stringify(envs))
152+
console.log(envMessage)
153153
}
154154

155155
await deployActions({
@@ -158,36 +158,36 @@ module.exports = {
158158
functionsDir: functionsBuildDir,
159159
timeout: inputs.timeout, // Default is 6 seconds
160160
memory: inputs.memory // Default is 256MB (max for free tier)
161-
});
161+
})
162162
} catch (error) {
163-
utils.build.failBuild('Failed to deploy the functions', {error});
163+
utils.build.failBuild('Failed to deploy the functions', {error})
164164
}
165165
}
166166
} else {
167167
console.log(
168168
`Skipping the deployment to Nimbella as the context (${process.env.CONTEXT}) is not production.`
169-
);
169+
)
170170
}
171171

172-
const redirectRules = [];
173-
const redirects = [];
174-
const redirectsFile = join(constants.PUBLISH_DIR, '_redirects');
172+
const redirectRules = []
173+
const redirects = []
174+
const redirectsFile = join(constants.PUBLISH_DIR, '_redirects')
175175

176176
if (isActions) {
177177
if (existsSync(redirectsFile)) {
178178
console.log(
179179
"Found _redirects file. We will rewrite rules that redirect (200 rewrites) to '/.netlify/functions/*'."
180-
);
181-
const {parseRedirectsFormat} = require('netlify-redirect-parser');
182-
const {success} = await parseRedirectsFormat(redirectsFile);
183-
redirects.push(...success);
180+
)
181+
const {parseRedirectsFormat} = require('netlify-redirect-parser')
182+
const {success} = await parseRedirectsFormat(redirectsFile)
183+
redirects.push(...success)
184184
}
185185

186186
if (netlifyToml.redirects) {
187187
console.log(
188188
"Found redirect rules in netlify.toml. We will rewrite rules that redirect (200 rewrites) to '/.netlify/functions/*'."
189-
);
190-
redirects.push(...netlifyToml.redirects);
189+
)
190+
redirects.push(...netlifyToml.redirects)
191191
}
192192

193193
for (const redirect of redirects) {
@@ -196,38 +196,38 @@ module.exports = {
196196
redirect.to &&
197197
redirect.to.startsWith('/.netlify/functions/')
198198
) {
199-
const redirectPath = redirect.to.split('/.netlify/functions/')[1];
199+
const redirectPath = redirect.to.split('/.netlify/functions/')[1]
200200
redirectRules.push(
201201
`${redirect.from} https://apigcp.nimbella.io/api/v1/web/${namespace}/default/${redirectPath} 200!`
202-
);
202+
)
203203
}
204204
}
205205
}
206206

207-
let {path: redirectPath} = inputs;
207+
let {path: redirectPath} = inputs
208208
redirectPath = redirectPath.endsWith('/')
209209
? redirectPath
210-
: redirectPath + '/';
210+
: redirectPath + '/'
211211

212212
if (isProject) {
213213
redirectRules.push(
214214
`${redirectPath}* https://apigcp.nimbella.io/api/v1/web/${namespace}/:splat 200!`
215-
);
215+
)
216216
}
217217

218218
if (isActions && !isProject) {
219219
redirectRules.push(
220220
`${redirectPath}* https://apigcp.nimbella.io/api/v1/web/${namespace}/default/:splat 200!`
221-
);
221+
)
222222
}
223223

224224
if (redirectRules.length > 0) {
225225
if (!existsSync(constants.PUBLISH_DIR)) {
226-
const mkdir = require('make-dir');
227-
await mkdir(constants.PUBLISH_DIR);
226+
const mkdir = require('make-dir')
227+
await mkdir(constants.PUBLISH_DIR)
228228
}
229229

230-
await appendFile(redirectsFile, redirectRules.join('\n'));
230+
await appendFile(redirectsFile, redirectRules.join('\n'))
231231
}
232232
}
233-
};
233+
}

0 commit comments

Comments
 (0)