Skip to content

Commit

Permalink
refactor: remove node-config
Browse files Browse the repository at this point in the history
  • Loading branch information
kanadgupta committed Sep 12, 2023
1 parent 45417ab commit ebb1f4f
Show file tree
Hide file tree
Showing 25 changed files with 68 additions and 129 deletions.
6 changes: 3 additions & 3 deletions __tests__/cmds/logout.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import config from 'config';
import { describe, afterEach, it, expect } from 'vitest';

import Command from '../../src/cmds/logout';
import config from '../../src/lib/config';
import configStore from '../../src/lib/configstore';

const cmd = new Command();
Expand All @@ -16,7 +16,7 @@ describe('rdme logout', () => {
configStore.delete('project');

return expect(cmd.run({})).resolves.toBe(
`You have logged out of ReadMe. Please use \`${config.get('cli')} login\` to login again.`,
`You have logged out of ReadMe. Please use \`${config.cli} login\` to login again.`,
);
});

Expand All @@ -25,7 +25,7 @@ describe('rdme logout', () => {
configStore.set('project', 'subdomain');

await expect(cmd.run({})).resolves.toBe(
`You have logged out of ReadMe. Please use \`${config.get('cli')} login\` to login again.`,
`You have logged out of ReadMe. Please use \`${config.cli} login\` to login again.`,
);

expect(configStore.get('email')).toBeUndefined();
Expand Down
6 changes: 3 additions & 3 deletions __tests__/cmds/open.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Version } from '../../src/cmds/versions';

import chalk from 'chalk';
import config from 'config';
import { describe, afterEach, it, expect } from 'vitest';

import Command from '../../src/cmds/open';
import config from '../../src/lib/config';
import configStore from '../../src/lib/configstore';
import getAPIMock from '../helpers/get-api-mock';

Expand All @@ -18,7 +18,7 @@ describe('rdme open', () => {
it('should error if no project provided', () => {
configStore.delete('project');

return expect(cmd.run({})).rejects.toStrictEqual(new Error(`Please login using \`${config.get('cli')} login\`.`));
return expect(cmd.run({})).rejects.toStrictEqual(new Error(`Please login using \`${config.cli} login\`.`));
});

it('should open the project', () => {
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('rdme open', () => {
}

return expect(cmd.run({ mockOpen, dash: true, key: '12345' })).rejects.toStrictEqual(
new Error(`Please login using \`${config.get('cli')} login\`.`),
new Error(`Please login using \`${config.cli} login\`.`),
);
});
});
Expand Down
4 changes: 2 additions & 2 deletions __tests__/cmds/openapi/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import fs from 'fs';

import chalk from 'chalk';
import config from 'config';
import nock from 'nock';
import prompts from 'prompts';
import { describe, beforeAll, beforeEach, afterEach, it, expect, vi } from 'vitest';

import OpenAPICommand from '../../../src/cmds/openapi';
import SwaggerCommand from '../../../src/cmds/swagger';
import APIError from '../../../src/lib/apiError';
import config from '../../../src/lib/config';
import petstoreWeird from '../../__fixtures__/petstore-simple-weird-version.json';
import getAPIMock, { getAPIMockWithVersionHeader } from '../../helpers/get-api-mock';
import { after, before } from '../../helpers/get-gha-setup';
Expand All @@ -24,7 +24,7 @@ let consoleWarnSpy;
const key = 'API_KEY';
const id = '5aa0409b7cf527a93bfb44df';
const version = '1.0.0';
const exampleRefLocation = `${config.get('host')}/project/example-project/1.0.1/refs/ex`;
const exampleRefLocation = `${config.host}/project/example-project/1.0.1/refs/ex`;
const successfulMessageBase = (specPath, specType) => [
'',
`\t${chalk.green(exampleRefLocation)}`,
Expand Down
4 changes: 2 additions & 2 deletions __tests__/cmds/whoami.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import config from 'config';
import { describe, afterEach, it, expect } from 'vitest';

import Command from '../../src/cmds/whoami';
import config from '../../src/lib/config';
import configStore from '../../src/lib/configstore';

const cmd = new Command();
Expand All @@ -15,7 +15,7 @@ describe('rdme whoami', () => {
configStore.delete('email');
configStore.delete('project');

return expect(cmd.run({})).rejects.toStrictEqual(new Error(`Please login using \`${config.get('cli')} login\`.`));
return expect(cmd.run({})).rejects.toStrictEqual(new Error(`Please login using \`${config.cli} login\`.`));
});

it('should return the authenticated user', () => {
Expand Down
6 changes: 3 additions & 3 deletions __tests__/helpers/get-api-mock.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Headers } from 'headers-polyfill';
import type { ResponseTransformer } from 'msw';

import config from 'config';
import { rest } from 'msw';
import nock from 'nock';

import config from '../../src/lib/config';
import { getUserAgent } from '../../src/lib/readmeAPIFetch';

/**
Expand All @@ -20,7 +20,7 @@ type ReqHeaders = Record<string, unknown>;
* @param proxy Optional proxy URL. Must contain trailing slash.
*/
export default function getAPIMock(reqHeaders = {}, proxy = '') {
return nock(`${proxy}${config.get('host')}`, {
return nock(`${proxy}${config.host}`, {
reqheaders: {
'User-Agent': getUserAgent(),
...reqHeaders,
Expand Down Expand Up @@ -76,7 +76,7 @@ export function getAPIMockMSW(
expectedReqHeaders: ReqHeaders = {},
proxy = '',
) {
return rest.get(`${proxy}${config.get('host')}${path}`, (req, res, ctx) => {
return rest.get(`${proxy}${config.host}${path}`, (req, res, ctx) => {
try {
validateHeaders(req.headers, basicAuthUser, expectedReqHeaders);
let responseTransformer: ResponseTransformer;
Expand Down
22 changes: 11 additions & 11 deletions __tests__/single-threaded/openapi/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import fs from 'fs';

import chalk from 'chalk';
import config from 'config';
import { rest } from 'msw';
import { setupServer } from 'msw/node';
import prompts from 'prompts';
import { describe, beforeAll, beforeEach, afterEach, it, expect, vi, afterAll } from 'vitest';

import OpenAPICommand from '../../../src/cmds/openapi';
import config from '../../../src/lib/config';
import { getAPIMockMSW } from '../../helpers/get-api-mock';
import { after, before } from '../../helpers/get-gha-setup';
import { after as afterGHAEnv, before as beforeGHAEnv } from '../../helpers/setup-gha-env';
Expand All @@ -20,7 +20,7 @@ let consoleWarnSpy;

const key = 'API_KEY';
const version = '1.0.0';
const exampleRefLocation = `${config.get('host')}/project/example-project/1.0.1/refs/ex`;
const exampleRefLocation = `${config.host}/project/example-project/1.0.1/refs/ex`;
const successfulMessageBase = (specPath, specType) => [
'',
`\t${chalk.green(exampleRefLocation)}`,
Expand Down Expand Up @@ -73,13 +73,13 @@ describe('rdme openapi (single-threaded)', () => {
server.use(
...[
getAPIMockMSW(`/api/v1/version/${version}`, 200, { json: { version } }, key),
rest.post(`${config.get('host')}/api/v1/api-registry`, async (req, res, ctx) => {
rest.post(`${config.host}/api/v1/api-registry`, async (req, res, ctx) => {
const body = await req.text();
expect(body).toMatch('form-data; name="spec"');
return res(ctx.status(201), ctx.json({ registryUUID, spec: { openapi: '3.0.0' } }));
}),
getAPIMockMSW('/api/v1/api-specification', 200, { json: [] }, key, { 'x-readme-version': version }),
rest.post(`${config.get('host')}/api/v1/api-specification`, async (req, res, ctx) => {
rest.post(`${config.host}/api/v1/api-specification`, async (req, res, ctx) => {
const body = await req.json();
expect(body).toStrictEqual({ registryUUID });
expect(req.headers.get('authorization')).toBeBasicAuthApiKey(key);
Expand Down Expand Up @@ -112,15 +112,15 @@ describe('rdme openapi (single-threaded)', () => {
server.use(
...[
getAPIMockMSW(`/api/v1/version/${version}`, 200, { json: { version } }, key),
rest.post(`${config.get('host')}/api/v1/api-registry`, async (req, res, ctx) => {
rest.post(`${config.host}/api/v1/api-registry`, async (req, res, ctx) => {
const body = await req.text();
requestBody = body.substring(body.indexOf('{'), body.lastIndexOf('}') + 1);
requestBody = JSON.parse(requestBody);
expect(body).toMatch('form-data; name="spec"');
return res(ctx.status(201), ctx.json({ registryUUID, spec: { openapi: '3.0.0' } }));
}),
getAPIMockMSW('/api/v1/api-specification', 200, { json: [] }, key, { 'x-readme-version': version }),
rest.post(`${config.get('host')}/api/v1/api-specification`, async (req, res, ctx) => {
rest.post(`${config.host}/api/v1/api-specification`, async (req, res, ctx) => {
const body = await req.json();
expect(body).toStrictEqual({ registryUUID });
expect(req.headers.get('authorization')).toBeBasicAuthApiKey(key);
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('rdme openapi (single-threaded)', () => {
server.use(
...[
getAPIMockMSW(`/api/v1/version/${version}`, 200, { json: { version } }, key),
rest.post(`${config.get('host')}/api/v1/api-registry`, async (req, res, ctx) => {
rest.post(`${config.host}/api/v1/api-registry`, async (req, res, ctx) => {
const body = await req.text();
expect(body).toMatch('form-data; name="spec"');
return res(ctx.status(201), ctx.json({ registryUUID, spec: { openapi: '3.0.0' } }));
Expand Down Expand Up @@ -211,13 +211,13 @@ describe('rdme openapi (single-threaded)', () => {
server.use(
...[
getAPIMockMSW(`/api/v1/version/${version}`, 200, { json: { version } }, key),
rest.post(`${config.get('host')}/api/v1/api-registry`, async (req, res, ctx) => {
rest.post(`${config.host}/api/v1/api-registry`, async (req, res, ctx) => {
const body = await req.text();
expect(body).toMatch('form-data; name="spec"');
return res(ctx.status(201), ctx.json({ registryUUID, spec: { openapi: '3.0.0' } }));
}),
getAPIMockMSW('/api/v1/api-specification', 200, { json: [] }, key, { 'x-readme-version': version }),
rest.post(`${config.get('host')}/api/v1/api-specification`, async (req, res, ctx) => {
rest.post(`${config.host}/api/v1/api-specification`, async (req, res, ctx) => {
expect(req.headers.get('authorization')).toBeBasicAuthApiKey(key);
const body = await req.json();
expect(body).toStrictEqual({ registryUUID });
Expand Down Expand Up @@ -260,13 +260,13 @@ describe('rdme openapi (single-threaded)', () => {
server.use(
...[
getAPIMockMSW(`/api/v1/version/${version}`, 200, { json: { version } }, key),
rest.post(`${config.get('host')}/api/v1/api-registry`, async (req, res, ctx) => {
rest.post(`${config.host}/api/v1/api-registry`, async (req, res, ctx) => {
const body = await req.text();
expect(body).toMatch('form-data; name="spec"');
return res(ctx.status(201), ctx.json({ registryUUID, spec: { openapi: '3.0.0' } }));
}),
getAPIMockMSW('/api/v1/api-specification', 200, { json: [] }, key, { 'x-readme-version': version }),
rest.post(`${config.get('host')}/api/v1/api-specification`, async (req, res, ctx) => {
rest.post(`${config.host}/api/v1/api-specification`, async (req, res, ctx) => {
expect(req.headers.get('authorization')).toBeBasicAuthApiKey(key);
expect(req.headers.get('x-rdme-ci')).toBe('GitHub Actions (test)');
expect(req.headers.get('x-readme-source')).toBe('cli-gh');
Expand Down
1 change: 0 additions & 1 deletion config/custom-environment-variables.json

This file was deleted.

4 changes: 0 additions & 4 deletions config/localhost.json

This file was deleted.

1 change: 0 additions & 1 deletion config/rdme-test.json

This file was deleted.

36 changes: 0 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"ci-info": "^3.6.1",
"command-line-args": "^5.2.0",
"command-line-usage": "^7.0.1",
"config": "^3.1.0",
"configstore": "^5.0.0",
"debug": "^4.3.3",
"editor": "^1.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/cmds/categories/create.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { CommandOptions } from '../../lib/baseCommand';

import chalk from 'chalk';
import config from 'config';
import { Headers } from 'node-fetch';

import Command, { CommandCategories } from '../../lib/baseCommand';
import config from '../../lib/config';
import getCategories from '../../lib/getCategories';
import readmeAPIFetch, { cleanHeaders, handleRes } from '../../lib/readmeAPIFetch';
import { getProjectVersion } from '../../lib/versionSelect';
Expand Down Expand Up @@ -58,7 +58,7 @@ export default class CategoriesCreateCommand extends Command {
const { categoryType, title, key, version, preventDuplicates } = opts;

if (!title) {
return Promise.reject(new Error(`No title provided. Usage \`${config.get('cli')} ${this.usage}\`.`));
return Promise.reject(new Error(`No title provided. Usage \`${config.cli} ${this.usage}\`.`));
}

if (categoryType !== 'guide' && categoryType !== 'reference') {
Expand Down
4 changes: 2 additions & 2 deletions src/cmds/docs/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import type { CommandOptions } from '../../lib/baseCommand';
import fs from 'fs';
import { promisify } from 'util';

import config from 'config';
import { Headers } from 'node-fetch';

import editor from 'editor';

import APIError from '../../lib/apiError';
import Command, { CommandCategories } from '../../lib/baseCommand';
import config from '../../lib/config';
import isHidden from '../../lib/decorators/isHidden';
import readmeAPIFetch, { cleanHeaders, handleRes } from '../../lib/readmeAPIFetch';
import { getProjectVersion } from '../../lib/versionSelect';
Expand Down Expand Up @@ -52,7 +52,7 @@ export default class DocsEditCommand extends Command {
const { slug, key, version } = opts;

if (!slug) {
return Promise.reject(new Error(`No slug provided. Usage \`${config.get('cli')} ${this.usage}\`.`));
return Promise.reject(new Error(`No slug provided. Usage \`${config.cli} ${this.usage}\`.`));
}

const selectedVersion = await getProjectVersion(version, key);
Expand Down
4 changes: 2 additions & 2 deletions src/cmds/docs/prune.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { CommandOptions } from '../../lib/baseCommand';

import chalk from 'chalk';
import config from 'config';
import prompts from 'prompts';

import Command, { CommandCategories } from '../../lib/baseCommand';
import config from '../../lib/config';
import createGHA from '../../lib/createGHA';
import deleteDoc from '../../lib/deleteDoc';
import getDocs from '../../lib/getDocs';
Expand Down Expand Up @@ -62,7 +62,7 @@ export default class DocsPruneCommand extends Command {
const { dryRun, folder, key, version } = opts;

if (!folder) {
return Promise.reject(new Error(`No folder provided. Usage \`${config.get('cli')} ${this.usage}\`.`));
return Promise.reject(new Error(`No folder provided. Usage \`${config.cli} ${this.usage}\`.`));
}

// TODO: should we allow version selection at all here?
Expand Down
Loading

0 comments on commit ebb1f4f

Please sign in to comment.