Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zeit 2 support #1417

Merged
merged 1 commit into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
class Deployment extends Component {
componentDidMount = () => {
this.props.signals.deployment.getDeploys();
this.props.signals.deployment.getPeople();
};

render() {
Expand All @@ -33,9 +32,6 @@ class Deployment extends Component {
store: { user, deployment },
} = this.props;

const hasVoted = deployment.peopleWant2.find(
a => a.username === user.username
);
return (
<div>
<Description>
Expand All @@ -50,50 +46,6 @@ class Deployment extends Component {
{!user.integrations.zeit &&
' You need to add ZEIT to your integrations to deploy.'}
</Description>
<Description
css={`
margin: 0;
padding: 0.5rem 1rem;

background: #122d42;
`}
>
We currently only support Zeit v1.
{!hasVoted && deployment.peopleWant2.length ? (
<Fragment>
<br />
<br />
If you would like us to support version 2.0 too please add your
thumbs up
</Fragment>
) : null}
<Button
css={`
padding: 5px 8px;
margin-top: 1rem;
`}
block
disabled={hasVoted || !deployment.peopleWant2.length}
onClick={() =>
signals.deployment.addPersonFor2({
username: user.username,
})
}
>
{deployment.peopleWant2.length > 0
? `${deployment.peopleWant2.length} people want v2`
: null}{' '}
<span
css={`
margin-left: 5px;
`}
role="img"
aria-label="I want this"
>
👍
</span>
</Button>
</Description>

{user.integrations.zeit ? (
<Fragment>
Expand Down
77 changes: 16 additions & 61 deletions packages/app/src/app/store/modules/deployment/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,61 +13,6 @@ export function loadZip({ props, jsZip }) {
return jsZip.loadAsync(file).then(result => ({ contents: result }));
}

export async function getPeopleWhoWant2() {
const Airtable = await import(/* webpackChunkName: 'airtable' */ '../../utils/setAirtable');

const base = await Airtable.default.base('apppgSmcJWwuXac6t');
const params = base('zeit2').select({
view: 'Grid view',
maxRecords: 100000,
});
const people = [];

const getPeople = () =>
new Promise(res => {
params.eachPage(
(records, fetchNextPage) => {
records.forEach(record => {
people.push(record);
});
fetchNextPage();
},
() => res()
);
});

await getPeople();

return {
people: people.map(a => a.fields),
};
}

export async function addPersonWhoWant2({ path, props }) {
const Airtable = await import(/* webpackChunkName: 'airtable' */ '../../utils/setAirtable');

const base = await Airtable.default.base('apppgSmcJWwuXac6t');

const AddPerson = () =>
new Promise((res, rej) => {
base('zeit2').create({ username: props.username }, err => {
if (err) {
console.error(err);
rej();
}
res();
});
});

try {
await AddPerson();

return path.success();
} catch (e) {
return path.error();
}
}

export async function createApiData({ props, state }) {
const { contents } = props;
const sandboxId = state.get('editor.currentId');
Expand Down Expand Up @@ -101,13 +46,12 @@ export async function createApiData({ props, state }) {

const nowDefaults = {
name: `csb-${sandbox.id}`,
type: 'NPM',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was removed because it's actually the default now 1 uses and it was ruining version 2

public: true,
};

const filePaths = nowJSON.files || Object.keys(contents.files);

// We'll omit the homepage-value from package.json as it creates wrong assumptions over the now deployment evironment.
// We'll omit the homepage-value from package.json as it creates wrong assumptions over the now deployment environment.
packageJSON = omit(packageJSON, 'homepage');

// We force the sandbox id, so ZEIT will always group the deployments to a
Expand All @@ -117,8 +61,16 @@ export async function createApiData({ props, state }) {
apiData.name = nowJSON.name || nowDefaults.name;
apiData.deploymentType = nowJSON.type || nowDefaults.type;
apiData.public = nowJSON.public || nowDefaults.public;
apiData.config = omit(nowJSON, ['public', 'type', 'name', 'files']);
apiData.forceNew = true;

// if now v2 we need to tell now the version, builds and routes
if (nowJSON.version === 2) {
apiData.version = 2;
apiData.builds = nowJSON.builds;
apiData.routes = nowJSON.routes;
} else {
apiData.config = omit(nowJSON, ['public', 'type', 'name', 'files']);
apiData.forceNew = true;
}

if (!nowJSON.files) {
apiData.files.push({
Expand All @@ -138,7 +90,9 @@ export async function createApiData({ props, state }) {
}
}

if (template.alterDeploymentData) {
// this adds unnecessary code for version 2
// packages/common/templates/template.js
if (template.alterDeploymentData && nowJSON.version !== 2) {
apiData = template.alterDeploymentData(apiData);
}

Expand Down Expand Up @@ -167,10 +121,11 @@ export async function aliasDeployment({ http, path, props, state }) {
export async function postToZeit({ http, path, props, state }) {
const { apiData } = props;
const token = state.get('user.integrations.zeit.token');
const deploymentVersion = apiData.version === 2 ? 'v6' : 'v3';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very smart!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what my momma says


try {
const deployment = await http.request({
url: 'https://api.zeit.co/v3/now/deployments',
url: `https://api.zeit.co/${deploymentVersion}/now/deployments?forceNew=1`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In now 2 force new is passed like this and version 1 ignores it so yay

body: apiData,
method: 'POST',
headers: { Authorization: `bearer ${token}` },
Expand Down
3 changes: 0 additions & 3 deletions packages/app/src/app/store/modules/deployment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import * as sequences from './sequences';
export default Module({
model,
state: {
peopleWant2: [],
hasAlias: false,
deployToDelete: null,
deploying: false,
Expand All @@ -15,12 +14,10 @@ export default Module({
},
signals: {
getDeploys: sequences.getDeploys,
addPersonFor2: sequences.addPersonFor2,
deployClicked: sequences.deploy,
deploySandboxClicked: sequences.openDeployModal,
setDeploymentToDelete: sequences.deploymentToDelete,
deleteDeployment: sequences.deleteDeployment,
aliasDeployment: sequences.aliasDeployment,
getPeople: sequences.getPeopleWhoWant2,
},
});
7 changes: 1 addition & 6 deletions packages/app/src/app/store/modules/deployment/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,10 @@ const Deploy = types.model('Deploy', {
alias: types.maybeNull(types.array(Alias)),
scale: types.maybeNull(Scale),
creator: Creator,
type: types.enumeration('types', ['NPM', 'DOCKER', 'STATIC']),
});

const People = types.model('Person', {
username: types.maybeNull(types.string),
type: types.enumeration('types', ['NPM', 'DOCKER', 'STATIC', 'LAMBDAS']),
});

export default {
peopleWant2: types.array(People),
hasAlias: types.boolean,
deployToDelete: types.maybeNull(types.string),
deploying: types.boolean,
Expand Down
24 changes: 0 additions & 24 deletions packages/app/src/app/store/modules/deployment/sequences.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,6 @@ export const deploymentToDelete = [
set(state`deployment.deployToDelete`, props`id`),
];

export const getPeopleWhoWant2 = [
actions.getPeopleWhoWant2,
set(state`deployment.peopleWant2`, props`people`),
];

export const addPersonFor2 = [
actions.addPersonWhoWant2,
{
success: [
actions.getPeopleWhoWant2,
set(state`deployment.peopleWant2`, props`people`),
addNotification('Your feedback has been saved', 'success'),
],
error: [
addNotification(
'An unknown error occurred when adding your vote',
'error'
),
],
},
actions.getPeopleWhoWant2,
set(state`deployment.peopleWant2`, props`people`),
];

export const getDeploys = [
actions.getDeploymentData,
actions.getDeploymentData,
Expand Down
9 changes: 1 addition & 8 deletions packages/common/templates/configuration/now/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@ const config: ConfigurationFile = {
description: 'Configuration for your deployments on now.',
moreInfoUrl: 'https://zeit.co/docs/features/configuration',

getDefaultCode: () =>
JSON.stringify(
{
type: 'NPM',
},
null,
2
),
getDefaultCode: () => JSON.stringify({}, null, 2),
};

export default config;
2 changes: 1 addition & 1 deletion packages/common/templates/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ export default class Template {
serve: '^10.1.1',
},
scripts: {
...parsedFile.scripts,
'now-start': `cd ${this.distDir} && serve -s ./`,
...parsedFile.scripts,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was moved because I may want to override your now-start

},
};

Expand Down