From b366876527cd7df38f48e3f2ebd5e09cc1856fa0 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Sat, 16 Nov 2024 09:00:00 -0600 Subject: [PATCH 1/2] chore: remove docker command --- __tests__/cmds/docker-gha.test.ts | 52 ------------------------------- src/cmds/docker-gha.ts | 40 ------------------------ src/index.ts | 3 -- 3 files changed, 95 deletions(-) delete mode 100644 __tests__/cmds/docker-gha.test.ts delete mode 100644 src/cmds/docker-gha.ts diff --git a/__tests__/cmds/docker-gha.test.ts b/__tests__/cmds/docker-gha.test.ts deleted file mode 100644 index ee925100d..000000000 --- a/__tests__/cmds/docker-gha.test.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { describe, beforeEach, it, expect, vi } from 'vitest'; - -import Command from '../../src/cmds/docker-gha.js'; -import { runCommand } from '../helpers/setup-oclif-config.js'; - -describe('rdme docker-gha (single arg string from GitHub Actions runner)', () => { - let run: (args?: string[]) => Promise; - - beforeEach(() => { - run = runCommand(Command); - }); - - it('should return version from package.json for help command', async () => { - const output: string[] = []; - const spy = vi.spyOn(console, 'log'); - spy.mockImplementation(msg => { - if (typeof msg === 'string') output.push(msg); - return true; - }); - await expect(run(['help'])).resolves.toBeUndefined(); - expect(output.join('\n')).toContain("ReadMe's official CLI and GitHub Action."); - spy.mockClear(); - }); - - it('should throw error if no arguments are passed', () => { - return expect(run()).rejects.toStrictEqual(new Error("Oops! Looks like you're missing a command.")); - }); - - it('should handle a single arg', async () => { - vi.stubEnv('TEST_RDME_CI', 'true'); - await expect(run(['openapi:validate'])).rejects.toThrow( - 'Multiple API definitions found in current directory. Please specify file.', - ); - vi.unstubAllEnvs(); - }); - - it('should handle an empty arg', () => { - return expect(run([' '])).rejects.toThrow('command undefined not found'); - }); - - it('should validate file (file path in quotes)', () => { - return expect(run(['openapi:validate "__tests__/__fixtures__/petstore-simple-weird-version.json"'])).resolves.toBe( - '__tests__/__fixtures__/petstore-simple-weird-version.json is a valid OpenAPI API definition!', - ); - }); - - it('should attempt to validate file (file path contains spaces)', () => { - return expect(run(['openapi:validate "a non-existent directory/petstore.json"'])).rejects.toThrow( - "ENOENT: no such file or directory, open 'a non-existent directory/petstore.json", - ); - }); -}); diff --git a/src/cmds/docker-gha.ts b/src/cmds/docker-gha.ts deleted file mode 100644 index 30d77c7e5..000000000 --- a/src/cmds/docker-gha.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { Args } from '@oclif/core'; -import parseArgsStringToArgv from 'string-argv'; - -import BaseCommand from '../lib/baseCommand.js'; - -/** - * We have a weird edge case with our Docker image version of `rdme` where GitHub Actions - * will pass all of the `rdme` arguments as a single string with escaped quotes, - * as opposed to the usual array of strings that we typically expect with `process.argv`. - * - * For example, say the user sends us `rdme openapi "petstore.json"`. - * Instead of `process.argv` being this (i.e., when running the command via CLI): - * ['openapi', 'petstore.json'] - * - * The GitHub Actions runner will send this to the `rdme` Docker image: - * ['openapi "petstore.json"'] - * - * To distinguish these, we have a hidden `docker-gha` command which - * consumes arguments that are coming from the GitHub Actions runner. - * This command parses those arguments and then runs the respective command. - */ -export default class DockerGitHubCommand extends BaseCommand { - static description = 'Wrapper command for consuming `rdme` commands via Docker + GitHub Actions.'; - - static args = { - rawArgv: Args.string(), - }; - - static hidden = true; - - async run() { - const { rawArgv } = this.args; - if (!rawArgv) { - throw new Error("Oops! Looks like you're missing a command."); - } - const processArgv = parseArgsStringToArgv(rawArgv); - const [commandId, ...args] = processArgv; - return this.config.runCommand(commandId, args); - } -} diff --git a/src/index.ts b/src/index.ts index 3594999d5..74805de5e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,6 @@ import CategoriesCreateCommand from './cmds/categories/create.js'; import CategoriesCommand from './cmds/categories/index.js'; import ChangelogsCommand from './cmds/changelogs.js'; import CustomPagesCommand from './cmds/custompages.js'; -import DockerGitHubCommand from './cmds/docker-gha.js'; import DocsCommand from './cmds/docs/index.js'; import DocsPruneCommand from './cmds/docs/prune.js'; import LoginCommand from './cmds/login.js'; @@ -32,8 +31,6 @@ export const COMMANDS = { docs: DocsCommand, 'docs:prune': DocsPruneCommand, - 'docker-gha': DockerGitHubCommand, - versions: VersionsCommand, 'versions:create': CreateVersionCommand, 'versions:delete': DeleteVersionCommand, From 6677c5f2612ef58a9b4e3e519c75e66357bdd932 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Sat, 16 Nov 2024 09:00:29 -0600 Subject: [PATCH 2/2] chore: simplify knip --- knip.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/knip.ts b/knip.ts index a55ca0759..72e96268f 100644 --- a/knip.ts +++ b/knip.ts @@ -1,7 +1,7 @@ import type { KnipConfig } from 'knip'; const config: KnipConfig = { - entry: ['src/index.ts', 'src/lib/hooks/*.ts', 'src/lib/help.ts'], + entry: ['src/index.ts', 'src/lib/help.ts'], ignore: ['bin/*.js'], ignoreBinaries: ['semantic-release'], ignoreDependencies: ['oclif'],