Skip to content

Commit 01da61e

Browse files
authored
Add no config deployment for zeit (codesandbox#2279)
1 parent fd75741 commit 01da61e

File tree

3 files changed

+20
-65
lines changed

3 files changed

+20
-65
lines changed

packages/app/src/app/pages/Sandbox/Editor/Workspace/items/Deployment/Zeit/DeployButton/DeployButton.tsx

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,19 @@ import React from 'react';
33

44
import { DeploymentIntegration } from 'app/components/DeploymentIntegration';
55
import NowLogo from 'app/components/NowLogo';
6-
import { useSignals, useStore } from 'app/store';
6+
import { useSignals } from 'app/store';
77

88
import { DeployButtonContainer } from '../../elements';
99

10-
import { Overlay, CreateFile } from './elements';
11-
1210
type Props = {
1311
isOpen: boolean;
1412
toggle: () => void;
1513
};
14+
1615
export const DeployButton = observer<Props>(({ isOpen, toggle }) => {
1716
const {
18-
files,
1917
deployment: { deploySandboxClicked },
2018
} = useSignals();
21-
const { editor } = useStore();
22-
const nowFile = editor.currentSandbox.modules
23-
.toJSON()
24-
.filter(file => file.title === 'now.json');
25-
26-
const createFile = () => {
27-
files.moduleCreated({
28-
title: 'now.json',
29-
code: JSON.stringify({
30-
version: 2,
31-
}),
32-
});
33-
};
3419

3520
return (
3621
<DeployButtonContainer>
@@ -42,29 +27,6 @@ export const DeployButton = observer<Props>(({ isOpen, toggle }) => {
4227
open={isOpen}
4328
toggle={toggle}
4429
>
45-
{!nowFile.length && (
46-
<Overlay>
47-
It seems you don{"'"}t have{' '}
48-
<a
49-
href="https://zeit.co/docs/v2/deployments/configuration"
50-
target="_blank"
51-
rel="noreferrer noopener"
52-
>
53-
now.json
54-
</a>{' '}
55-
file. Please create{' '}
56-
<CreateFile onClick={createFile}>one</CreateFile> to be able to
57-
deploy to{' '}
58-
<a
59-
href="https://zeit.co/now"
60-
target="_blank"
61-
rel="noreferrer noopener"
62-
>
63-
<span>ZEIT Now</span>
64-
</a>
65-
.
66-
</Overlay>
67-
)}
6830
Deploy your sandbox on{' '}
6931
<a href="https://zeit.co/now" rel="noreferrer noopener" target="_blank">
7032
<span>ZEIT Now</span>

packages/app/src/app/pages/Sandbox/Editor/Workspace/items/Deployment/Zeit/DeployButton/elements.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/app/src/app/store/modules/deployment/actions.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,24 @@ export async function createApiData({ props, state }) {
173173
apiData.deploymentType = nowJSON.type || nowDefaults.type;
174174
apiData.public = nowJSON.public || nowDefaults.public;
175175

176-
// if now v2 we need to tell now the version, builds and routes
177-
if (nowJSON.version === 2) {
176+
// if now v 1we need to tell now the version, builds and routes
177+
if (nowJSON.version === 1) {
178+
apiData.config = omit(nowJSON, [
179+
'public',
180+
'type',
181+
'name',
182+
'files',
183+
'version',
184+
]);
185+
apiData.forceNew = true;
186+
} else {
178187
apiData.version = 2;
179188
apiData.builds = nowJSON.builds;
180189
apiData.routes = nowJSON.routes;
181190
apiData.env = nowJSON.env;
182191
apiData.scope = nowJSON.scope;
183192
apiData['build.env'] = nowJSON['build.env'];
184193
apiData.regions = nowJSON.regions;
185-
} else {
186-
apiData.config = omit(nowJSON, ['public', 'type', 'name', 'files']);
187-
apiData.forceNew = true;
188194
}
189195

190196
if (!nowJSON.files) {
@@ -233,7 +239,9 @@ export async function aliasDeployment({ http, path, props, state }) {
233239
url: `https://api.zeit.co/v2/now/deployments/${id}/aliases`,
234240
body: { alias: nowData.alias },
235241
method: 'POST',
236-
headers: { Authorization: `bearer ${token}` },
242+
headers: {
243+
Authorization: `bearer ${token}`,
244+
},
237245
});
238246
const url = `https://${alias.result.alias}`;
239247

@@ -247,7 +255,7 @@ export async function aliasDeployment({ http, path, props, state }) {
247255
export async function postToZeit({ http, path, props, state }) {
248256
const { apiData } = props;
249257
const token = state.get('user.integrations.zeit.token');
250-
const deploymentVersion = apiData.version === 2 ? 'v6' : 'v3';
258+
const deploymentVersion = apiData.version === 2 ? 'v9' : 'v3';
251259

252260
try {
253261
const deployment = await http.request({
@@ -287,7 +295,7 @@ export function getDeploymentData({ state }) {
287295
async function deploysByID(id, token, http) {
288296
try {
289297
const data = await http.request({
290-
url: `https://api.zeit.co/v3/now/deployments/${id}/aliases`,
298+
url: `https://api.zeit.co/v2/now/deployments/${id}/aliases`,
291299
method: 'GET',
292300
headers: { Authorization: `bearer ${token}` },
293301
});
@@ -305,7 +313,7 @@ export async function getDeploys({ http, path, state, props }) {
305313

306314
try {
307315
const data = await http.request({
308-
url: 'https://api.zeit.co/v3/now/deployments',
316+
url: 'https://api.zeit.co/v4/now/deployments',
309317
method: 'GET',
310318
headers: { Authorization: `bearer ${token}` },
311319
});
@@ -343,7 +351,7 @@ export async function deleteDeployment({ http, path, state }) {
343351

344352
try {
345353
await http.request({
346-
url: `https://api.zeit.co/v2/now/deployments/${id}`,
354+
url: `https://api.zeit.co/v9/now/deployments/${id}`,
347355
method: 'DELETE',
348356
headers: { Authorization: `bearer ${token}` },
349357
});

0 commit comments

Comments
 (0)