Feat: Support bundlers (#783)

With this change, we support code bundlers, such as webpack.
Fixes: https://github.com/elastic/elasticsearch-js/issues/781
This commit is contained in:
Tomas Della Vedova
2019-03-19 07:50:05 +01:00
committed by GitHub
parent 532ded5d5c
commit 3b41c555ae
2 changed files with 416 additions and 414 deletions

View File

@ -17,6 +17,8 @@
* under the License.
*/
/* eslint-disable no-template-curly-in-string */
'use strict'
const { readdirSync } = require('fs')
@ -63,12 +65,12 @@ function genFactory (folder) {
.reduce((acc, val) => {
const obj = {
[val]: acc === null
? `lazyLoad('./api/${file}', opts)` // `${name}(opts)`
? `lazyLoad('${file.slice(0, -3)}', opts)` // `${name}(opts)`
: acc
}
if (isSnakeCased(val)) {
obj[camelify(val)] = acc === null
? `lazyLoad('./api/${file}', opts)` // `${name}(opts)`
? `lazyLoad('${file.slice(0, -3)}', opts)` // `${name}(opts)`
: acc
}
return obj
@ -138,7 +140,7 @@ function genFactory (folder) {
var fn = null
return function _lazyLoad (params, options, callback) {
if (fn === null) {
fn = require(file)(opts)
fn = require(${'`./api/${file}.js`'})(opts)
}
return fn(params, options, callback)
}