Skip to content

Commit 73a650b

Browse files
authored
Use nim as a dependency and fix cross-platform issue (#24)
* fix: use homedir() for cross-platform compatibility Closes #19 * fix: use nim as a dependency Closes #21
1 parent 2969462 commit 73a650b

File tree

3 files changed

+2272
-61
lines changed

3 files changed

+2272
-61
lines changed

index.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
const {existsSync} = require('fs');
2-
const {appendFile, readFile, readdir, writeFile} = require('fs').promises;
2+
const {appendFile, readFile, readdir} = require('fs').promises;
33
const {join} = require('path');
44
const toml = require('@iarna/toml');
55
const cpx = require('cpx');
66
const build = require('netlify-lambda/lib/build');
77

8-
const NIM_CLI = 'https://apigcp.nimbella.io/downloads/nim/nimbella-cli.tgz';
98
const functionsBuildDir = `functions-build-${Date.now()}`;
109
let netlifyToml = {};
1110
let isProject = false;
@@ -25,7 +24,7 @@ process.env.NIM_DISABLE_AUTOUPDATE = '1';
2524
* @param {*} run - function provided under utils by Netlify to build event functions.
2625
*/
2726
async function deployProject(run) {
28-
await run.command(`nim project deploy . --exclude=web`);
27+
await run.command(`npx nim project deploy . --exclude=web`);
2928
}
3029

3130
/**
@@ -38,7 +37,7 @@ async function deployActions({run, functionsDir, timeout, memory}) {
3837
for (const file of files) {
3938
const [actionName, extension] = file.split('.');
4039
let command =
41-
`nim action update ${actionName} ${join(functionsDir, file)} ` +
40+
`npx nim action update ${actionName} ${join(functionsDir, file)} ` +
4241
`--timeout=${Number(timeout)} --memory=${Number(memory)} ` +
4342
`--web=raw `;
4443

@@ -71,20 +70,17 @@ module.exports = {
7170
);
7271
}
7372

74-
console.log('Installing nimbella cli...');
75-
await utils.run.command(`npm i -g ${NIM_CLI}`);
76-
77-
const nimConfig = join(process.env.HOME, '.nimbella');
73+
const nimConfig = join(require('os').homedir(), '.nimbella');
7874
await utils.cache.restore(nimConfig);
7975

8076
const loggedIn = existsSync(nimConfig);
8177
// Login if not logged in before.
8278
if (loggedIn) {
8379
console.log('\nUsing the following namespace.');
84-
await utils.run.command('nim auth current');
80+
await utils.run.command('npx nim auth current');
8581
} else {
8682
await utils.run.command(
87-
`nim auth login ${process.env.NIMBELLA_LOGIN_TOKEN}`
83+
`npx nim auth login ${process.env.NIMBELLA_LOGIN_TOKEN}`
8884
);
8985

9086
// Cache the nimbella config to avoid logging in for consecutive builds.
@@ -122,7 +118,9 @@ module.exports = {
122118
// Execute after build is done.
123119
onPostBuild: async ({constants, utils}) => {
124120
try {
125-
const {stdout: namespace} = await utils.run.command(`nim auth current`);
121+
const {stdout: namespace} = await utils.run.command(
122+
`npx nim auth current`
123+
);
126124

127125
if (process.env.CONTEXT === 'production') {
128126
if (isProject) {
@@ -165,13 +163,14 @@ module.exports = {
165163
}
166164

167165
for (const redirect of redirects) {
168-
if (redirect.status === 200) {
169-
if (redirect.to.startsWith('/.netlify/functions/')) {
170-
const redirectPath = redirect.to.split('/.netlify/functions/')[1];
171-
redirectRules.push(
172-
`${redirect.from} https://apigcp.nimbella.io/api/v1/web/${namespace}/default/${redirectPath} 200!`
173-
);
174-
}
166+
if (
167+
redirect.status === 200 &&
168+
redirect.to.startsWith('/.netlify/functions/')
169+
) {
170+
const redirectPath = redirect.to.split('/.netlify/functions/')[1];
171+
redirectRules.push(
172+
`${redirect.from} https://apigcp.nimbella.io/api/v1/web/${namespace}/default/${redirectPath} 200!`
173+
);
175174
}
176175
}
177176
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"@iarna/toml": "^2.2.5",
3030
"cpx": "^1.5.0",
3131
"netlify-lambda": "satyarohith/netlify-lambda#master",
32-
"netlify-redirect-parser": "^2.5.0"
32+
"netlify-redirect-parser": "^2.5.0",
33+
"nimbella-cli": "https://apigcp.nimbella.io/downloads/nim/nim-v1.8.0/nim-v1.8.0.tar.gz"
3334
},
3435
"xo": {
3536
"space": true,

0 commit comments

Comments
 (0)