@@ -6,17 +6,15 @@ import path, { dirname, join, relative } from 'path'
66import process from 'process'
77import { fileURLToPath , pathToFileURL } from 'url'
88
9- import { confirm , input , search , select , Separator } from '@inquirer/prompts'
9+ import { input , search , select , Separator } from '@inquirer/prompts'
1010import { OptionValues } from 'commander'
1111import { findUp } from 'find-up'
1212import fuzzy from 'fuzzy'
1313import fetch from 'node-fetch'
1414import { createSpinner } from 'nanospinner'
1515
1616import { fileExistsAsync } from '../../lib/fs.js'
17- import { getAddons , getCurrentAddon , getSiteData } from '../../utils/addons/prepare.js'
1817import {
19- APIError ,
2018 NETLIFYDEVERR ,
2119 NETLIFYDEVLOG ,
2220 NETLIFYDEVWARN ,
@@ -406,10 +404,9 @@ const downloadFromURL = async function (command, options, argumentName, function
406404 const fnTemplateFile = path . join ( fnFolder , '.netlify-function-template.mjs' )
407405 if ( await fileExistsAsync ( fnTemplateFile ) ) {
408406 const {
409- default : { addons = [ ] , onComplete } ,
407+ default : { onComplete } ,
410408 } = await import ( pathToFileURL ( fnTemplateFile ) . href )
411409
412- await installAddons ( command , addons , path . resolve ( fnFolder ) )
413410 await handleOnComplete ( { command, onComplete } )
414411 // delete
415412 await unlink ( fnTemplateFile )
@@ -504,7 +501,7 @@ const scaffoldFromTemplate = async function (command, options, argumentName, fun
504501 } else if ( chosenTemplate === 'report' ) {
505502 log ( `${ NETLIFYDEVLOG } Open in browser: https://github.com/netlify/cli/issues/new` )
506503 } else {
507- const { addons = [ ] , lang, name : templateName , onComplete } = chosenTemplate
504+ const { lang, name : templateName , onComplete } = chosenTemplate
508505 const pathToTemplate = path . join ( templatesDir , lang , templateName )
509506 if ( ! fs . existsSync ( pathToTemplate ) ) {
510507 throw new Error (
@@ -551,7 +548,6 @@ const scaffoldFromTemplate = async function (command, options, argumentName, fun
551548 await registerEFInToml ( name , command . netlify )
552549 }
553550
554- await installAddons ( command , addons , path . resolve ( functionPath ) )
555551 await handleOnComplete ( { command, onComplete } )
556552
557553 log ( )
@@ -561,26 +557,6 @@ const scaffoldFromTemplate = async function (command, options, argumentName, fun
561557
562558const TEMPLATE_PERMISSIONS = 0o777
563559
564- // @ts -expect-error TS(7031) FIXME: Binding element 'addonName' implicitly has an 'any... Remove this comment to see the full error message
565- const createFunctionAddon = async function ( { addonName, addons, api, siteData, siteId } ) {
566- try {
567- const addon = getCurrentAddon ( { addons, addonName } )
568- if ( addon ?. id ) {
569- log ( `The "${ addonName } add-on" already exists for ${ siteData . name } ` )
570- return false
571- }
572- await api . createServiceInstance ( {
573- siteId,
574- addon : addonName ,
575- body : { config : { } } ,
576- } )
577- log ( `Add-on "${ addonName } " created for ${ siteData . name } ` )
578- return true
579- } catch ( error_ ) {
580- return logAndThrowError ( ( error_ as APIError ) . message )
581- }
582- }
583-
584560/**
585561 *
586562 * @param {object } config
@@ -601,81 +577,6 @@ const handleOnComplete = async ({ command, onComplete }) => {
601577 await onComplete . call ( command )
602578 }
603579}
604- /**
605- *
606- * @param {object } config
607- * @param {* } config.addonCreated
608- * @param {* } config.addonDidInstall
609- * @param {import('../base-command.js').default } config.command
610- * @param {string } config.fnPath
611- */
612- // @ts -expect-error TS(7031) FIXME: Binding element 'addonCreated' implicitly has an '... Remove this comment to see the full error message
613- const handleAddonDidInstall = async ( { addonCreated, addonDidInstall, command, fnPath } ) => {
614- const { config } = command . netlify
615-
616- if ( ! addonCreated || ! addonDidInstall ) {
617- return
618- }
619-
620- const confirmPostInstall = await confirm ( {
621- message : `This template has an optional setup script that runs after addon install. This can be helpful for first time users to try out templates. Run the script?` ,
622- default : false ,
623- } )
624-
625- if ( ! confirmPostInstall ) {
626- return
627- }
628-
629- await injectEnvVariables ( {
630- devConfig : { ...config . dev } ,
631- env : command . netlify . cachedConfig . env ,
632- site : command . netlify . site ,
633- } )
634- addonDidInstall ( fnPath )
635- }
636-
637- /**
638- *
639- * @param {import('../base-command.js').default } command
640- * @param {* } functionAddons
641- * @param {* } fnPath
642- * @returns
643- */
644- // @ts -expect-error TS(7006) FIXME: Parameter 'command' implicitly has an 'any' type.
645- const installAddons = async function ( command , functionAddons , fnPath ) {
646- if ( functionAddons . length === 0 ) {
647- return
648- }
649-
650- const { api, site } = command . netlify
651- const siteId = site . id
652- if ( ! siteId ) {
653- log ( 'No project id found, please run inside a project directory or `netlify link`' )
654- return false
655- }
656- log ( `${ NETLIFYDEVLOG } checking Netlify APIs...` )
657-
658- const [ siteData , siteAddons ] = await Promise . all ( [ getSiteData ( { api, siteId } ) , getAddons ( { api, siteId } ) ] )
659-
660- // @ts -expect-error TS(7031) FIXME: Binding element 'addonDidInstall' implicitly has a... Remove this comment to see the full error message
661- const arr = functionAddons . map ( async ( { addonDidInstall, addonName } ) => {
662- log ( `${ NETLIFYDEVLOG } installing addon: ${ chalk . yellow . inverse ( addonName ) } ` )
663- try {
664- const addonCreated = await createFunctionAddon ( {
665- api,
666- addons : siteAddons ,
667- siteId,
668- addonName,
669- siteData,
670- } )
671-
672- await handleAddonDidInstall ( { addonCreated, addonDidInstall, command, fnPath } )
673- } catch ( error_ ) {
674- return logAndThrowError ( `${ NETLIFYDEVERR } Error installing addon: ${ error_ } ` )
675- }
676- } )
677- return Promise . all ( arr )
678- }
679580
680581/**
681582 *
0 commit comments