aboutsummaryrefslogtreecommitdiff
path: root/docs/AddingAFormatter.md
blob: 8cd0bc97b331ce08c15e5fc914bec98f2ee679d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Adding a new formatter

- Add a `etc/config/compiler-explorer.local.properties` file

  - Add a new formatter under the `formatters` key
  - The new formatter can have the following keys: name, exe, styles, type, explicitVersion (to override version
    parsing), version (argument to get version info), versionRe (regex to filter out the right version info)
  - Add a `lib/formatters/<formatter>.ts` file using the template below, replacing `Type` and `type` as appropriate

    ```js
    import {UnprocessedExecResult} from '../../types/execution/execution.interfaces';
    import {BaseFormatter} from './base';
    import {FormatOptions} from './base.interfaces';

    export class TypeFormatter extends BaseFormatter {
      static get key() {
        return 'type';
      }
    }
    ```

  - The value returned by `key` above corresponds to the `type` property you set in the compiler-explorer properties
    configuration file.
  - Tweak `format(source: string, options: FormatOptions): Promise<UnprocessedExecResult>` and
    `isValidStyle(style: string): boolean` as necessary. See the JSDoc for `format` and the implementations for other
    formatters to get a further understanding of how to implement `format(source, options)`.

- Add your `TypeFormatter` to `lib/formatters/_all.ts` in alphabetical order

- You can check the output of http://localhost:10240/api/formats to be sure your formatter is there.

- Make an installer in the [infra](https://github.com/compiler-explorer/infra) repository. An example patch for adding
  an installer can be found [here](https://github.com/compiler-explorer/infra/pull/560)