Skip to content

Commit

Permalink
chore(tsdocs): remove the workaround for constructor md file name
Browse files Browse the repository at this point in the history
We had to rename it from `(construcotr).md` to `_constructor_.md`.
Now it's fixed by microsoft/rushstack#1410.
  • Loading branch information
raymondfeng committed Jul 23, 2019
1 parent 2c11fff commit 742519c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
12 changes: 5 additions & 7 deletions packages/tsdocs/src/__tests__/acceptance/tsdocs.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import pEvent from 'p-event';
import * as path from 'path';
import {runExtractorForMonorepo, updateApiDocs} from '../..';
import {runExtractorForPackage} from '../../monorepo-api-extractor';
import {fixConstructorName} from '../../update-api-md-docs';

const runCLI = require('@loopback/build').runCLI;

Expand All @@ -23,7 +22,9 @@ describe('tsdocs', function() {

const API_MD_FILES = [
'pkg1.md',
'pkg1.pet.(constructor).md',
// It was `'pkg1.pet._constructor_.md'` before
// https://github.com/microsoft/web-build-tools/pull/1410
'pkg1.pet._constructor_.md',
'pkg1.pet.greet.md',
'pkg1.pet.kind.md',
'pkg1.pet.md',
Expand Down Expand Up @@ -102,10 +103,7 @@ describe('tsdocs', function() {
});

const files = await fs.readdir(SITE_APIDOCS_ROOT);
expect(files.sort()).to.eql([
'index.md',
...API_MD_FILES.map(fixConstructorName),
]);
expect(files.sort()).to.eql(['index.md', ...API_MD_FILES]);

for (const f of files) {
const md = await fs.readFile(path.join(SITE_APIDOCS_ROOT, f), 'utf-8');
Expand Down Expand Up @@ -135,6 +133,6 @@ permalink: /doc/en/lb4/apidocs.index.html
path.join(SITE_APIDOCS_ROOT, 'pkg1.pet._constructor_.md'),
'utf-8',
);
expect(constructorDoc).to.not.match(/\.\(constructor\)/);
expect(constructorDoc).to.not.match(/\.\(constructor\).md/);
});
});
18 changes: 4 additions & 14 deletions packages/tsdocs/src/update-api-md-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ async function addJekyllMetadata(
}

const docFile = path.join(apiDocsRoot, f);
const targetDocFile = path.join(apiDocsRoot, fixConstructorName(f));
let doc = await fs.readFile(docFile, 'utf-8');

if (isPackage && options.generateDefaultPackageDoc) {
Expand All @@ -146,7 +145,9 @@ async function addJekyllMetadata(
const model = await fs.readJson(modelFile, {encoding: 'utf-8'});
debug('Package %s', name, model);
if (model.kind === 'Package' && !model.docComment) {
const pkgDoc = `[${model.canonicalReference}](https://github.com/strongloop/loopback-next/tree/master/packages/${name})`;
const pkgDoc = `[${
model.canonicalReference
}](https://github.com/strongloop/loopback-next/tree/master/packages/${name})`;
doc = doc.replace(
`## ${name} package`,
`## ${name} package\n\n${pkgDoc}`,
Expand All @@ -165,20 +166,9 @@ permalink: /doc/en/lb4/apidocs.${name}.html
${doc}
`;

// Fix `*.(constructor)`
doc = fixConstructorName(doc);

if (!options.dryRun) {
await fs.writeFile(targetDocFile, doc, 'utf-8');
if (targetDocFile !== docFile) {
await fs.remove(docFile);
}
await fs.writeFile(docFile, doc, 'utf-8');
}
}
return true;
}

// Fix `*.(constructor)`
export function fixConstructorName(name: string) {
return name.replace(/\.\(constructor\)/g, '._constructor_');
}

0 comments on commit 742519c

Please sign in to comment.