Skip to content

Commit

Permalink
feat: refactored code and updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Sep 12, 2024
1 parent 0321100 commit 5923d61
Show file tree
Hide file tree
Showing 26 changed files with 2,106 additions and 2,263 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Editor configuration, see http://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2

[*.ts]
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false
insert_final_newline = false
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: ["16"]
node: ['18']
name: Node ${{ matrix.node }}
steps:
- name: Checkout repository
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
on:
push:
branches:
- main
name: release-please
jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: googleapis/release-please-action@v4
id: release
with:
release-type: node
# The logic below handles the npm publication:
- uses: actions/checkout@v4
# these if statements ensure that a publication only occurs when
# a new release is created:
if: ${{ steps.release.outputs.release_created }}
- uses: actions/setup-node@v4
with:
node-version: 12
registry-url: 'https://registry.npmjs.org'
if: ${{ steps.release.outputs.release_created }}
- run: npm ci
if: ${{ steps.release.outputs.release_created }}
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
if: ${{ steps.release.outputs.release_created }}
5 changes: 5 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": "all",
"plugins": ["prettier-plugin-organize-imports"]
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Tom Grey
Copyright (c) 2024 Tom Grey

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
110 changes: 99 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,119 @@ A plugin for [TypeDoc](https://github.com/TypeStrong/typedoc) that inlines sourc

[![npm](https://img.shields.io/npm/v/typedoc-plugin-inline-sources.svg)](https://www.npmjs.com/package/typedoc-plugin-inline-sources) [![Build Status](https://github.com/tgreyuk/typedoc-plugin-inline-sources/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/tgreyuk/typedoc-plugin-inline-sources/actions/workflows/ci.yml)

## What it does?
## Contents

The plugin retrieves the source from the ts compiler and injects within fenced code blocks.
- [Overview](#overview)
- [Installation](#installation)
- [Usage](#usage)
- [Documentation](#documentation)
- [`@source` Tag](#source-tag)
- [Displaying an alternative title](#displaying-an-alternative-title)
- [Handling "unknown block tag" warning](#handling-unknown-block-tag-warning)
- [License](#license)

## Overview

By default, when you generate documentation using TypeDoc, it includes a "Defined in" section at the bottom of each symbol, linking to the relevant line in the source file.

This plugin can be used if you additionally require the symbols source code to be included in the generated documentation.

## Installation

```bash
npm install --save-dev typedoc typedoc-plugin-inline-sources
npm install --save-dev typedoc-plugin-inline-sources
```

## Usage

Simply use the `@source` annotation in your comments. This will create a tag with the inlined source code.
Simply add the plugin to your `typedoc.json` or equivalent config file.

```json
{
"plugin": ["typedoc-plugin-inline-sources"]
}
```

## Documentation

### `@source` Tag

The **`@source`** tag is a custom documentation tag used to include the source code directly within the generated output documentation. This is particularly useful where you not only want to describe the functionality of a symbol but also display the actual code for reference.

### Code
Here’s an example of a function with the @source tag included:

```typescript
#### Typescript

```ts
/**
* Comments for variable
* Logs a greeting message to the console.
*
* @source source tag comment?
* @source Optional source comments
*/
export const message = "Hello World!";
export function greet(): void {
console.log('Hello, welcome to TypeScript!');
}
```

#### Output

<img src="images/example-1.png" style="max-width:700px">

### Displaying an alternative title

Block tags are output as "title case" headings in the final output. If you would like an alternative heading to "Source" you can replace locale entry for the tag:

```json
"locales": {
"en": {
"tag_source": "My Source Code"
}
}
```

### Output
### Handling "unknown block tag" warning

When using the tag, TypeDoc (since 0.26) will generate the following warning:

```shell
[warning] Encountered an unknown block tag @source
```

To suppress this warning you have two options.

#### 1. Using the `--blockTags` TypeDoc option:

You can extend the tag defaults by using a JavaScript configuration file:

```ts
import { OptionDefaults } from 'typedoc';

const config = {
blockTags: [...OptionDefaults.blockTags, '@source'],
};
```

See https://typedoc.org/options/comments/#blocktags.

#### 2. Adding a `tsdoc.json` file:

You add a `tsdoc.json` file next to your `tsconfig.json` file and include the `@source` tag name.

```json
{
"$schema": "https://developer.microsoft.com/en-us/json-schemas/tsdoc/v0/tsdoc.schema.json",
"extends": ["typedoc/tsdoc.json"],
"tagDefinitions": [
{
"tagName": "@source",
"syntaxKind": "block"
}
]
}
```

See https://typedoc.org/options/configuration/#tsconfig.

## License

![image](https://user-images.githubusercontent.com/11680870/120396197-0f726800-c32e-11eb-800e-8cf7466635bb.png)
MIT
15 changes: 15 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
{
rules: {
'no-undef': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/no-require-imports': 'off',
},
},
);
Binary file added images/example-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 12 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig.test.json',
},
],
},
verbose: true,
testTimeout: 30000,
detectOpenHandles: true,
forceExit: true,
};
Loading

0 comments on commit 5923d61

Please sign in to comment.