From 395f7b51e8c956174c51712cc4c4c179a40d5b44 Mon Sep 17 00:00:00 2001 From: Jens Neuse Date: Wed, 9 Jul 2025 21:09:47 +0200 Subject: [PATCH 01/10] feat(cli): add wgc grpc-service list-templates & init --- cli/package.json | 3 + .../commands/grpc-service/commands/init.ts | 87 +++++++++++++++++ .../grpc-service/commands/list-templates.ts | 39 ++++++++ cli/src/commands/grpc-service/index.ts | 4 + pnpm-lock.yaml | 94 ++++++++++++++----- 5 files changed, 202 insertions(+), 25 deletions(-) create mode 100644 cli/src/commands/grpc-service/commands/init.ts create mode 100644 cli/src/commands/grpc-service/commands/list-templates.ts diff --git a/cli/package.json b/cli/package.json index 622df4ccea..ad0cd90545 100644 --- a/cli/package.json +++ b/cli/package.json @@ -54,6 +54,7 @@ "commander": "^11.1.0", "date-fns": "^3.6.0", "decompress": "^4.2.1", + "degit": "^2.8.4", "dotenv": "^16.6.0", "env-ci": "^11.1.0", "env-paths": "^3.0.0", @@ -65,6 +66,7 @@ "jwt-decode": "^3.1.2", "lodash-es": "4.17.21", "log-symbols": "^5.1.0", + "node-fetch": "^3.3.2", "octokit": "^4.1.3", "open": "^9.1.0", "ora": "^8.2.0", @@ -83,6 +85,7 @@ "@types/cli-progress": "^3.11.5", "@types/cli-table": "^0.3.1", "@types/decompress": "^4.2.7", + "@types/degit": "^2.8.6", "@types/env-ci": "^3.1.4", "@types/inquirer": "^9.0.3", "@types/js-yaml": "^4.0.5", diff --git a/cli/src/commands/grpc-service/commands/init.ts b/cli/src/commands/grpc-service/commands/init.ts new file mode 100644 index 0000000000..98e8b6a020 --- /dev/null +++ b/cli/src/commands/grpc-service/commands/init.ts @@ -0,0 +1,87 @@ +import { existsSync, readdirSync } from 'node:fs'; +import { mkdir } from 'node:fs/promises'; +import { Command, program } from 'commander'; +import { resolve } from 'pathe'; +import Spinner from 'ora'; +import degit from 'degit'; +import pc from 'picocolors'; +import fetch from 'node-fetch'; +import { BaseCommandOptions } from '../../../core/types/types.js'; +import { fetchAvailableTemplates } from './list-templates.js'; + +async function checkTemplateExists(template: string): Promise { + const url = `https://api.github.com/repos/wundergraph/cosmo-grpc-templates/contents/${template}`; + const res = await fetch(url, { headers: { Accept: 'application/vnd.github.v3+json' } }); + if (res.status === 200) { + const data: any = await res.json(); + return Array.isArray(data); // Should be an array if it's a directory + } + return false; +} + +export default (opts: BaseCommandOptions) => { + const command = new Command('init'); + command.description('Scaffold a new gRPC service project from a template'); + command.option('-t, --template