From aa84f69f403e3676367236a66a43d21aae495cc0 Mon Sep 17 00:00:00 2001 From: shir lupo Date: Sun, 6 Mar 2022 18:38:29 +0200 Subject: [PATCH] feat: adding support for beta language flags in cli --- src/analysis.ts | 1 + src/bundles.ts | 28 +++++++++++++++----- src/interfaces/analysis-options.interface.ts | 2 ++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/analysis.ts b/src/analysis.ts index 35d1bb61..3ea0fbac 100644 --- a/src/analysis.ts +++ b/src/analysis.ts @@ -100,6 +100,7 @@ export async function analyzeFolders(options: FileAnalysisOptions): Promise { +async function getSupportedFiles( + baseURL: string, + source: string, + requestId?: string, + languages?: string[], +): Promise { emitter.supportedFilesLoaded(null); const resp = await getFilters(baseURL, source, undefined, requestId); if (resp.type === 'error') { throw resp.error; } - const supportedFiles = resp.value; - emitter.supportedFilesLoaded(supportedFiles); - return supportedFiles; + const supportedFilesFromApi = resp.value; + //Given supported languages from 'registy' + if (languages) { + let supportedFiles: SupportedFiles = {} as any; + supportedFiles.configFiles = supportedFilesFromApi.configFiles; + supportedFiles.extensions = languages; + //For verification only + supportedFiles.extensions = supportedFiles.extensions.filter(langExtension => + supportedFilesFromApi.extensions.includes(langExtension), + ); + emitter.supportedFilesLoaded(supportedFiles); + return supportedFiles; + } + emitter.supportedFilesLoaded(supportedFilesFromApi); + return supportedFilesFromApi; } export interface FileBundle extends RemoteBundle { @@ -208,10 +225,9 @@ export interface FileBundle extends RemoteBundle { */ export async function createBundleFromFolders(options: CreateBundleFromFoldersOptions): Promise { const baseDir = determineBaseDir(options.paths); - const [supportedFiles, fileIgnores] = await Promise.all([ // Fetch supporte files to save network traffic - getSupportedFiles(options.baseURL, options.source, options.requestId), + getSupportedFiles(options.baseURL, options.source, options.requestId, options.languages), // Scan for custom ignore rules collectIgnoreRules(options.paths, options.symlinksEnabled, options.defaultFileIgnores), ]); diff --git a/src/interfaces/analysis-options.interface.ts b/src/interfaces/analysis-options.interface.ts index 7d4e4e39..ceef9f96 100644 --- a/src/interfaces/analysis-options.interface.ts +++ b/src/interfaces/analysis-options.interface.ts @@ -31,12 +31,14 @@ export interface FileAnalysisOptions extends AnalysisContext { connection: ConnectionOptions; analysisOptions: AnalysisOptions; fileOptions: AnalyzeFoldersOptions; + languages?: string[]; } export interface AnalyzeFoldersOptions { paths: string[]; symlinksEnabled?: boolean; defaultFileIgnores?: string[]; + languages?: string[]; } export interface CollectBundleFilesOptions extends AnalyzeFoldersOptions {