1
1
const { existsSync} = require ( 'fs' ) ;
2
- const { appendFile, readFile, readdir, writeFile } = require ( 'fs' ) . promises ;
2
+ const { appendFile, readFile, readdir} = require ( 'fs' ) . promises ;
3
3
const { join} = require ( 'path' ) ;
4
4
const toml = require ( '@iarna/toml' ) ;
5
5
const cpx = require ( 'cpx' ) ;
6
6
const build = require ( 'netlify-lambda/lib/build' ) ;
7
7
8
- const NIM_CLI = 'https://apigcp.nimbella.io/downloads/nim/nimbella-cli.tgz' ;
9
8
const functionsBuildDir = `functions-build-${ Date . now ( ) } ` ;
10
9
let netlifyToml = { } ;
11
10
let isProject = false ;
@@ -25,7 +24,7 @@ process.env.NIM_DISABLE_AUTOUPDATE = '1';
25
24
* @param {* } run - function provided under utils by Netlify to build event functions.
26
25
*/
27
26
async function deployProject ( run ) {
28
- await run . command ( `nim project deploy . --exclude=web` ) ;
27
+ await run . command ( `npx nim project deploy . --exclude=web` ) ;
29
28
}
30
29
31
30
/**
@@ -38,7 +37,7 @@ async function deployActions({run, functionsDir, timeout, memory}) {
38
37
for ( const file of files ) {
39
38
const [ actionName , extension ] = file . split ( '.' ) ;
40
39
let command =
41
- `nim action update ${ actionName } ${ join ( functionsDir , file ) } ` +
40
+ `npx nim action update ${ actionName } ${ join ( functionsDir , file ) } ` +
42
41
`--timeout=${ Number ( timeout ) } --memory=${ Number ( memory ) } ` +
43
42
`--web=raw ` ;
44
43
@@ -71,20 +70,17 @@ module.exports = {
71
70
) ;
72
71
}
73
72
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' ) ;
78
74
await utils . cache . restore ( nimConfig ) ;
79
75
80
76
const loggedIn = existsSync ( nimConfig ) ;
81
77
// Login if not logged in before.
82
78
if ( loggedIn ) {
83
79
console . log ( '\nUsing the following namespace.' ) ;
84
- await utils . run . command ( 'nim auth current' ) ;
80
+ await utils . run . command ( 'npx nim auth current' ) ;
85
81
} else {
86
82
await utils . run . command (
87
- `nim auth login ${ process . env . NIMBELLA_LOGIN_TOKEN } `
83
+ `npx nim auth login ${ process . env . NIMBELLA_LOGIN_TOKEN } `
88
84
) ;
89
85
90
86
// Cache the nimbella config to avoid logging in for consecutive builds.
@@ -122,7 +118,9 @@ module.exports = {
122
118
// Execute after build is done.
123
119
onPostBuild : async ( { constants, utils} ) => {
124
120
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
+ ) ;
126
124
127
125
if ( process . env . CONTEXT === 'production' ) {
128
126
if ( isProject ) {
@@ -165,13 +163,14 @@ module.exports = {
165
163
}
166
164
167
165
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
+ ) ;
175
174
}
176
175
}
177
176
}
0 commit comments