@@ -36,6 +36,20 @@ exec('surge --version', error => {
3636 }
3737} ) ;
3838
39+ var sysNetlify = true ;
40+ exec ( 'netlify --version' , error => {
41+ if ( error ) {
42+ sysNetlify = false ;
43+ }
44+ } ) ;
45+
46+ var sysVercel = true ;
47+ exec ( 'vercel --version' , error => {
48+ if ( error ) {
49+ sysVercel = false ;
50+ }
51+ } ) ;
52+
3953const siteRecipeFile = 'create-cli.recipe' ;
4054const siteLoggingName = 'cli' ;
4155const logLevels = { } ;
@@ -86,6 +100,8 @@ export function siteActions() {
86100 { value : 'site:schema' , label : "Full site as HAXElementSchema" } ,
87101 { value : 'site:sync' , label : "Sync git repo" } ,
88102 { value : 'site:surge' , label : "Publish site to Surge.sh" } ,
103+ { value : 'site:netlify' , label : "Publish site to Netlify" } ,
104+ { value : 'site:vercel' , label : "Publish site to Vercel" } ,
89105 { value : 'recipe:read' , label : "Read recipe file" } ,
90106 { value : 'recipe:play' , label : "Play recipe file" } ,
91107 { value : 'issue:general' , label : "Issue: Submit an issue or suggestion" } ,
@@ -996,6 +1012,86 @@ export async function siteCommandDetected(commandRun) {
9961012 log ( e . stderr ) ;
9971013 }
9981014 break ;
1015+ case "site:netlify" :
1016+ try {
1017+ // attempt to install; implies they asked to publish with netlify but
1018+ // system test did not see it globally
1019+ if ( ! sysNetlify ) {
1020+ let s = p . spinner ( ) ;
1021+ s . start ( merlinSays ( 'Installing Netlify CLI globally so we can publish' ) ) ;
1022+ let execOutput = await exec ( `npm install --global netlify-cli` ) ;
1023+ s . stop ( merlinSays ( 'Netlify CLI installed globally' ) ) ;
1024+ log ( execOutput . stdout . trim ( ) ) ;
1025+ sysNetlify = true ;
1026+ }
1027+ let execOutput ;
1028+ if ( commandRun . options . y ) {
1029+ let s = p . spinner ( ) ;
1030+ s . start ( merlinSays ( 'Deploying site to Netlify ..' ) ) ;
1031+ if ( commandRun . options . domain ) {
1032+ // If specific site/domain is specified, deploy to existing site
1033+ execOutput = await exec ( `cd ${ activeHaxsite . directory } && netlify deploy --prod --site ${ commandRun . options . domain } ` ) ;
1034+ } else {
1035+ // Auto deploy - will create a new site or use existing site config
1036+ execOutput = await exec ( `cd ${ activeHaxsite . directory } && netlify deploy --prod` ) ;
1037+ }
1038+ log ( execOutput . stdout . trim ( ) ) ;
1039+ s . stop ( merlinSays ( `Site deployed to Netlify` ) ) ;
1040+ }
1041+ else {
1042+ let netlifyArgs = [ 'deploy' , '--prod' ] ;
1043+ if ( commandRun . options . domain ) {
1044+ netlifyArgs . push ( '--site' , commandRun . options . domain ) ;
1045+ }
1046+ execOutput = await interactiveExec ( 'netlify' , netlifyArgs , { cwd : activeHaxsite . directory } ) ;
1047+ log ( merlinSays ( `Site deployed to Netlify` ) ) ;
1048+ }
1049+ }
1050+ catch ( e ) {
1051+ console . log ( "?" ) ;
1052+ log ( e . stderr ) ;
1053+ }
1054+ break ;
1055+ case "site:vercel" :
1056+ try {
1057+ // attempt to install; implies they asked to publish with vercel but
1058+ // system test did not see it globally
1059+ if ( ! sysVercel ) {
1060+ let s = p . spinner ( ) ;
1061+ s . start ( merlinSays ( 'Installing Vercel CLI globally so we can publish' ) ) ;
1062+ let execOutput = await exec ( `npm install --global vercel` ) ;
1063+ s . stop ( merlinSays ( 'Vercel CLI installed globally' ) ) ;
1064+ log ( execOutput . stdout . trim ( ) ) ;
1065+ sysVercel = true ;
1066+ }
1067+ let execOutput ;
1068+ if ( commandRun . options . y ) {
1069+ let s = p . spinner ( ) ;
1070+ s . start ( merlinSays ( 'Deploying site to Vercel ..' ) ) ;
1071+ if ( commandRun . options . domain ) {
1072+ // Deploy with specific domain/project name
1073+ execOutput = await exec ( `cd ${ activeHaxsite . directory } && vercel --prod --name ${ commandRun . options . domain } ` ) ;
1074+ } else {
1075+ // Auto deploy with default settings
1076+ execOutput = await exec ( `cd ${ activeHaxsite . directory } && vercel --prod` ) ;
1077+ }
1078+ log ( execOutput . stdout . trim ( ) ) ;
1079+ s . stop ( merlinSays ( `Site deployed to Vercel` ) ) ;
1080+ }
1081+ else {
1082+ let vercelArgs = [ '--prod' ] ;
1083+ if ( commandRun . options . domain ) {
1084+ vercelArgs . push ( '--name' , commandRun . options . domain ) ;
1085+ }
1086+ execOutput = await interactiveExec ( 'vercel' , vercelArgs , { cwd : activeHaxsite . directory } ) ;
1087+ log ( merlinSays ( `Site deployed to Vercel` ) ) ;
1088+ }
1089+ }
1090+ catch ( e ) {
1091+ console . log ( "?" ) ;
1092+ log ( e . stderr ) ;
1093+ }
1094+ break ;
9991095 case "site:file-list" :
10001096 let res = new Res ( ) ;
10011097 await hax . RoutesMap . get . listFiles ( { query : activeHaxsite . name , filename : commandRun . options . filename } , res ) ;
@@ -1473,6 +1569,12 @@ export async function siteProcess(commandRun, project, port = '3000') { // au
14731569 if ( ! fs . existsSync ( `${ project . path } /${ project . name } /._surgeignore` ) ) {
14741570 await fs . copyFileSync ( `${ process . mainModule . path } /templates/sitedotfiles/_surgeignore` , `${ project . path } /${ project . name } /.surgeignore` ) ;
14751571 }
1572+ if ( ! fs . existsSync ( `${ project . path } /${ project . name } /.netlifyignore` ) ) {
1573+ await fs . copyFileSync ( `${ process . mainModule . path } /templates/sitedotfiles/_netlifyignore` , `${ project . path } /${ project . name } /.netlifyignore` ) ;
1574+ }
1575+ if ( ! fs . existsSync ( `${ project . path } /${ project . name } /.vercelignore` ) ) {
1576+ await fs . copyFileSync ( `${ process . mainModule . path } /templates/sitedotfiles/_vercelignore` , `${ project . path } /${ project . name } /.vercelignore` ) ;
1577+ }
14761578 // options for install, git and other extras
14771579 // can't launch if we didn't install first so launch implies installation
14781580 if ( project . extras && project . extras . includes && project . extras . includes ( 'launch' ) ) {
0 commit comments