Skip to content

Commit

Permalink
tsd is now added to webpack output dir by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaid committed Jan 27, 2019
1 parent ae446be commit 0f99032
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.2.0",
"version": "1.3.0",
"scripts": {
"build:prod": "NODE_ENV=production webpack",
"build:dev": "webpack",
Expand Down Expand Up @@ -50,4 +50,4 @@
"webpack-cli": "^3.2.1",
"webpack-config-jaid": "1.18.0"
}
}
}
21 changes: 18 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {exec} from "node-exec-promise"
import readPkgUp from "read-pkg-up"

const webpackId = "JsdocTsdWebpackPlugin"
const tsdFileName = "types.d.ts"

const getHtmlConfigPath = async (compiler, configBase, template, options, configDir) => {
const config = {
Expand All @@ -29,10 +30,16 @@ const getTsdConfigPath = async (compiler, configBase, template, options, configD
opts: {
...configBase.opts,
template,
destination: options.tsdOutputDir || path.join(compiler.context, "dist-jsdoc", "tsd"),
},
...options.jsdocTsdConfig,
}
if (options.tsdOutputFile) {
config.opts.destination = path.dirname(options.tsdOutputFile)
config.opts.outFile = path.basename(options.tsdOutputFile)
} else {
config.opts.destination = configDir
config.opts.outFile = tsdFileName
}
const configPath = path.join(configDir, "jsdoc-config-tsd.json")
fs.writeJsonSync(configPath, config)
return configPath
Expand All @@ -43,7 +50,7 @@ export default class {
constructor(options) {
this.options = {
htmlOutputDir: null,
tsdOutputDir: null,
tsdOutputFile: null,
readmePath: null,
packagePath: null,
jsdocConfig: {},
Expand Down Expand Up @@ -142,7 +149,15 @@ export default class {
])

const jsdocJobs = [htmlConfigPath, tsdConfigPath].map(configPath => exec(`node "${jsdocPath}" --configure "${configPath}"`))
const execResults = await Promise.all(jsdocJobs)
await Promise.all(jsdocJobs)

if (!this.options.tsdOutputFile) {
const tsdContent = fs.readFileSync(path.join(tempDir, tsdFileName))
compilation.assets[tsdFileName] = {
source: () => tsdContent,
size: () => tsdContent.length,
}
}
})
}

Expand Down
2 changes: 1 addition & 1 deletion webpack.config.babel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import webpackConfigJaid from "webpack-config-jaid"

export default webpackConfigJaid({
type: "lib",
type: "libClass",
include: [
"license.*",
"readme.md",
Expand Down

0 comments on commit 0f99032

Please sign in to comment.