Skip to content

Commit 5efa462

Browse files
committed
add dist
1 parent a5d0fcd commit 5efa462

File tree

4 files changed

+403
-15
lines changed

4 files changed

+403
-15
lines changed

dist/index.js

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
'use strict';
2+
3+
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
4+
5+
/* eslint-disable arrow-body-style */
6+
7+
var graphqlHTTP = require('express-graphql');
8+
9+
var _require = require('graphql'),
10+
buildSchema = _require.buildSchema;
11+
12+
var fetch = require('node-fetch');
13+
14+
var schema = buildSchema('\n type Registry {\n href: String\n ocVersion: String\n type: String\n }\n\n type Component {\n name: String\n description: String\n version: String\n }\n\n type Query {\n registry: Registry\n component(name: String): Component\n components: [Component]\n }\n');
15+
16+
var fetchComponent = function () {
17+
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(url) {
18+
return regeneratorRuntime.wrap(function _callee$(_context) {
19+
while (1) {
20+
switch (_context.prev = _context.next) {
21+
case 0:
22+
return _context.abrupt('return', fetch(url).then(function (response) {
23+
return response.json();
24+
}).then(function (data) {
25+
return data;
26+
}));
27+
28+
case 1:
29+
case 'end':
30+
return _context.stop();
31+
}
32+
}
33+
}, _callee, undefined);
34+
}));
35+
36+
return function fetchComponent(_x) {
37+
return _ref.apply(this, arguments);
38+
};
39+
}();
40+
41+
var makeComponent = function () {
42+
var _ref2 = _asyncToGenerator(regeneratorRuntime.mark(function _callee2(baseUrl, name) {
43+
var url, info, copy;
44+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
45+
while (1) {
46+
switch (_context2.prev = _context2.next) {
47+
case 0:
48+
url = '' + baseUrl + name + '/~info';
49+
_context2.next = 3;
50+
return fetchComponent(url);
51+
52+
case 3:
53+
info = _context2.sent;
54+
copy = Object.assign({}, info);
55+
return _context2.abrupt('return', copy);
56+
57+
case 6:
58+
case 'end':
59+
return _context2.stop();
60+
}
61+
}
62+
}, _callee2, undefined);
63+
}));
64+
65+
return function makeComponent(_x2, _x3) {
66+
return _ref2.apply(this, arguments);
67+
};
68+
}();
69+
70+
var root = function root(options) {
71+
return {
72+
registry: function () {
73+
var _ref3 = _asyncToGenerator(regeneratorRuntime.mark(function _callee3() {
74+
return regeneratorRuntime.wrap(function _callee3$(_context3) {
75+
while (1) {
76+
switch (_context3.prev = _context3.next) {
77+
case 0:
78+
return _context3.abrupt('return', fetch(options.baseUrl).then(function (response) {
79+
return response.json();
80+
}).then(function (data) {
81+
return {
82+
href: data.href,
83+
ocVersion: data.ocVersion,
84+
type: data.type
85+
};
86+
}));
87+
88+
case 1:
89+
case 'end':
90+
return _context3.stop();
91+
}
92+
}
93+
}, _callee3, undefined);
94+
}));
95+
96+
return function registry() {
97+
return _ref3.apply(this, arguments);
98+
};
99+
}(),
100+
components: function () {
101+
var _ref4 = _asyncToGenerator(regeneratorRuntime.mark(function _callee4() {
102+
return regeneratorRuntime.wrap(function _callee4$(_context4) {
103+
while (1) {
104+
switch (_context4.prev = _context4.next) {
105+
case 0:
106+
return _context4.abrupt('return', fetch(options.baseUrl).then(function (response) {
107+
return response.json();
108+
}).then(function (data) {
109+
return data.components.map(function (component) {
110+
var name = component.replace(options.baseUrl, '');
111+
return makeComponent(options.baseUrl, name);
112+
});
113+
}));
114+
115+
case 1:
116+
case 'end':
117+
return _context4.stop();
118+
}
119+
}
120+
}, _callee4, undefined);
121+
}));
122+
123+
return function components() {
124+
return _ref4.apply(this, arguments);
125+
};
126+
}(),
127+
component: function () {
128+
var _ref5 = _asyncToGenerator(regeneratorRuntime.mark(function _callee5(_ref6) {
129+
var name = _ref6.name;
130+
return regeneratorRuntime.wrap(function _callee5$(_context5) {
131+
while (1) {
132+
switch (_context5.prev = _context5.next) {
133+
case 0:
134+
return _context5.abrupt('return', makeComponent(options.baseUrl, name));
135+
136+
case 1:
137+
case 'end':
138+
return _context5.stop();
139+
}
140+
}
141+
}, _callee5, undefined);
142+
}));
143+
144+
return function component(_x4) {
145+
return _ref5.apply(this, arguments);
146+
};
147+
}()
148+
};
149+
};
150+
151+
var factory = function factory(options) {
152+
return graphqlHTTP({
153+
schema: schema,
154+
rootValue: root(options),
155+
graphiql: options.graphiql
156+
});
157+
};
158+
159+
module.exports = factory;

index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
require('babel-core/register');
2-
require('babel-polyfill');
3-
4-
module.exports = require('./src');
1+
module.exports = require('./dist');

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "OpenComponent Registry GraphQL Express middleware.",
55
"main": "index.js",
66
"scripts": {
7+
"compile": "babel src --out-dir dist",
78
"npm-check": "npm-check",
89
"test": "jest --coverage"
910
},
@@ -28,6 +29,7 @@
2829
},
2930
"homepage": "https://github.com/opencomponents/oc-registry-graphql-express-middleware#readme",
3031
"devDependencies": {
32+
"babel-cli": "^6.24.1",
3133
"babel-core": "^6.24.1",
3234
"babel-eslint": "^7.2.3",
3335
"babel-polyfill": "^6.23.0",

0 commit comments

Comments
 (0)