Skip to content

Commit a5aea99

Browse files
committed
add dist again
1 parent 467ffc4 commit a5aea99

File tree

3 files changed

+171
-1
lines changed

3 files changed

+171
-1
lines changed

dist/index.js

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

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
require('babel-core/register');
22
require('babel-polyfill');
33

4-
module.exports = require('./src');
4+
module.exports = require('./dist');

package.json

Lines changed: 1 addition & 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
},

0 commit comments

Comments
 (0)