From b75e33e6252935a34e3c906dae31d8988e6352ea Mon Sep 17 00:00:00 2001 From: Yusuke Wada Date: Thu, 28 Mar 2024 23:08:41 +0900 Subject: [PATCH] fix: don't use GitHub API --- src/github.ts | 49 ------------------------------------------------- src/index.ts | 17 +++++++++++++++-- 2 files changed, 15 insertions(+), 51 deletions(-) delete mode 100644 src/github.ts diff --git a/src/github.ts b/src/github.ts deleted file mode 100644 index 9333dd1..0000000 --- a/src/github.ts +++ /dev/null @@ -1,49 +0,0 @@ -import fetch from 'node-fetch' - -const api = async (endpoint: string) => { - const response = await fetch(`https://api.github.com/repos/${endpoint}`) - const contents = (await response.json()) as - | { message: string } - | { type: string; path: string }[] - return contents -} - -type Options = { - user: string - repository: string - ref: string - directory: string -} - -export const viaContentsApi = async ({ - user, - repository, - ref = 'HEAD', - directory, -}: Options) => { - const files = [] - const contents = await api( - `${user}/${repository}/contents/${directory}?ref=${ref}`, - ) - - if ('message' in contents) { - if (contents.message === 'Not Found') { - return [] - } - if (contents.message) { - throw new Error(contents.message) - } - } - - if (Array.isArray(contents)) { - for (const item of contents) { - if (item.type === 'file') { - files.push(item.path) - } else if (item.type === 'dir') { - files.push(item.path) - } - } - } - - return files -} diff --git a/src/index.ts b/src/index.ts index 7178bc6..8c1a2e1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,6 @@ import prompts from 'prompts' import tiged from 'tiged' import yargsParser from 'yargs-parser' import { version } from '../package.json' -import { viaContentsApi } from './github.js' import { projectDependenciesHook } from './hook' import { afterCreateHook } from './hooks/after-create' import { registerInstallationHook } from './hooks/dependencies' @@ -19,6 +18,21 @@ const config = { ref: 'main', } +const templateDirs = [ + 'templates/aws-lambda', + 'templates/bun', + 'templates/cloudflare-pages', + 'templates/cloudflare-workers', + 'templates/deno', + 'templates/fastly', + 'templates/lambda-edge', + 'templates/netlify', + 'templates/nextjs', + 'templates/nodejs', + 'templates/vercel', + 'templates/x-basic', +] + function mkdirp(dir: string) { try { fs.mkdirSync(dir, { recursive: true }) @@ -37,7 +51,6 @@ async function main() { const templateArg = args.template - const templateDirs = await viaContentsApi(config) const templates: Record = {} templateDirs.forEach((dir) => {