@@ -12,6 +12,8 @@ const cp = require("child_process");
12
12
const { createAddon } = require ( "netlify/src/addons" ) ;
13
13
const ora = require ( "ora" ) ;
14
14
const { track } = require ( "@netlify/cli-utils/src/utils/telemetry" ) ;
15
+ const chalk = require ( "chalk" ) ;
16
+ const NETLIFYDEV = `[${ chalk . cyan ( "Netlify Dev" ) } ]` ;
15
17
16
18
const templatesDir = path . resolve ( __dirname , "../../functions-templates" ) ;
17
19
@@ -161,7 +163,6 @@ async function pickTemplate() {
161
163
const filteredTemplateNames = filteredTemplates . map ( x =>
162
164
input ? x . string : x
163
165
) ;
164
- // console.log({ filteredTemplateNames })
165
166
return registry
166
167
. filter ( t => filteredTemplateNames . includes ( t . name + t . description ) )
167
168
. map ( t => {
@@ -203,15 +204,17 @@ function ensureFunctionDirExists(flags, config) {
203
204
const functionsDir =
204
205
flags . functions || ( config . build && config . build . functions ) ;
205
206
if ( ! functionsDir ) {
206
- this . log ( "No functions folder specified in netlify.toml or as an argument" ) ;
207
+ this . log (
208
+ `${ NETLIFYDEV } No functions folder specified in netlify.toml or as an argument`
209
+ ) ;
207
210
process . exit ( 1 ) ;
208
211
}
209
212
if ( ! fs . existsSync ( functionsDir ) ) {
210
213
this . log (
211
- `functions folder ${ functionsDir } specified in netlify.toml but folder not found, creating it...`
214
+ `${ NETLIFYDEV } functions folder ${ functionsDir } specified in netlify.toml but folder not found, creating it...`
212
215
) ;
213
216
fs . mkdirSync ( functionsDir ) ;
214
- this . log ( `functions folder ${ functionsDir } created` ) ;
217
+ this . log ( `${ NETLIFYDEV } functions folder ${ functionsDir } created` ) ;
215
218
}
216
219
return functionsDir ;
217
220
}
@@ -227,7 +230,7 @@ async function downloadFromURL(flags, args, functionsDir) {
227
230
fs . lstatSync ( fnFolder + ".js" ) . isFile ( )
228
231
) {
229
232
this . log (
230
- `A single file version of the function ${ name } already exists at ${ fnFolder } .js`
233
+ `${ NETLIFYDEV } Warning: A single file version of the function ${ name } already exists at ${ fnFolder } .js. Terminating without further action. `
231
234
) ;
232
235
process . exit ( 1 ) ;
233
236
}
@@ -254,9 +257,11 @@ async function downloadFromURL(flags, args, functionsDir) {
254
257
} )
255
258
) ;
256
259
257
- this . log ( `installing dependencies for ${ nameToUse } ...` ) ;
260
+ this . log ( `${ NETLIFYDEV } Installing dependencies for ${ nameToUse } ...` ) ;
258
261
cp . exec ( "npm i" , { cwd : path . join ( functionsDir , nameToUse ) } , ( ) => {
259
- this . log ( `installing dependencies for ${ nameToUse } complete ` ) ;
262
+ this . log (
263
+ `${ NETLIFYDEV } Installing dependencies for ${ nameToUse } complete `
264
+ ) ;
260
265
} ) ;
261
266
262
267
// read, execute, and delete function template file if exists
@@ -296,16 +301,13 @@ async function scaffoldFromTemplate(flags, args, functionsDir) {
296
301
try {
297
302
await downloadFromURL . call ( this , flags , args , functionsDir ) ;
298
303
} catch ( err ) {
299
- console . error ( " Error downloading from URL: " + flags . url ) ;
304
+ console . error ( ` ${ NETLIFYDEV } Error downloading from URL: ` + flags . url ) ;
300
305
console . error ( err ) ;
301
306
process . exit ( 1 ) ;
302
307
}
303
308
} else if ( chosentemplate === "report" ) {
304
309
console . log (
305
- "opening in browser: https://github.com/netlify/netlify-dev-plugin/issues/new"
306
- ) ;
307
- require ( "../../utils/openBrowser.js" ) (
308
- "https://github.com/netlify/netlify-dev-plugin/issues/new"
310
+ `${ NETLIFYDEV } Open in browser: https://github.com/netlify/netlify-dev-plugin/issues/new`
309
311
) ;
310
312
} else {
311
313
const {
@@ -323,7 +325,7 @@ async function scaffoldFromTemplate(flags, args, functionsDir) {
323
325
}
324
326
325
327
const name = await getNameFromArgs ( args , flags , templateName ) ;
326
- this . log ( `Creating function ${ name } ` ) ;
328
+ this . log ( `${ NETLIFYDEV } Creating function ${ name } ` ) ;
327
329
const functionPath = ensureFunctionPathIsOk . call (
328
330
this ,
329
331
functionsDir ,
@@ -338,7 +340,7 @@ async function scaffoldFromTemplate(flags, args, functionsDir) {
338
340
copy ( pathToTemplate , functionPath , vars , async ( err , createdFiles ) => {
339
341
if ( err ) throw err ;
340
342
createdFiles . forEach ( filePath => {
341
- this . log ( `Created ${ filePath } ` ) ;
343
+ this . log ( `${ NETLIFYDEV } Created ${ filePath } ` ) ;
342
344
require ( "fs" ) . chmodSync ( path . resolve ( filePath ) , 0o777 ) ;
343
345
if ( filePath . includes ( "package.json" ) ) hasPackageJSON = true ;
344
346
} ) ;
@@ -377,12 +379,12 @@ async function installAddons(addons = [], fnPath) {
377
379
) ;
378
380
return false ;
379
381
}
380
- console . log ( " checking Netlify APIs..." ) ;
382
+ console . log ( ` ${ NETLIFYDEV } checking Netlify APIs...` ) ;
381
383
382
384
return api . getSite ( { siteId } ) . then ( async siteData => {
383
- const accessToken = await this . authenticate ( ) ;
385
+ const accessToken = api . accessToken ;
384
386
const arr = addons . map ( ( { addonName, addonDidInstall } ) => {
385
- console . log ( " installing addon: " + addonName ) ;
387
+ console . log ( ` ${ NETLIFYDEV } installing addon: ` + addonName ) ;
386
388
// will prompt for configs if not supplied - we do not yet allow for addon configs supplied by `netlify functions:create` command and may never do so
387
389
return createSiteAddon (
388
390
accessToken ,
@@ -423,7 +425,9 @@ async function installAddons(addons = [], fnPath) {
423
425
function ensureFunctionPathIsOk ( functionsDir , flags , name ) {
424
426
const functionPath = path . join ( functionsDir , name ) ;
425
427
if ( fs . existsSync ( functionPath ) ) {
426
- this . log ( `Function ${ functionPath } already exists, cancelling...` ) ;
428
+ this . log (
429
+ `${ NETLIFYDEV } Function ${ functionPath } already exists, cancelling...`
430
+ ) ;
427
431
process . exit ( 1 ) ;
428
432
}
429
433
return functionPath ;
0 commit comments