Skip to content

Commit

Permalink
fix(core): should generate correct output path for docs #295 (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
why520crazy committed Dec 19, 2021
1 parent abd804d commit 5e18a3a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
30 changes: 15 additions & 15 deletions packages/core/src/builders/doc-file.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('DocSourceFile', () => {
let docgeniHost: DocgeniHost;

beforeEach(() => {
root = '/root/test/';
root = '/D/root/test/';
testHost = new virtualFs.test.TestHost({});
docgeniHost = new DocgeniHostImpl(new virtualFs.ScopedHost(testHost, normalize(root)));
});
Expand Down Expand Up @@ -87,9 +87,9 @@ describe('DocSourceFile', () => {
});

it('should get correct outputDir', async () => {
const outputRootPath = '/dest/path';
const outputRootPath = '/D/dest/path';
const outDir = docSourceFile.getOutputDir(outputRootPath);
expect(outDir).toEqual(path.resolve(outputRootPath, 'docs'));
expect(outDir).toEqual(`${outputRootPath}/docs`);
});

it('should get correct relativeOutputPath', async () => {
Expand All @@ -103,15 +103,15 @@ describe('DocSourceFile', () => {
});

it('should get correct outPath', async () => {
const outputRootPath = '/dest/path';
const outputRootPath = '/D/dest/path';
const outPath = docSourceFile.getOutputPath(outputRootPath);
expect(outPath).toEqual(path.resolve(outputRootPath, `docs/getting-started.html`));
expect(outPath).toEqual(`${outputRootPath}/docs/getting-started.html`);
});

it(`should get correct outPath when ext = '.htm'`, async () => {
const outputRootPath = '/dest/path';
const outputRootPath = '/D/dest/path';
const outPath = docSourceFile.getOutputPath(outputRootPath, '.htm');
expect(outPath).toEqual(path.resolve(outputRootPath, `docs/getting-started.htm`));
expect(outPath).toEqual(`${outputRootPath}/docs/getting-started.htm`);
});
});

Expand Down Expand Up @@ -151,8 +151,8 @@ describe('DocSourceFile', () => {
docgeniHost
);
await docSourceFile.build();
await docSourceFile.emit('/dest/root');
const outputFilePath = path.resolve(`/dest/root/`, `docs/getting-started.html`);
await docSourceFile.emit('/D/dest/root');
const outputFilePath = `/D/dest/root/docs/getting-started.html`;
expect(await docgeniHost.pathExists(outputFilePath)).toBeTruthy();
const outputContent = await docgeniHost.readFile(outputFilePath);
expect(outputContent).toContain(`<p>content</p>`);
Expand All @@ -173,8 +173,8 @@ describe('DocSourceFile', () => {
docgeniHost
);
await docSourceFile.build();
await docSourceFile.emit('/dest/root');
const outputFilePath = path.resolve(`/dest/root/`, `docs/getting-started.html`);
await docSourceFile.emit('/D/dest/root');
const outputFilePath = `/D/dest/root/docs/getting-started.html`;
expect(await docgeniHost.pathExists(outputFilePath)).toBeTruthy();
await docSourceFile.clear();
expect(await docgeniHost.pathExists(outputFilePath)).toBeFalsy();
Expand All @@ -195,13 +195,13 @@ describe('DocSourceFile', () => {
docgeniHost
);
await docSourceFile.build();
await docSourceFile.emit('/dest/root');
const outputFilePath = path.resolve(`/dest/root/`, `docs/getting-started.html`);
await docSourceFile.emit('/D/dest/root');
const outputFilePath = `/D/dest/root/docs/getting-started.html`;
expect(await docgeniHost.pathExists(outputFilePath)).toBeTruthy();
await docSourceFile.build();
await docSourceFile.emit('/dest/root2');
await docSourceFile.emit('/D/dest/root2');
expect(await docgeniHost.pathExists(outputFilePath)).toBeFalsy();
expect(await docgeniHost.pathExists(path.resolve(`/dest/root2/docs/getting-started.html`))).toBeTruthy();
expect(await docgeniHost.pathExists(`/D/dest/root2/docs/getting-started.html`)).toBeTruthy();
});

it('should get correct isEmpty', async () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/builders/doc-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { DocType } from '../enums';
import { Markdown } from '../markdown';
import { normalize, relative } from '@angular-devkit/core';
import { DocgeniHost } from '../docgeni-host';
import { resolve } from '../fs';
import { HeadingLink } from '../interfaces';

export interface DocSourceFileOptions {
Expand Down Expand Up @@ -122,11 +123,11 @@ export class DocSourceFile<TMeta extends DocMeta = DocMeta> {
}

public getOutputDir(outputRootPath: string) {
return path.resolve(outputRootPath, this.relativeDirname);
return resolve(outputRootPath, this.relativeDirname);
}

public getOutputPath(outputRootPath: string, ext = '.html') {
return path.resolve(this.getOutputDir(outputRootPath), this.name + ext);
return resolve(this.getOutputDir(outputRootPath), this.name + ext);
}

public getRelativeOutputPath(ext = '.html') {
Expand Down
28 changes: 25 additions & 3 deletions packages/core/src/builders/docs-builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,34 @@ describe('#components-builder', () => {
let context: DocgeniContext;
beforeEach(() => {
context = createTestDocgeniContext({
[`${DEFAULT_TEST_ROOT_PATH}/docs/index.md`]: 'index',
[`${DEFAULT_TEST_ROOT_PATH}/docs/guides/index.md`]: 'guides',
[`${DEFAULT_TEST_ROOT_PATH}/docs/guides/hello.md`]: 'hello'
initialFiles: {
[`${DEFAULT_TEST_ROOT_PATH}/docs/index.md`]: 'index',
[`${DEFAULT_TEST_ROOT_PATH}/docs/guides/index.md`]: 'guides',
[`${DEFAULT_TEST_ROOT_PATH}/docs/guides/hello.md`]: 'hello'
}
});
});

it('should emit docs success', async () => {
const docsBuilder = new DocsBuilder(context);
const globSyncSyp = spyOn(toolkit.fs, 'globSync');
const docFiles = ['index.md', 'guides/index.md', 'guides/hello.md'];
globSyncSyp.and.returnValue(
docFiles.map(docFile => {
return `${DEFAULT_TEST_ROOT_PATH}/docs/${docFile}`;
})
);
await docsBuilder.initialize();
await docsBuilder.build();
await docsBuilder.emit();

for (const docFile of docFiles) {
const distFullPath = `${context.paths.absSiteAssetsContentDocsPath}/${docFile.replace('.md', '.html')}`;
const isExists = await context.host.exists(distFullPath);
expect(isExists).toEqual(true, `doc file ${docFile} is not exist`);
}
});

it('should watch success', async () => {
const docsBuilder = new DocsBuilder(context);
await docsBuilder.initialize();
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@
magic-string "0.25.7"
rxjs "6.6.3"
source-map "0.7.3"

"@angular-devkit/core@7.1.4":
version "7.1.4"
resolved "https://registry.npmjs.org/@angular-devkit/core/-/core-7.1.4.tgz#4d903fd2ecc259b716ae76da19695d03993e583c"
Expand Down Expand Up @@ -2474,6 +2473,7 @@
"@angular-devkit/schematics" "11.2.15"
jsonc-parser "3.0.0"


"@schematics/schematics@0.11.4":
version "0.11.4"
resolved "https://registry.npmjs.org/@schematics/schematics/-/schematics-0.11.4.tgz#6976e1e25ac98a7adc88ec98f1347564af86ef86"
Expand Down

0 comments on commit 5e18a3a

Please sign in to comment.