@otris/jsdoc-tsd
Version:
JSDoc Template for generate typescript definition files from JSDoc comments
83 lines (82 loc) • 3.2 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.publish = void 0;
var fs = __importStar(require("fs"));
var helper = __importStar(require("jsdoc/util/templateHelper"));
var path = __importStar(require("path"));
var shelljs = __importStar(require("shelljs"));
var Configuration_1 = require("./Configuration");
var jsdoc_tsd_parser_1 = require("./jsdoc-tsd-parser");
/**
* Entry-Point of jsdoc. Gets called by the jsdoc-module to generate the docs.
* @param {TAFFY} data - The TaffyDB containing the data that jsdoc parsed.
* @param {*} opts - Options passed into jsdoc.
*/
function publish(data, opts) {
// remove undocumented stuff.
data({ undocumented: true }).remove();
// remove members that will not be included in the output
data = helper.prune(data);
// get the jsdoc results
var jsdocResults = data().get();
var parser;
if (opts.configure) {
var config = new Configuration_1.Configuration(opts.configure);
parser = new jsdoc_tsd_parser_1.JSDocTsdParser(config);
}
else {
parser = new jsdoc_tsd_parser_1.JSDocTsdParser();
}
// parse the results
parser.parse(jsdocResults);
// Write the output
var outputDir, outputFilePath;
if (opts.destination.endsWith(".d.ts")) {
outputFilePath = opts.destination;
outputDir = path.dirname(outputFilePath);
}
else {
outputDir = opts.destination;
outputFilePath = path.join(outputDir, "jsdoc-results.d.ts");
}
if (!fs.existsSync(outputDir)) {
try {
shelljs.mkdir("-p", outputDir);
}
catch (err) {
throw new Error("Can't create output directory '" + outputDir + "': " + err);
}
}
try {
fs.writeFileSync(outputFilePath, parser.generateTypeDefinition());
}
catch (err) {
var error = err instanceof Error ? err : new Error("" + err);
error.message = "Can't write results to file '" + outputFilePath + "': " + error.message;
throw error;
}
}
exports.publish = publish;
;