Skip to content

Commit

Permalink
chore: directory spring cleaning (#327)
Browse files Browse the repository at this point in the history
* feat: dropping support for node 10

* test: fixing a broken test on node 14

* ci: updating the ci workflow to use node 12+

* ci: upgrading the codeql workflow to the latest way it configs

* chore(deps-dev): upgrading jest to v27

* chore(deps-dev): upgrading code styling dev deps

* chore(deps-dev): upgrading nock to the latest version

* chore: removing a swagger file that shouldnt be in the root dir?

* ci: updating codeql to run on `main` not `master`

* chore: updating the license to be 2021

* chore: renaming the test directory to `__tests__`

* chore: various dotfile cleanup

* chore: moving the codebase into a `src/` directory structure
  • Loading branch information
erunion authored and ollyfg committed Jun 22, 2021
1 parent 95ccf87 commit 708662a
Show file tree
Hide file tree
Showing 43 changed files with 63 additions and 76 deletions.
12 changes: 0 additions & 12 deletions .editorconfig

This file was deleted.

2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
coverage
coverage/
10 changes: 3 additions & 7 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
.DS_Store
.editorconfig
.eslintignore
.eslintrc
__tests__/
.github/
.prettierignore
.prettierrc
coverage/
test/
.eslint*
.prettier*
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
coverage
coverage/
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright © 2018 ReadMe.io
Copyright © 2021 ReadMe

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions test/cmds/docs.test.js → __tests__/cmds/docs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const path = require('path');
const crypto = require('crypto');
const frontMatter = require('gray-matter');

const docs = require('../../cmds/docs/index');
const docsEdit = require('../../cmds/docs/edit');
const docs = require('../../src/cmds/docs');
const docsEdit = require('../../src/cmds/docs/edit');

const fixturesDir = `${__dirname}./../fixtures`;
const fixturesDir = `${__dirname}./../__fixtures__`;
const key = 'Xmw4bGctRVIQz7R7dQXqH9nQe5d0SPQs';
const version = '1.0.0';

Expand Down Expand Up @@ -71,7 +71,7 @@ describe('rdme docs', () => {
.basicAuth({ user: key })
.reply(200);

return docs.run({ folder: './test/fixtures/existing-docs', key, version }).then(() => {
return docs.run({ folder: './__tests__/__fixtures__/existing-docs', key, version }).then(() => {
getMock.done();
putMock.done();
});
Expand All @@ -94,7 +94,7 @@ describe('rdme docs', () => {
.basicAuth({ user: key })
.reply(200, { category: '5ae9ece93a685f47efb9a97c', slug, lastUpdatedHash: hash });

return docs.run({ folder: './test/fixtures/existing-docs', key, version }).then(([message]) => {
return docs.run({ folder: './__tests__/__fixtures__/existing-docs', key, version }).then(([message]) => {
expect(message).toBe('`simple-doc` not updated. No changes.');
getMock.done();
});
Expand Down Expand Up @@ -133,7 +133,7 @@ describe('rdme docs', () => {
.basicAuth({ user: key })
.reply(201);

return docs.run({ folder: './test/fixtures/new-docs', key, version }).then(() => {
return docs.run({ folder: './__tests__/__fixtures__/new-docs', key, version }).then(() => {
getMock.done();
postMock.done();
});
Expand Down
4 changes: 2 additions & 2 deletions test/cmds/login.test.js → __tests__/cmds/login.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const nock = require('nock');
const config = require('config');
const configStore = require('../../lib/configstore');
const cmd = require('../../cmds/login');
const configStore = require('../../src/lib/configstore');
const cmd = require('../../src/cmds/login');

describe('rdme login', () => {
beforeAll(() => nock.disableNetConnect());
Expand Down
6 changes: 3 additions & 3 deletions test/cmds/logout.test.js → __tests__/cmds/logout.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const config = require('config');
const configStore = require('../../lib/configstore');
const cmd = require('../../cmds/logout');
const loginCmd = require('../../cmds/login');
const configStore = require('../../src/lib/configstore');
const cmd = require('../../src/cmds/logout');
const loginCmd = require('../../src/cmds/login');

describe('rdme logout', () => {
it("should report the user as logged out if they aren't logged in", () => {
Expand Down
6 changes: 3 additions & 3 deletions test/cmds/open.test.js → __tests__/cmds/open.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const config = require('config');
const configStore = require('../../lib/configstore');
const cmd = require('../../cmds/open');
const loginCmd = require('../../cmds/login');
const configStore = require('../../src/lib/configstore');
const cmd = require('../../src/cmds/open');
const loginCmd = require('../../src/cmds/login');

describe('rdme open', () => {
it('should error if no project provided', () => {
Expand Down
22 changes: 11 additions & 11 deletions test/cmds/swagger.test.js → __tests__/cmds/swagger.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const nock = require('nock');
const config = require('config');
const fs = require('fs');
const promptHandler = require('../../lib/prompts');
const swagger = require('../../cmds/swagger');
const promptHandler = require('../../src/lib/prompts');
const swagger = require('../../src/cmds/swagger');

const key = 'Xmw4bGctRVIQz7R7dQXqH9nQe5d0SPQs';
const version = '1.0.0';

jest.mock('../../lib/prompts');
jest.mock('../../src/lib/prompts');

const getCommandOutput = () => {
return [console.warn.mock.calls.join('\n\n'), console.log.mock.calls.join('\n\n')].filter(Boolean).join('\n\n');
Expand Down Expand Up @@ -51,7 +51,7 @@ describe('rdme swagger', () => {
// Surface our test fixture to the root directory so rdme can autodiscover it. It's easier to do
// this than mocking out the fs module because mocking the fs module here causes Jest sourcemaps
// to break.
fs.copyFileSync('./test/fixtures/swagger.json', './swagger.json');
fs.copyFileSync('./__tests__/__fixtures__/swagger.json', './swagger.json');

return swagger.run({ key }).then(() => {
expect(console.log).toHaveBeenCalledTimes(2);
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('rdme swagger', () => {
help: 'If you need help, email [email protected] and mention log "fake-metrics-uuid".',
});

return expect(swagger.run({ spec: './test/fixtures/swagger.json', key, version }))
return expect(swagger.run({ spec: './__tests__/__fixtures__/swagger.json', key, version }))
.rejects.toThrow('The version you specified')
.then(() => mock.done());
});
Expand All @@ -103,7 +103,7 @@ describe('rdme swagger', () => {
.basicAuth({ user: key })
.reply(201, { _id: 1 }, { location: exampleRefLocation });

return swagger.run({ spec: './test/fixtures/swagger.json', key, version }).then(() => {
return swagger.run({ spec: './__tests__/__fixtures__/swagger.json', key, version }).then(() => {
expect(console.log).toHaveBeenCalledTimes(1);

const output = getCommandOutput();
Expand Down Expand Up @@ -134,7 +134,7 @@ describe('rdme swagger', () => {
help: 'If you need help, email [email protected] and mention log "fake-metrics-uuid".',
});

return expect(swagger.run({ spec: './test/fixtures/invalid-swagger.json', key, version }))
return expect(swagger.run({ spec: './__tests__/__fixtures__/invalid-swagger.json', key, version }))
.rejects.toThrow('README VALIDATION ERROR "x-samples-languages" must be of type "Array"')
.then(() => mock.done());
});
Expand All @@ -161,7 +161,7 @@ describe('rdme swagger', () => {
.basicAuth({ user: key })
.reply(201, { _id: 1 }, { location: exampleRefLocation });

return swagger.run({ spec: './test/fixtures/swagger.json', key }).then(() => {
return swagger.run({ spec: './__tests__/__fixtures__/swagger.json', key }).then(() => {
mock.done();
});
});
Expand All @@ -174,7 +174,7 @@ describe('rdme swagger', () => {
.basicAuth({ user: key })
.reply(201, { body: '{ id: 1 }' });

return swagger.run({ spec: './test/fixtures/swagger.json', key, id, version }).then(() => {
return swagger.run({ spec: './__tests__/__fixtures__/swagger.json', key, id, version }).then(() => {
mock.done();
});
});
Expand All @@ -187,7 +187,7 @@ describe('rdme swagger', () => {
.basicAuth({ user: key })
.reply(201, { id: 1 }, { location: exampleRefLocation });

return swagger.run({ spec: './test/fixtures/swagger.json', token: `${key}-${id}`, version }).then(() => {
return swagger.run({ spec: './__tests__/__fixtures__/swagger.json', token: `${key}-${id}`, version }).then(() => {
expect(console.warn).toHaveBeenCalledTimes(1);
expect(console.log).toHaveBeenCalledTimes(1);

Expand All @@ -200,7 +200,7 @@ describe('rdme swagger', () => {
});

it('should error if no api key provided', async () => {
await expect(swagger.run({ spec: './test/fixtures/swagger.json' })).rejects.toThrow(
await expect(swagger.run({ spec: './__tests__/__fixtures__/swagger.json' })).rejects.toThrow(
'No project API key provided. Please use `--key`.'
);
});
Expand Down
12 changes: 6 additions & 6 deletions test/cmds/versions.test.js → __tests__/cmds/versions.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const nock = require('nock');
const config = require('config');
const promptHandler = require('../../lib/prompts');
const promptHandler = require('../../src/lib/prompts');

const versions = require('../../cmds/versions/index');
const createVersion = require('../../cmds/versions/create');
const deleteVersion = require('../../cmds/versions/delete');
const updateVersion = require('../../cmds/versions/update');
const versions = require('../../src/cmds/versions');
const createVersion = require('../../src/cmds/versions/create');
const deleteVersion = require('../../src/cmds/versions/delete');
const updateVersion = require('../../src/cmds/versions/update');

const key = 'Xmw4bGctRVIQz7R7dQXqH9nQe5d0SPQs';
const version = '1.0.0';
Expand All @@ -31,7 +31,7 @@ const version2Payload = {
version: version2,
};

jest.mock('../../lib/prompts');
jest.mock('../../src/lib/prompts');

describe('rdme versions*', () => {
beforeAll(() => nock.disableNetConnect());
Expand Down
6 changes: 3 additions & 3 deletions test/cmds/whoami.test.js → __tests__/cmds/whoami.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const config = require('config');
const configStore = require('../../lib/configstore');
const cmd = require('../../cmds/whoami');
const loginCmd = require('../../cmds/login');
const configStore = require('../../src/lib/configstore');
const cmd = require('../../src/cmds/whoami');
const loginCmd = require('../../src/cmds/login');

describe('rdme whoami', () => {
it('should error if user is not authenticated', () => {
Expand Down
6 changes: 3 additions & 3 deletions test/cli.test.js → __tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require('colors');

const nock = require('nock');
const cli = require('../cli');
const cli = require('../src');
const { version } = require('../package.json');
const conf = require('../lib/configstore');
const swaggerCmd = require('../cmds/swagger');
const conf = require('../src/lib/configstore');
const swaggerCmd = require('../src/cmds/swagger');

describe('cli', () => {
it('command not found', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const APIError = require('../../lib/apiError');
const APIError = require('../../src/lib/apiError');

const response = {
error: 'VERSION_FORK_EMPTY',
Expand Down
10 changes: 5 additions & 5 deletions test/lib/commands.test.js → __tests__/lib/commands.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const commands = require('../../lib/commands').list();
const commands = require('../../src/lib/commands');

describe('utils', () => {
describe('#getCommands', () => {
describe('#list', () => {
it('should have commands returned', () => {
expect(commands).not.toHaveLength(0);
expect(commands.list()).not.toHaveLength(0);
});

describe('commands', () => {
it('should be configured properly', () => {
commands.forEach(c => {
commands.list().forEach(c => {
const cmd = c.command;

expect(typeof cmd.command === 'string' && cmd.command.length !== 0).toBe(true);
Expand All @@ -31,7 +31,7 @@ describe('utils', () => {
});

it('should abide by our cli standards', () => {
commands.forEach(c => {
commands.list().forEach(c => {
const cmd = c.command;

expect(cmd.description[cmd.description.length - 1]).toBe('.');
Expand Down
2 changes: 1 addition & 1 deletion test/lib/prompts.test.js → __tests__/lib/prompts.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Enquirer = require('enquirer');
const promptHandler = require('../../lib/prompts');
const promptHandler = require('../../src/lib/prompts');

const versionlist = [
{
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion rdme.js → bin/rdme
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/env node
require('colors');

require('./cli')(process.argv.slice(2))
require('../src')(process.argv.slice(2))
.then(msg => {
if (msg) console.log(msg);
process.exit(0);
Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"node": "^12 || ^14 || ^16"
},
"bin": {
"rdme": "rdme.js"
"rdme": "bin/rdme"
},
"tags": [
"api",
Expand Down Expand Up @@ -63,17 +63,20 @@
"test": "jest --coverage"
},
"jest": {
"setupFiles": [
"./test/set-node-env"
],
"coverageThreshold": {
"global": {
"branches": 80,
"functions": 80,
"lines": 90,
"statements": 90
}
}
},
"setupFiles": [
"./__tests__/set-node-env"
],
"testPathIgnorePatterns": [
"./__tests__/set-node-env"
]
},
"prettier": "@readme/eslint-config/prettier"
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion cmds/oas.js → src/cmds/oas.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports.position = 1;
exports.args = [];

exports.run = function () {
const cp = spawn(path.join(__dirname, '..', 'node_modules', '.bin', 'oas'), process.argv.slice(3), {
const cp = spawn(path.join(__dirname, '..', '..', 'node_modules', '.bin', 'oas'), process.argv.slice(3), {
stdio: 'inherit',
});

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions cli.js → src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ const path = require('path');
// but since this is only supposed to be a cli and not
// requireable, i think this is okay
const configDir = process.env.NODE_CONFIG_DIR;
process.env.NODE_CONFIG_DIR = path.join(__dirname, '/config');
process.env.NODE_CONFIG_DIR = path.join(__dirname, '../config');

const config = require('config');

process.env.NODE_CONFIG_DIR = configDir;

const { version } = require('./package.json');
const { version } = require('../package.json');
const configStore = require('./lib/configstore');
const help = require('./lib/help');
const commands = require('./lib/commands');
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/configstore.js → src/lib/configstore.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Configstore = require('configstore');
const pkg = require('../package.json');
const pkg = require('../../package.json');

module.exports = new Configstore(`${pkg.name}-${process.env.NODE_ENV || 'production'}`);
File renamed without changes.
File renamed without changes.

0 comments on commit 708662a

Please sign in to comment.