Skip to content

Commit

Permalink
If the module is a single dts file, show it in the README
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed May 20, 2021
1 parent dd16981 commit 53d2b24
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/definitions-parser/src/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,9 @@ export class TypingsData extends PackageBase {
get files(): readonly string[] {
return this.data.files;
}
get dtsFiles(): readonly string[] {
return this.data.files.filter(f => f.endsWith(".d.ts"));
}
get license(): License {
return this.data.license;
}
Expand Down
14 changes: 11 additions & 3 deletions packages/publisher/src/generate-packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ async function generateTypingPackage(
await writeCommonOutputs(
typing,
createPackageJSON(typing, version, packages, Registry.NPM),
createReadme(typing),
createReadme(typing, packageFS),
Registry.NPM
);
await writeCommonOutputs(
typing,
createPackageJSON(typing, version, packages, Registry.Github),
createReadme(typing),
createReadme(typing, packageFS),
Registry.Github
);
await Promise.all(
Expand Down Expand Up @@ -258,7 +258,7 @@ export function createNotNeededPackageJSON(
return JSON.stringify(out, undefined, 4);
}

export function createReadme(typing: TypingsData): string {
export function createReadme(typing: TypingsData, packageJFS: FS): string {
const lines: string[] = [];
lines.push("# Installation");
lines.push(`> \`npm install --save ${typing.fullNpmName}\``);
Expand All @@ -275,6 +275,14 @@ export function createReadme(typing: TypingsData): string {
lines.push("# Details");
lines.push(`Files were exported from ${definitelyTypedURL}/tree/${sourceBranch}/types/${typing.subDirectoryPath}.`);

if (typing.dtsFiles.length === 1) {
const dts = typing.dtsFiles[0]
lines.push("## " + path.basename(dts))
lines.push("```ts")
lines.push(packageJFS.readFile(dts))
lines.push("```")
}

lines.push("");
lines.push("### Additional Details");
lines.push(` * Last updated: ${new Date().toUTCString()}`);
Expand Down

0 comments on commit 53d2b24

Please sign in to comment.