Skip to content

Commit

Permalink
Adds manifest.json to examples folder (#3536)
Browse files Browse the repository at this point in the history
* Revert "Revert "[examples] Add manifest.json""

This reverts commit c65336e.

* Revert "Revert "Do not use now-examples anymore""

This reverts commit ac72e94.

* Update nowignore

* Fix join

* Fix JSON

* Fix header

* Replace manifest.json with @now/frameworks

* Adjust readmes

* Adjust .nowignore

* Update scully

* Fix description

* Update examples/create-react-app/src/App.js

Co-Authored-By: Shu Ding <ds303077135@gmail.com>

* Update readme

* Add websites

* Use https

* Adjust example URL

* Change order

Co-authored-by: Shu Ding <ds303077135@gmail.com>
  • Loading branch information
AndyBitz and shuding committed Jan 9, 2020
1 parent 7064f4e commit 2db627b
Show file tree
Hide file tree
Showing 91 changed files with 9,365 additions and 562 deletions.
40 changes: 22 additions & 18 deletions api/_lib/examples/example-list.ts
@@ -1,21 +1,25 @@
// Currently we read & parse the README file from zeit/now-examples
// TODO: create a `manifest.json` for zeit/now-examples
import Frameworks, { Framework } from '../../../packages/frameworks';

import fetch from 'node-fetch';

/**
* Fetch and parse the `Frameworks and Libraries` table
* in the README file of zeit/now-examples
*/
export async function getExampleList() {
const response = await fetch(
`https://raw.githubusercontent.com/zeit/now-examples/master/manifest.json`
);

if (response.status !== 200) {
console.log('manifest.json missing in zeit/now-examples');
return null;
}
interface Example {
example: string;
path: string;
demo: string;
description: string;
tagline: string;
framework: string;
}

return response.json();
export async function getExampleList(): Promise<Example[]> {
return (Frameworks as Framework[])
.filter(f => f.demo)
.map(framework => {
return {
example: framework.name,
path: `/${framework.slug}`,
demo: framework.demo,
description: framework.description,
tagline: framework.tagline,
framework: framework.slug,
};
});
}
9 changes: 5 additions & 4 deletions api/_lib/examples/github-repo-info.ts
Expand Up @@ -10,9 +10,9 @@ export async function getGitHubRepoInfo(repo: Repo) {
const response = await fetch(`https://api.github.com/repos/${repo.repo}`, {
headers: {
Accept: 'application/vnd.github.machine-man-preview+json',
// If we don't use a personal access token,
// If we don't use a personal access token,
// it will get rate limited very easily.
Authorization: `Bearer ${process.env.GITHUB_ACCESS_TOKEN}`
Authorization: `Bearer ${process.env.GITHUB_ACCESS_TOKEN}`,
},
});

Expand Down Expand Up @@ -51,7 +51,9 @@ export async function getGitHubRepoInfo(repo: Repo) {
data.subdir = repo.path.slice(subdirPath.length).split('/');
}

if (data.id === 'zeit/now-examples' && data.subdir) {
const isExamples = data.id === 'zeit/now-examples' || data.id === 'zeit/now';

if (isExamples && data.subdir) {
// from our examples, add `homepage` and `description` fields
const example = data.subdir[0];
const exampleList = await getExampleList();
Expand All @@ -61,7 +63,6 @@ export async function getGitHubRepoInfo(repo: Repo) {
data.homepage = item.demo;
data.description = item.description;
data.exampleName = item.example;
data.icon = item.icon;
data.tagline = item.tagline;
data.framework = item.framework;
return data;
Expand Down
1 change: 1 addition & 0 deletions api/_lib/examples/map-old-to-new.ts
Expand Up @@ -21,6 +21,7 @@ export const mapOldToNew: { [key: string]: string[] } = {
'nuxt-static': ['nuxtjs'],
static: ['vanilla'],
typescript: ['gatsby-functions'],
umi: ['umijs'],
'vanilla-go': ['vanilla-functions'],
'vanilla-json-api': ['svelte-functions'],
'vue-ssr': ['vue'],
Expand Down
10 changes: 2 additions & 8 deletions api/examples/download/[segment].ts
Expand Up @@ -51,14 +51,8 @@ export default withApiHandler(async function(req: NowRequest, res: NowResponse)
await extract('https://github.com/zeit/now-examples/archive/7c7b27e49b8b17d0d3f0e1604dc74fd005cd69e3.zip', TMP_DIR);
directory = `${TMP_DIR}/now-examples-7c7b27e49b8b17d0d3f0e1604dc74fd005cd69e3/${example}`;
} else {
await extract('https://github.com/zeit/now-examples/archive/master.zip', TMP_DIR);
directory = `${TMP_DIR}/now-examples-master/${example}`;

if (!isDirectory(directory)) {
// Use `now` instead of `now-examples` if the searched example does not exist
await extract('https://github.com/zeit/now/archive/master.zip', TMP_DIR);
directory = `${TMP_DIR}/now-master/examples/${example}`;
}
await extract('https://github.com/zeit/now/archive/master.zip', TMP_DIR);
directory = `${TMP_DIR}/now-master/examples/${example}`;
}

if (!isDirectory(directory)) {
Expand Down
11 changes: 2 additions & 9 deletions api/examples/list.ts
Expand Up @@ -20,15 +20,8 @@ export default withApiHandler(async function(
return res.send(exampleList);
}

await Promise.all([
extract('https://github.com/zeit/now/archive/master.zip', '/tmp'),
extract('https://github.com/zeit/now-examples/archive/master.zip', '/tmp'),
]);

const exampleList = new Set([
...summary('/tmp/now-master/examples'),
...summary('/tmp/now-examples-master'),
]);
await extract('https://github.com/zeit/now/archive/master.zip', '/tmp');
const exampleList = summary('/tmp/now-master/examples');

const existingExamples = Array.from(exampleList).map(key => ({
name: key,
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/README.md
@@ -1,4 +1,4 @@
![Angular Logo](../.github/images/angular.svg)
![Angular Logo](../packages/frameworks/logos/angular.svg)

# Angular Example

Expand Down
28 changes: 0 additions & 28 deletions examples/create-react-app-functions/.gitignore

This file was deleted.

29 changes: 0 additions & 29 deletions examples/create-react-app-functions/README.md

This file was deleted.

22 changes: 0 additions & 22 deletions examples/create-react-app-functions/package.json

This file was deleted.

44 changes: 0 additions & 44 deletions examples/create-react-app-functions/src/App.css

This file was deleted.

57 changes: 0 additions & 57 deletions examples/create-react-app-functions/src/App.js

This file was deleted.

9 changes: 0 additions & 9 deletions examples/create-react-app-functions/src/App.test.js

This file was deleted.

14 changes: 0 additions & 14 deletions examples/create-react-app-functions/src/index.css

This file was deleted.

12 changes: 0 additions & 12 deletions examples/create-react-app-functions/src/index.js

This file was deleted.

1 comment on commit 2db627b

@vercel
Copy link

@vercel vercel bot commented on 2db627b Jan 9, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.