-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdeployer.js
107 lines (86 loc) · 2.78 KB
/
deployer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
var Generator = require('generate-js'),
merge = require('deepmerge'),
Utils = require('./utils'),
async = require('async');
var APIDeploy = Generator.generate(function APIDeploy() {
var _ = this;
_.defineProperties({
plugins: {},
logger: Utils.logger
});
_.defineProperties({
writable: true
}, {
each: async.each
});
});
APIDeploy.definePrototype({
handlebars: Utils.handlebars,
registerPlugin: function registerPlugin(plugin) {
var _ = this;
if (!plugin.name) throw new Error('Please supply a plugin name.');
if (_.plugins[plugin.name]) console.warn('Plugin already exists. Overwriting: ' + plugin.name);
for (var i = 0; i < (plugin.requires || []).length; i++) {
if (!_.plugins[plugin.requires[i]]) {
throw new Error('`' + plugin.name + '` is missing required plugin: `' + plugin.requires[i] + '`. Maybe change the order in which they are registered?');
}
}
plugin.APIDeploy = _;
plugin.defineProperties({
writable: true,
enumerable: true,
configurable: true
}, {
sdk: merge(_.sdk || {}, plugin.sdk || {})
});
_.plugins[plugin.name] = plugin;
return plugin;
},
deployAPI: function deployAPI(pluginName, args, options, done) {
var _ = this,
plugin = _.plugins[pluginName];
options.pluginName = pluginName;
if (plugin) {
plugin._deployAPI(args, options, function(err, data) {
done && done(err, data);
});
} else {
throw new Error('No plugin found: ' + pluginName);
}
},
generateSDK: function generateSDK(pluginName, args, options, done) {
var _ = this,
plugin = _.plugins[pluginName];
options.pluginName = pluginName;
if (plugin) {
plugin._generateSDK(args, options, done);
} else {
throw new Error('No plugin found: ' + pluginName);
}
},
configure: function configure(options) {
var _ = this;
_.defineProperties({
writable: true,
enumerable: true,
configurable: true
}, options);
_.sdk = _.sdk || {};
_.swagger = _.swagger || {};
_.swagger.data = _.readSwagger();
_.sdk = merge({
path: './sdk.js'
}, _.sdk || {});
_.swagger = merge({
path: './swagger.json',
templates: {
resource: JSON.stringify({
'options': {}
})
}
}, _.swagger || {});
return _;
}
});
APIDeploy.definePrototype(require('./lib/swagger/generate'));
module.exports = APIDeploy;