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:
committed by
delvedor
parent
1e55d2a099
commit
2504563480
4
.gitignore
vendored
4
.gitignore
vendored
@ -50,10 +50,6 @@ package-lock.json
|
|||||||
# elasticsearch repo or binary files
|
# elasticsearch repo or binary files
|
||||||
elasticsearch*
|
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/*
|
test/benchmarks/macro/fixtures/*
|
||||||
|
|
||||||
*-junit.xml
|
*-junit.xml
|
||||||
|
|||||||
2
index.d.ts
vendored
2
index.d.ts
vendored
@ -113,6 +113,7 @@ declare class Client extends EventEmitter {
|
|||||||
extend: ClientExtends;
|
extend: ClientExtends;
|
||||||
child(opts?: ClientOptions): Client;
|
child(opts?: ClientOptions): Client;
|
||||||
close(callback?: Function): Promise<void> | void;
|
close(callback?: Function): Promise<void> | void;
|
||||||
|
/* GENERATED */
|
||||||
bulk: ApiMethod<RequestParams.Bulk>
|
bulk: ApiMethod<RequestParams.Bulk>
|
||||||
cat: {
|
cat: {
|
||||||
aliases: ApiMethod<RequestParams.CatAliases>
|
aliases: ApiMethod<RequestParams.CatAliases>
|
||||||
@ -568,6 +569,7 @@ declare class Client extends EventEmitter {
|
|||||||
stop: ApiMethod<RequestParams.XpackWatcherStop>
|
stop: ApiMethod<RequestParams.XpackWatcherStop>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* /GENERATED */
|
||||||
}
|
}
|
||||||
|
|
||||||
declare const events: {
|
declare const events: {
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const { join } = require('path')
|
const { join } = require('path')
|
||||||
const { readdirSync, writeFileSync } = require('fs')
|
const { readdirSync, readFileSync, writeFileSync } = require('fs')
|
||||||
const minimist = require('minimist')
|
const minimist = require('minimist')
|
||||||
const semver = require('semver')
|
const semver = require('semver')
|
||||||
const ora = require('ora')
|
const ora = require('ora')
|
||||||
@ -32,7 +32,7 @@ function start (opts) {
|
|||||||
const packageFolder = join(__dirname, '..', 'api')
|
const packageFolder = join(__dirname, '..', 'api')
|
||||||
const apiOutputFolder = join(packageFolder, 'api')
|
const apiOutputFolder = join(packageFolder, 'api')
|
||||||
const mainOutputFile = join(packageFolder, 'index.js')
|
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 docOutputFile = join(__dirname, '..', 'docs', 'reference.asciidoc')
|
||||||
const requestParamsOutputFile = join(packageFolder, 'requestParams.d.ts')
|
const requestParamsOutputFile = join(packageFolder, 'requestParams.d.ts')
|
||||||
const allSpec = []
|
const allSpec = []
|
||||||
@ -64,9 +64,14 @@ function start (opts) {
|
|||||||
factory,
|
factory,
|
||||||
{ encoding: 'utf8' }
|
{ 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(
|
writeFileSync(
|
||||||
typesOutputFile,
|
typeDefFile,
|
||||||
types,
|
newTypeDefString,
|
||||||
{ encoding: 'utf8' }
|
{ encoding: 'utf8' }
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -82,7 +87,6 @@ function start (opts) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
log.succeed('Done!')
|
log.succeed('Done!')
|
||||||
console.log('Remember to copy the generated types into the index.d.ts file')
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -73,7 +73,13 @@ function genFactory (folder) {
|
|||||||
|
|
||||||
// serialize the type object
|
// serialize the type object
|
||||||
const typesStr = Object.keys(types)
|
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')
|
.join('\n')
|
||||||
// remove useless quotes and commas
|
// remove useless quotes and commas
|
||||||
.replace(/"/g, '')
|
.replace(/"/g, '')
|
||||||
|
|||||||
Reference in New Issue
Block a user