Updated automatically the main typings file with the generated t… (#919)

* Updated automatically the main typings file with the generated types

* Removed useless log
This commit is contained in:
Tomas Della Vedova
2019-07-25 10:57:47 +02:00
committed by delvedor
parent f74123fb53
commit 29ad0735c2
4 changed files with 18 additions and 10 deletions

4
.gitignore vendored
View File

@ -50,10 +50,6 @@ package-lock.json
# elasticsearch repo or binary files
elasticsearch*
# Generated typings, we don't commit them
# because we should copy them in the main .d.ts file
api/generated.d.ts
test/benchmarks/macro/fixtures/*
*-junit.xml

2
index.d.ts vendored
View File

@ -126,6 +126,7 @@ declare class Client extends EventEmitter {
extend: ClientExtends;
child(opts?: ClientOptions): Client;
close(callback?: Function): Promise<void> | void;
/* GENERATED */
bulk: ApiMethod<RequestParams.Bulk>
cat: {
aliases: ApiMethod<RequestParams.CatAliases>
@ -609,6 +610,7 @@ declare class Client extends EventEmitter {
info: ApiMethod<RequestParams.XpackInfo>
usage: ApiMethod<RequestParams.XpackUsage>
}
/* /GENERATED */
}
declare const events: {

View File

@ -20,7 +20,7 @@
'use strict'
const { join } = require('path')
const { readdirSync, writeFileSync } = require('fs')
const { readdirSync, readFileSync, writeFileSync } = require('fs')
const minimist = require('minimist')
const semver = require('semver')
const ora = require('ora')
@ -47,7 +47,7 @@ function start (opts) {
const packageFolder = join(__dirname, '..', 'api')
const apiOutputFolder = join(packageFolder, 'api')
const mainOutputFile = join(packageFolder, 'index.js')
const typesOutputFile = join(packageFolder, 'generated.d.ts')
const typeDefFile = join(__dirname, '..', 'index.d.ts')
const docOutputFile = join(__dirname, '..', 'docs', 'reference.asciidoc')
const requestParamsOutputFile = join(packageFolder, 'requestParams.d.ts')
const allSpec = []
@ -79,9 +79,14 @@ function start (opts) {
factory,
{ encoding: 'utf8' }
)
const oldTypeDefString = readFileSync(typeDefFile, 'utf8')
const start = oldTypeDefString.indexOf('/* GENERATED */')
const end = oldTypeDefString.indexOf('/* /GENERATED */')
const newTypeDefString = oldTypeDefString.slice(0, start + 15) + '\n' + types + '\n ' + oldTypeDefString.slice(end)
writeFileSync(
typesOutputFile,
types,
typeDefFile,
newTypeDefString,
{ encoding: 'utf8' }
)
@ -97,7 +102,6 @@ function start (opts) {
)
log.succeed('Done!')
console.log('Remember to copy the generated types into the index.d.ts file')
})
})

View File

@ -88,7 +88,13 @@ function genFactory (folder) {
// serialize the type object
const typesStr = Object.keys(types)
.map(key => `${key}: ${JSON.stringify(types[key], null, 2)}`)
.map(key => {
const line = ` ${key}: ${JSON.stringify(types[key], null, 4)}`
if (line.slice(-1) === '}') {
return line.slice(0, -1) + ' }'
}
return line
})
.join('\n')
// remove useless quotes and commas
.replace(/"/g, '')