2020-04-06 11:17:22 +00:00
|
|
|
const fs = require('fs')
|
|
|
|
const ts = require('typescript')
|
|
|
|
const path = require('path')
|
|
|
|
const pkgJson = require('../package.json')
|
2020-03-03 08:36:04 +00:00
|
|
|
|
2020-04-06 11:17:22 +00:00
|
|
|
const rootDir = path.join(__dirname, '..')
|
2020-04-07 22:21:02 +00:00
|
|
|
const jsFile = path.join(rootDir, pkgJson.browser)
|
2020-04-06 11:17:22 +00:00
|
|
|
const dtsFile = path.join(rootDir, pkgJson.types)
|
2020-03-03 08:36:04 +00:00
|
|
|
|
|
|
|
const compilerOptions = {
|
2020-04-06 11:17:22 +00:00
|
|
|
declaration: true,
|
|
|
|
noEmit: false,
|
|
|
|
emitDeclarationOnly: true,
|
|
|
|
allowJs: true
|
|
|
|
}
|
2020-03-03 08:36:04 +00:00
|
|
|
|
2020-04-06 11:17:22 +00:00
|
|
|
const host = ts.createCompilerHost(compilerOptions)
|
2020-03-03 08:36:04 +00:00
|
|
|
|
2020-03-03 08:43:13 +00:00
|
|
|
host.writeFile = (fileName, contents) => {
|
2020-04-06 11:17:22 +00:00
|
|
|
fs.writeFileSync(dtsFile, contents)
|
|
|
|
}
|
2020-03-03 08:36:04 +00:00
|
|
|
|
2020-03-03 08:43:13 +00:00
|
|
|
// Prepare and emit the d.ts files
|
2020-04-06 11:17:22 +00:00
|
|
|
const program = ts.createProgram([jsFile], compilerOptions, host)
|
|
|
|
program.emit()
|