Skip to content

Commit

Permalink
fix: expose detectInFileList
Browse files Browse the repository at this point in the history
  • Loading branch information
bodinsamuel committed Oct 27, 2023
1 parent faa2865 commit e2978a9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
loadAllRules,
loadOne,
} from './loader.js';
import { matchAllFiles } from './matchAllFiles.js';
import { matchDependencies } from './matchDependencies.js';
import {
flatten,
Expand Down Expand Up @@ -84,6 +85,7 @@ export const dependencies = {
};

export const tech = {
detectInFileList: matchAllFiles,
indexed: listIndexed,
list: listTech,
keys: registeredTech,
Expand Down
20 changes: 20 additions & 0 deletions src/matchAllFiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { rulesTechs } from './loader.js';

import type { AllowedKeys, ProviderFile } from './index.js';

export function matchAllFiles(
files: ProviderFile[],
basePath: string
): Map<AllowedKeys, string[]> {
const matched = new Map<AllowedKeys, string[]>();
for (const rule of rulesTechs) {
const res = rule(files);
if (!res) {
continue;
}

matched.set(res[0].tech, [`matched file: ${res[1].replace(basePath, '')}`]);
}

return matched;
}
15 changes: 5 additions & 10 deletions src/payload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import path from 'node:path';

import { detectLang } from '../common/languages.js';
import { nid } from '../common/nid.js';
import { rulesComponents, rulesTechs } from '../loader.js';
import { rulesComponents } from '../loader.js';
import { matchAllFiles } from '../matchAllFiles.js';
import type { BaseProvider } from '../provider/base.js';
import { IGNORED_DIVE_PATHS } from '../provider/base.js';
import { listIndexed, nameToKey } from '../register.js';
Expand Down Expand Up @@ -91,15 +92,9 @@ export class Payload implements Analyser {
}

// Detect Tech
for (const rule of rulesTechs) {
const res = rule(files);
if (!res) {
continue;
}

ctx.addTech(res[0].tech, [
`matched file: ${res[1].replace(provider.basePath, '')}`,
]);
const matched = matchAllFiles(files, provider.basePath);
for (const match of matched.entries()) {
ctx.addTech(match[0], match[1]);
}

// Recursively dive in folders
Expand Down

0 comments on commit e2978a9

Please sign in to comment.