From c985979c07e758fd5fc7a65abb7765b57422825f Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Thu, 27 Oct 2022 11:17:51 -0400 Subject: [PATCH] feat(breaking/docs): deprecate `docs:edit` --- __tests__/cmds/docs/edit.test.ts | 21 +++++++++++++++++++ __tests__/index.test.ts | 19 +---------------- .../lib/__snapshots__/commands.test.ts.snap | 4 ++-- src/cmds/docs/edit.ts | 5 ++++- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/__tests__/cmds/docs/edit.test.ts b/__tests__/cmds/docs/edit.test.ts index a67a04670..02bf91f46 100644 --- a/__tests__/cmds/docs/edit.test.ts +++ b/__tests__/cmds/docs/edit.test.ts @@ -14,6 +14,20 @@ const version = '1.0.0'; const category = 'CATEGORY_ID'; describe('rdme docs:edit', () => { + let consoleWarnSpy; + + function getWarningCommandOutput() { + return [consoleWarnSpy.mock.calls.join('\n\n')].filter(Boolean).join('\n\n'); + } + + beforeEach(() => { + consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(); + }); + + afterEach(() => { + consoleWarnSpy.mockRestore(); + }); + beforeAll(() => nock.disableNetConnect()); afterAll(() => nock.cleanAll()); @@ -31,6 +45,13 @@ describe('rdme docs:edit', () => { delete process.env.TEST_CI; }); + it('should log deprecation notice', async () => { + process.env.TEST_CI = 'true'; + await expect(docsEdit.run({})).rejects.toStrictEqual(new Error('No project API key provided. Please use `--key`.')); + delete process.env.TEST_CI; + expect(getWarningCommandOutput()).toMatch('is now deprecated'); + }); + it('should error if no slug provided', () => { return expect(docsEdit.run({ key, version: '1.0.0' })).rejects.toThrow( 'No slug provided. Usage `rdme docs:edit [options]`.' diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts index cbfdf38de..bce1f7482 100644 --- a/__tests__/index.test.ts +++ b/__tests__/index.test.ts @@ -1,4 +1,3 @@ -import nock from 'nock'; import prompts from 'prompts'; import { version } from '../package.json'; @@ -33,17 +32,6 @@ describe('cli', () => { 'Command not found.' ); }); - - it('should not be returned if `--version` is being used on a subcommand', async () => { - nock.disableNetConnect(); - - await expect(cli(['docs:edit', 'getting-started', '--version', '1.0.0', '--key=abcdef'])).rejects.not.toThrow( - // We're testing that the docs:edit command does NOT return an error about `--version` not - // being here because if it throws that error, then that means that `--version` wasn't - // passed in as expected. - 'No project version provided. Please use `--version`.' - ); - }); }); describe('--help', () => { @@ -95,13 +83,8 @@ describe('cli', () => { }); describe('subcommands', () => { - // docs:edit will make a backend connection - beforeAll(() => nock.disableNetConnect()); - it('should load subcommands from the folder', async () => { - await expect(cli(['docs:edit', 'getting-started', '--version=1.0.0', '--key=abcdef'])).rejects.not.toThrow( - 'Command not found.' - ); + await expect(cli(['openapi:validate', 'package.json'])).rejects.not.toThrow('Command not found.'); }); }); diff --git a/__tests__/lib/__snapshots__/commands.test.ts.snap b/__tests__/lib/__snapshots__/commands.test.ts.snap index c86da70f4..c2b7d8d98 100644 --- a/__tests__/lib/__snapshots__/commands.test.ts.snap +++ b/__tests__/lib/__snapshots__/commands.test.ts.snap @@ -120,8 +120,8 @@ exports[`utils #listByCategory should list commands by category 1`] = ` "position": 1, }, { - "description": "Edit a single file from your ReadMe project without saving locally.", - "hidden": false, + "description": "Edit a single file from your ReadMe project without saving locally. [deprecated]", + "hidden": true, "name": "docs:edit", "position": 2, }, diff --git a/src/cmds/docs/edit.ts b/src/cmds/docs/edit.ts index f2556dbe3..52db5e04e 100644 --- a/src/cmds/docs/edit.ts +++ b/src/cmds/docs/edit.ts @@ -10,6 +10,7 @@ import editor from 'editor'; import APIError from '../../lib/apiError'; import Command, { CommandCategories } from '../../lib/baseCommand'; +import isHidden from '../../lib/decorators/isHidden'; import fetch, { cleanHeaders, handleRes } from '../../lib/fetch'; import { getProjectVersion } from '../../lib/versionSelect'; @@ -22,13 +23,14 @@ export type Options = { slug?: string; }; +@isHidden export default class EditDocsCommand extends Command { constructor() { super(); this.command = 'docs:edit'; this.usage = 'docs:edit [options]'; - this.description = 'Edit a single file from your ReadMe project without saving locally.'; + this.description = 'Edit a single file from your ReadMe project without saving locally. [deprecated]'; this.cmdCategory = CommandCategories.DOCS; this.position = 2; @@ -45,6 +47,7 @@ export default class EditDocsCommand extends Command { } async run(opts: CommandOptions): Promise { + Command.warn('`rdme docs:edit` is now deprecated and will be removed in a future release.'); await super.run(opts); const { slug, key, version } = opts;