Skip to content

Commit

Permalink
feat: adding support for beta language flags in cli
Browse files Browse the repository at this point in the history
  • Loading branch information
shir lupo authored and shirlupo committed Mar 9, 2022
1 parent c43c279 commit aa84f69
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export async function analyzeFolders(options: FileAnalysisOptions): Promise<File
const fileBundle = await createBundleFromFolders({
...options.connection,
...options.fileOptions,
languages: options.languages,
});
if (fileBundle === null) return null;

Expand Down
28 changes: 22 additions & 6 deletions src/bundles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,32 @@ interface CreateBundleFromFoldersOptions extends ConnectionOptions, AnalyzeFolde
* @param source
* @returns
*/
async function getSupportedFiles(baseURL: string, source: string, requestId?: string): Promise<SupportedFiles> {
async function getSupportedFiles(
baseURL: string,
source: string,
requestId?: string,
languages?: string[],
): Promise<SupportedFiles> {
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 {
Expand All @@ -208,10 +225,9 @@ export interface FileBundle extends RemoteBundle {
*/
export async function createBundleFromFolders(options: CreateBundleFromFoldersOptions): Promise<FileBundle | null> {
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),
]);
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/analysis-options.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit aa84f69

Please sign in to comment.