Files
vercel/api/examples/list.ts
Andy 2db627b79d Adds manifest.json to examples folder (#3536)
* Revert "Revert "[examples] Add manifest.json""

This reverts commit c65336e63b.

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

This reverts commit ac72e944a7.

* 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>
2020-01-10 00:14:51 +01:00

40 lines
1.2 KiB
TypeScript

import { extract } from '../_lib/examples/extract';
import { summary } from '../_lib/examples/summary';
import { NowRequest, NowResponse } from '@now/node';
import { mapOldToNew } from '../_lib/examples/map-old-to-new';
import { withApiHandler } from '../_lib/util/with-api-handler';
export default withApiHandler(async function(
req: NowRequest,
res: NowResponse
) {
if (Number(req.query.version) === 1) {
// The old cli is pinned to a specific commit hash
await extract(
'https://github.com/zeit/now-examples/archive/7c7b27e49b8b17d0d3f0e1604dc74fd005cd69e3.zip',
'/tmp'
);
const exampleList = summary(
'/tmp/now-examples-7c7b27e49b8b17d0d3f0e1604dc74fd005cd69e3'
);
return res.send(exampleList);
}
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,
visible: true,
suggestions: [],
}));
const oldExamples = Object.keys(mapOldToNew).map(key => ({
name: key,
visible: false,
suggestions: mapOldToNew[key],
}));
res.status(200).json([...existingExamples, ...oldExamples]);
});