Skip to content
This repository has been archived by the owner on Jun 15, 2024. It is now read-only.

Commit

Permalink
docs: update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jordimarimon committed Aug 11, 2023
1 parent 8ae5f31 commit ed990d9
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/assets/js/playground.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const dialogElCloseButton = document.getElementById('dialog-button-close');

const parseCode = async (code) => {
try {
return (await parseFromSource(code)).serialize();
return (await parseFromSource(code)).result.serialize();
} catch (error) {
console.error(error);
return {};
Expand Down
4 changes: 2 additions & 2 deletions docs/assets/js/preview.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ class Preview extends HTMLElement {
fetch(`${origin}${pathName}/assets/previews/${src}`)
.then(response => response.text())
.then(async (code) => {
const reflectedNodes = await parseFromSource(code);
return [code, reflectedNodes];
const {result} = await parseFromSource(code);
return [code, result];
})
.then(([code, reflectedNodes]) => {
const serializedNodes = JSON.stringify(reflectedNodes.serialize(), null, 4);
Expand Down
11 changes: 4 additions & 7 deletions docs/getting-started.njk
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ pnpm add -D @ts-ast-parser/core
{% highlight "ts" %}
import { parseFromProject } from '@ts-ast-parser/core';

const reflectedModules = parseFromProject({
/* You can optionally specify the TSConfig file path */
tsConfigFilePath: '<path>',
});
const {result, errors} = await parseFromProject(<options>);
{% endhighlight %}

<p class="text-md mb-4">
Expand All @@ -67,7 +64,7 @@ const reflectedModules = parseFromProject({
{% highlight "ts" %}
import { parseFromFiles } from '@ts-ast-parser/core';

const reflectedModules = parseFromFiles(['test1.ts', 'test2.ts']);
const {result, errors} = await parseFromFiles(['test1.ts', 'test2.ts'], <options>);
{% endhighlight %}

<p class="text-md mb-4">
Expand All @@ -77,7 +74,7 @@ const reflectedModules = parseFromFiles(['test1.ts', 'test2.ts']);
{% highlight "ts" %}
import { parseFromGlob } from '@ts-ast-parser/core';

const reflectedModules = parseFromGlob('**/*.ts');
const {result, errors} = await parseFromGlob('**/*.ts', <options>);
{% endhighlight %}

<p class="text-md mb-4">
Expand All @@ -87,7 +84,7 @@ const reflectedModules = parseFromGlob('**/*.ts');
{% highlight "ts" %}
import { parseFromSource } from '@ts-ast-parser/core';

const reflectedModules = parseFromSource('const foo = true;export { foo };');
const {result, errors} = await parseFromSource('const foo = true;export { foo };', <options>);
{% endhighlight %}

<p class="text mt-4">
Expand Down
8 changes: 8 additions & 0 deletions docs/overview.njk
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,17 @@ module: overview
<a href="https://vitepress.vuejs.org/" class="prose" target="_blank">VitePress</a>
</li>

<li>
<a href="https://sveltepress.site/" class="prose" target="_blank">Sveltepress</a>
</li>

<li>
<a href="https://modernjs.dev/doc-tools" class="prose" target="_blank">Modern.js Doc</a>
</li>

<li>
<a href="https://ng-doc.com/" class="prose" target="_blank">NgDoc</a>
</li>
</ul>

<p class="text text-md">
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/analyser-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import type { AnalyserSystem } from './analyser-system.js';
export interface AnalyserOptions {
/**
* Allows you to manually specify the path to a TSConfig file.
*
* Expects a relative path to the current working directory.
*/
tsConfigFilePath: string;

Expand Down Expand Up @@ -44,7 +42,7 @@ export interface AnalyserOptions {
jsProject: boolean;

/**
* An abstraction layer around how we interact with the environment (browser or Node.js)
* An abstraction layer around how the analyser interacts with the environment (browser or Node.js)
*/
system: AnalyserSystem;
}
4 changes: 4 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export * from './models/function.js';
export * from './models/import.js';
export * from './models/interface.js';
export * from './models/js-doc.js';
export * from './models/member.js';
export * from './models/member-kind.js';
export * from './models/mixin.js';
export * from './models/module.js';
Expand Down Expand Up @@ -47,6 +48,7 @@ export * from './nodes/named-import-node.js';
export * from './nodes/namespace-export-node.js';
export * from './nodes/namespace-import-node.js';
export * from './nodes/parameter-node.js';
export * from './nodes/project-node.js';
export * from './nodes/property-node.js';
export * from './nodes/re-export-node.js';
export * from './nodes/reflected-node.js';
Expand All @@ -59,6 +61,8 @@ export * from './nodes/variable-node.js';

// UTILS
export * from './analyser-options.js';
export * from './analyser-result.js';
export * from './analyser-system.js';
export * from './browser-system.js';
export * from './context.js';
export * from './node-system.js';
Expand Down
17 changes: 10 additions & 7 deletions scripts/docs/generate-api-reference.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Handlebars.registerHelper('typeWithReference', type => {
});

// Obtain the reflected modules
const reflectedModules = parseFromGlob('packages/core/src/**/*.ts');
const {result: reflectedModules} = await parseFromGlob('packages/core/src/**/*.ts');

// Handlebars templates
const {pathname: cwd} = new URL('../..', import.meta.url);
Expand Down Expand Up @@ -263,12 +263,14 @@ function createTypeAlias(typeAlias, category, filePath) {
function createFunctionContext(func, filePath) {
const signature = func.getSignatures()[0];
const funcJsDoc = func.isArrowFunctionOrFunctionExpression() ? func.getJSDoc() : signature.getJSDoc();
const returnType = signature.getReturnType().type;
const returnType = signature.getReturnType();
const returnTypeDescription = funcJsDoc.getTag(JSDocTagName.returns)?.getValue() ?? '';
const parameters = signature.getParameters().map(p => ({
name: p.getName(),
description: funcJsDoc.getAllTags(JSDocTagName.param)?.find(t => t.getName() === p.getName())?.getDescription() ?? '',
type: p.getType(),
type: {
text: p.getType().getText(),
},
default: p.getDefault(),
}));

Expand All @@ -277,11 +279,10 @@ function createFunctionContext(func, filePath) {
path: filePath,
line: signature.getLine(),
description: funcJsDoc.getTag(JSDocTagName.description)?.getValue() ?? '',
signature: `${func.getName()}(${parameters.map(p => `${p.name}: ${p.type.text}`).join(', ')}): ${returnType.text}`,
signature: `${func.getName()}(${parameters.map(p => `${p.name}: ${p.type.text}`).join(', ')}): ${returnType.getText()}`,
parameters,
returnType: {
text: returnType.text,
sources: returnType.sources,
text: returnType.getText(),
description: returnTypeDescription,
},
};
Expand All @@ -293,7 +294,9 @@ function createPropertyContext(property, filePath) {
path: filePath,
line: property.getLine(),
description: property.getJSDoc().getTag(JSDocTagName.description)?.getValue() ?? '',
type: property.getType(),
type: {
text: property.getType().getText(),
},
default: property.getDefault(),
optional: property.isOptional(),
};
Expand Down

0 comments on commit ed990d9

Please sign in to comment.