Skip to content

Commit

Permalink
feat: CLI show endpoints and status SO-201 (#296)
Browse files Browse the repository at this point in the history
* feat: CLI show endpoints and status

* test: add real fake resource

* docs: update output

* refactor: rename variable
  • Loading branch information
XVincentX committed May 13, 2019
1 parent a09dfb3 commit d60830b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 7 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ Running Prism on the CLI will create a HTTP mock server.

```bash
prism mock https://raw.githack.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore-expanded.yaml
> http://127.0.0.1:4010
✔ success Prism is listening on http://127.0.0.1:4010
● note GET http://127.0.0.1:4010/pets
● note POST http://127.0.0.1:4010/pets
● note GET http://127.0.0.1:4010/pets/{id}
● note DELETE http://127.0.0.1:4010/pets/{id}
```

Then in another tab, you can hit the HTTP server with your favorite HTTP client.
Expand Down
5 changes: 4 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
"@oclif/plugin-help": "^2.0.0",
"@stoplight/prism-core": "^3.0.0-alpha.2",
"@stoplight/prism-http-server": "^3.0.0-alpha.2",
"signale": "^1.4.0",
"tmp": "^0.1.0",
"tslib": "^1.0.0"
"tslib": "^1.0.0",
"urijs": "^1.19.1"
},
"devDependencies": {
"@oclif/dev-cli": "^1.0.0",
"@oclif/tslint": "^3.0.0",
"@types/chai": "^4.0.0",
"@types/node": "^12.0.0",
"@types/signale": "^1.2.1",
"@types/tmp": "^0.1.0",
"globby": "^9.0.0",
"ts-node": "^8.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/__tests__/mock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Mock from '../mock';
const listenMock = jest.fn();

jest.mock('../../util/createServer', () => ({
createServer: jest.fn(() => ({ listen: listenMock })),
createServer: jest.fn(() => ({ listen: listenMock, prism: { resources: [{ method: 'get', path: '/test' }] } })),
}));

describe('mock command', () => {
Expand Down
17 changes: 15 additions & 2 deletions packages/cli/src/commands/mock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Command } from '@oclif/command';
import * as signale from 'signale';
import { ARGS, FLAGS } from '../const/options';
import { createServer } from '../util/createServer';

Expand All @@ -8,15 +9,27 @@ export default class Server extends Command {
public static args = [ARGS.spec];

public async run() {
const signaleInteractiveInstance = new signale.Signale({ interactive: true });

signaleInteractiveInstance.await('Starting Prism…');

const {
flags: { port },
args: { spec },
} = this.parse(Server);

const server = createServer(spec, { mock: true });

const address = await server.listen(port);

this.log(address);
if (server.prism.resources.length === 0) {
signaleInteractiveInstance.fatal('No operations found in the current file.');
this.exit(1);
}

signaleInteractiveInstance.success(`Prism is listening on ${address}`);

server.prism.resources.forEach(resource => {
signale.note(`${resource.method.toUpperCase().padEnd(10)} ${address}${resource.path}`);
});
}
}
28 changes: 26 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,13 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.0.0.tgz#d11813b9c0ff8aaca29f04cbc12817f4c7d656e5"
integrity sha512-Jrb/x3HT4PTJp6a4avhmJCDEVrPdqLfl3e8GGMbpkGGdwAV5UGlIs4vVEfsHHfylZVOKZWpOqmqFH8CbfOZ6kg==

"@types/signale@^1.2.1":
version "1.2.1"
resolved "https://registry.yarnpkg.com/@types/signale/-/signale-1.2.1.tgz#7ff3d477e8d5983b7ecef544f5830c3cb271d1a8"
integrity sha512-mV6s2VgcBC16Jb+1EwulgRrrZBT93V4JCILkNPg31rvvSK6LRQQGU8R/SUivgHjDZ5LJZu/yL2kMF8j85YQTnA==
dependencies:
"@types/node" "*"

"@types/sizzle@*":
version "2.3.2"
resolved "https://registry.yarnpkg.com/@types/sizzle/-/sizzle-2.3.2.tgz#a811b8c18e2babab7d542b3365887ae2e4d9de47"
Expand Down Expand Up @@ -2003,7 +2010,7 @@ chalk@^1.1.3:
strip-ansi "^3.0.0"
supports-color "^2.0.0"

chalk@^2.0.0, chalk@^2.0.1, chalk@^2.3.0, chalk@^2.3.1, chalk@^2.4.1, chalk@^2.4.2:
chalk@^2.0.0, chalk@^2.0.1, chalk@^2.3.0, chalk@^2.3.1, chalk@^2.3.2, chalk@^2.4.1, chalk@^2.4.2:
version "2.4.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==
Expand Down Expand Up @@ -5974,6 +5981,14 @@ pirates@^4.0.1:
dependencies:
node-modules-regexp "^1.0.0"

pkg-conf@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/pkg-conf/-/pkg-conf-2.1.0.tgz#2126514ca6f2abfebd168596df18ba57867f0058"
integrity sha1-ISZRTKbyq/69FoWW3xi6V4Z/AFg=
dependencies:
find-up "^2.0.0"
load-json-file "^4.0.0"

pkg-dir@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-2.0.0.tgz#f6d5d1109e19d63edf428e0bd57e12777615334b"
Expand Down Expand Up @@ -6689,6 +6704,15 @@ signal-exit@^3.0.0, signal-exit@^3.0.2:
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
integrity sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=

signale@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/signale/-/signale-1.4.0.tgz#c4be58302fb0262ac00fc3d886a7c113759042f1"
integrity sha512-iuh+gPf28RkltuJC7W5MRi6XAjTDCAPC/prJUpQoG4vIP3MJZ+GTydVnodXA7pwvTKb2cA0m9OFZW/cdWy/I/w==
dependencies:
chalk "^2.3.2"
figures "^2.0.0"
pkg-conf "^2.1.0"

sisteransi@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.0.tgz#77d9622ff909080f1c19e5f4a1df0c1b0a27b88c"
Expand Down Expand Up @@ -7660,7 +7684,7 @@ uri-js@^4.2.2:
dependencies:
punycode "^2.1.0"

[email protected], [email protected]:
[email protected], [email protected], urijs@^1.19.1:
version "1.19.1"
resolved "https://registry.yarnpkg.com/urijs/-/urijs-1.19.1.tgz#5b0ff530c0cbde8386f6342235ba5ca6e995d25a"
integrity sha512-xVrGVi94ueCJNrBSTjWqjvtgvl3cyOTThp2zaMaFNGp3F542TR6sM3f2o8RqZl+AwteClSVmoCyt0ka4RjQOQg==
Expand Down

0 comments on commit d60830b

Please sign in to comment.