Skip to content

Commit

Permalink
fix: Prism should read yml files too SO-200 (#299)
Browse files Browse the repository at this point in the history
* docs: yml support is there

* fix: catch loading exceptions and print it on the screen

* fix: correctly set language

* fix: use graphite stuff
  • Loading branch information
XVincentX committed May 14, 2019
1 parent 7643c19 commit cbc96b2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ This error shows the request is missing a required property `name` from the HTTP
- [ ] Forwarding proxy with validation
- [ ] Recording traffic to spec file
- [ ] Data Persistence (turn Prism into a sandbox server)
- [ ] Support files ending with `.yml` and extension-less files
- [x] Support files ending with `.yml` and extension-less files

## FAQs

Expand Down
22 changes: 13 additions & 9 deletions packages/cli/src/commands/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@ export default class Server extends Command {
} = this.parse(Server);

const server = createServer(spec, { mock: true });
const address = await server.listen(port);
try {
const address = await server.listen(port);

if (server.prism.resources.length === 0) {
signaleInteractiveInstance.fatal('No operations found in the current file.');
this.exit(1);
}
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}`);
signaleInteractiveInstance.success(`Prism is listening on ${address}`);

server.prism.resources.forEach(resource => {
signale.note(`${resource.method.toUpperCase().padEnd(10)} ${address}${resource.path}`);
});
server.prism.resources.forEach(resource => {
signale.note(`${resource.method.toUpperCase().padEnd(10)} ${address}${resource.path}`);
});
} catch (e) {
signaleInteractiveInstance.fatal(e.message);
}
}
}
7 changes: 4 additions & 3 deletions packages/core/src/utils/graphFacade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
FileSystemBackend,
FilesystemNodeType,
} from '@stoplight/graphite/backends/filesystem';
import { filenameToLanguage } from '@stoplight/graphite/backends/filesystem/utils';
import { NodeCategory } from '@stoplight/graphite/graph/nodes';
import { createGraphite } from '@stoplight/graphite/graphite';
import { createOas2HttpPlugin } from '@stoplight/graphite/plugins/http/oas2';
Expand All @@ -14,7 +15,7 @@ import { createOas3Plugin } from '@stoplight/graphite/plugins/oas3';
import { createYamlPlugin } from '@stoplight/graphite/plugins/yaml';
import { IHttpOperation } from '@stoplight/types';
import * as fs from 'fs';
import { extname, resolve } from 'path';
import { resolve } from 'path';

import { compact } from 'lodash';

Expand All @@ -37,8 +38,8 @@ export class GraphFacade {

public async createFilesystemNode(fsPath: string) {
const resourceFile = resolve(fsPath);
const language = extname(resourceFile).slice(1);
const stat = fs.lstatSync(resourceFile);

if (stat.isDirectory()) {
this.graphite.graph.addNode({
category: NodeCategory.Source,
Expand All @@ -50,7 +51,7 @@ export class GraphFacade {
this.graphite.graph.addNode({
category: NodeCategory.Source,
type: FilesystemNodeType.File,
language,
language: filenameToLanguage(resourceFile),
path: resourceFile,
});
this.fsBackend.readFile(resourceFile);
Expand Down

0 comments on commit cbc96b2

Please sign in to comment.