Skip to content

Commit 81c36ce

Browse files
committed
https://github.com/haxtheweb/issues/issues/2197
1 parent 942cf6b commit 81c36ce

File tree

4 files changed

+184
-0
lines changed

4 files changed

+184
-0
lines changed

examples.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,30 @@ Publish site to surge.sh, setting the domain to be `my-cool-blog.surge.sh`
150150
```bash
151151
hax site site:surge --domain my-cool-blog.surge.sh
152152
```
153+
Publish site to Netlify, interactively
154+
```bash
155+
hax site site:netlify
156+
```
157+
Publish site to Netlify, automated deployment
158+
```bash
159+
hax site site:netlify --y
160+
```
161+
Publish site to Netlify, setting the site ID to deploy to an existing site
162+
```bash
163+
hax site site:netlify --domain my-site-id --y
164+
```
165+
Publish site to Vercel, interactively
166+
```bash
167+
hax site site:vercel
168+
```
169+
Publish site to Vercel, automated deployment
170+
```bash
171+
hax site site:vercel --y
172+
```
173+
Publish site to Vercel, setting the project name
174+
```bash
175+
hax site site:vercel --domain my-project-name --y
176+
```
153177
Print out the recipe used in building the current site
154178
```bash
155179
hax site recipe:read

src/lib/programs/site.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
3953
const siteRecipeFile = 'create-cli.recipe';
4054
const siteLoggingName = 'cli';
4155
const 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')) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Local files
2+
.DS_Store
3+
Thumbs.db
4+
5+
# Logs
6+
logs
7+
*.log
8+
9+
# Dependencies (usually handled by build process)
10+
!node_modules/
11+
12+
# Development files
13+
.env.local
14+
.env.development.local
15+
.env.test.local
16+
.env.production.local
17+
18+
# IDE files
19+
.vscode/
20+
.idea/
21+
22+
# Build artifacts (if not using for deployment)
23+
# dist/
24+
# build/
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Local files
2+
.DS_Store
3+
Thumbs.db
4+
5+
# Logs
6+
logs
7+
*.log
8+
npm-debug.log*
9+
yarn-debug.log*
10+
yarn-error.log*
11+
12+
# Dependencies (handled by Vercel build process)
13+
!node_modules/
14+
15+
# Development files
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
# IDE files
22+
.vscode/
23+
.idea/
24+
25+
# Version control
26+
.git/
27+
28+
# Build artifacts (if not needed for deployment)
29+
# dist/
30+
# build/
31+
32+
# Cache directories
33+
.cache/
34+
.tmp/

0 commit comments

Comments
 (0)