feat: changed to provide entire linguist-js options object

Signed-off-by: Jos Craw <me.joscraw@gmail.com>
This commit is contained in:
Jos Craw
2023-03-03 08:15:37 +13:00
parent 9b3bc42f1c
commit 4eae508310
5 changed files with 23 additions and 14 deletions
+1 -1
View File
@@ -2,4 +2,4 @@
'@backstage/plugin-linguist-backend': patch
---
Added support for offline language data
Added support for linguist-js options.
+6 -3
View File
@@ -85,12 +85,15 @@ return createRouter({ schedule: schedule, age: { days: 30 } }, { ...env });
With the `age` setup like this if the language breakdown is older than 15 days it will get regenerated. It's recommended that if you choose to use this configuration to set it to a large value - 30, 90, or 180 - as this data generally does not change drastically.
## Offline
## Linguist JS options
The default setup will pull the language data from GitHub, by setting `offline` to `true` a packaged offline version of this data is used instead.
The default setup will use the default [linguist-js](https://www.npmjs.com/package/linguist-js) options, a full list of the available options can be found [here](https://www.npmjs.com/package/linguist-js#API).
```ts
return createRouter({ schedule: schedule, offline: true }, { ...env });
return createRouter(
{ schedule: schedule, linguistJsOptions: { offline: true } },
{ ...env },
);
```
## Use Source Location
+2 -2
View File
@@ -35,7 +35,7 @@ export class LinguistBackendApi {
batchSize?: number,
useSourceLocation?: boolean,
kind?: string[],
offline?: boolean,
linguistJsOptions?: Record<string, any>,
);
// (undocumented)
getEntityLanguages(entityRef: string): Promise<Languages>;
@@ -83,7 +83,7 @@ export interface PluginOptions {
// (undocumented)
kind?: string[];
// (undocumented)
offline?: boolean;
linguistJsOptions?: Record<string, any>;
// (undocumented)
schedule?: TaskScheduleDefinition;
// (undocumented)
@@ -57,7 +57,7 @@ export class LinguistBackendApi {
private readonly batchSize?: number;
private readonly useSourceLocation?: boolean;
private readonly kind: string[];
private readonly offline?: boolean;
private readonly linguistJsOptions?: Record<string, any>;
public constructor(
logger: Logger,
store: LinguistBackendStore,
@@ -68,7 +68,7 @@ export class LinguistBackendApi {
batchSize?: number,
useSourceLocation?: boolean,
kind?: string[],
offline?: boolean,
linguistJsOptions?: Record<string, any>,
) {
this.logger = logger;
this.store = store;
@@ -80,7 +80,7 @@ export class LinguistBackendApi {
this.age = age;
this.useSourceLocation = useSourceLocation;
this.kind = kindOrDefault(kind);
this.offline = offline;
this.linguistJsOptions = linguistJsOptions;
}
public async getEntityLanguages(entityRef: string): Promise<Languages> {
@@ -193,7 +193,7 @@ export class LinguistBackendApi {
const readTreeResponse = await this.urlReader.readTree(url);
const dir = await readTreeResponse.dir();
const results = await linguist(dir, { offline: this.offline });
const results = await linguist(dir, this.linguistJsOptions);
try {
const totalBytes = results.languages.bytes;
+10 -4
View File
@@ -38,7 +38,7 @@ export interface PluginOptions {
age?: HumanDuration;
batchSize?: number;
useSourceLocation?: boolean;
offline?: boolean;
linguistJsOptions?: Record<string, any>;
kind?: string[];
}
@@ -58,8 +58,14 @@ export async function createRouter(
pluginOptions: PluginOptions,
routerOptions: RouterOptions,
): Promise<express.Router> {
const { schedule, age, batchSize, useSourceLocation, kind, offline } =
pluginOptions;
const {
schedule,
age,
batchSize,
useSourceLocation,
kind,
linguistJsOptions,
} = pluginOptions;
const { logger, reader, database, discovery, scheduler, tokenManager } =
routerOptions;
@@ -80,7 +86,7 @@ export async function createRouter(
batchSize,
useSourceLocation,
kind,
offline,
linguistJsOptions,
);
if (scheduler && schedule) {