Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Generate local directory file using script
Browse files Browse the repository at this point in the history
  • Loading branch information
Dom Harrington committed Oct 23, 2017
1 parent 5250c7a commit b207ac8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ coverage
.idea/*
lerna-debug.log
.DS_Store
example/swagger-files/directory.json
13 changes: 3 additions & 10 deletions example/src/ApiList.jsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
const React = require('react');
const PropTypes = require('prop-types');

const localDirectory = require('../swagger-files/directory.json');

class ApiList extends React.Component {
constructor(props) {
super(props);
const petStore = '/swagger-files/petstore.json';
this.state = {
apis: {
petstore: {
preferred: '1.0.0',
versions: {
'1.0.0': {
swaggerUrl: petStore,
},
},
},
},
apis: localDirectory,
selected: petStore,
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.0",
"scripts": {
"test": "eslint -f unix example && lerna run test",
"example": "budo example/index.jsx --dir example -- -t babelify -p livereactload --extension .jsx",
"example": "node scripts/update-example-swagger-files && budo example/index.jsx --dir example -- -t babelify -p livereactload --extension .jsx",
"build": "watchify packages/api-explorer-ui/src/index.jsx -t [ babelify ] -o 'derequire > packages/api-explorer-ui/dist/index.js' --extension jsx --standalone ApiExplorer"
},
"publishConfig": {
Expand Down
23 changes: 23 additions & 0 deletions scripts/update-example-swagger-files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { join, basename } = require('path');
const { readdirSync, writeFileSync } = require('fs');

const dir = join(__dirname, '/../example/swagger-files/');
const files = readdirSync(dir);

const directory = files.filter(file => file !== 'directory.json').map((file) => {
// eslint-disable-next-line import/no-dynamic-require, global-require
const swagger = require(join(dir, file));

return {
[basename(file)]: {
preferred: swagger.info.version,
versions: {
[swagger.info.version]: {
swaggerUrl: join('/', 'swagger-files', file),
},
},
},
};
}).reduce((prev, next) => Object.assign(prev, next));

writeFileSync(join(__dirname, '../example/swagger-files/directory.json'), JSON.stringify(directory, null, 2));

0 comments on commit b207ac8

Please sign in to comment.