From 742519cdad0d10b870db9bd9966dc07972cbdce8 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Tue, 23 Jul 2019 08:47:02 -0700 Subject: [PATCH] chore(tsdocs): remove the workaround for constructor md file name We had to rename it from `(construcotr).md` to `_constructor_.md`. Now it's fixed by https://github.com/microsoft/web-build-tools/pull/1410. --- .../__tests__/acceptance/tsdocs.acceptance.ts | 12 +++++------- packages/tsdocs/src/update-api-md-docs.ts | 18 ++++-------------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/packages/tsdocs/src/__tests__/acceptance/tsdocs.acceptance.ts b/packages/tsdocs/src/__tests__/acceptance/tsdocs.acceptance.ts index 2210274b0912..17bd022b9f5a 100644 --- a/packages/tsdocs/src/__tests__/acceptance/tsdocs.acceptance.ts +++ b/packages/tsdocs/src/__tests__/acceptance/tsdocs.acceptance.ts @@ -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; @@ -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', @@ -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'); @@ -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/); }); }); diff --git a/packages/tsdocs/src/update-api-md-docs.ts b/packages/tsdocs/src/update-api-md-docs.ts index 0d4a8301a17f..545bc90be6e7 100644 --- a/packages/tsdocs/src/update-api-md-docs.ts +++ b/packages/tsdocs/src/update-api-md-docs.ts @@ -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) { @@ -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}`, @@ -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_'); -}