mirror of
https://github.com/dream-num/univer.git
synced 2026-09-01 15:29:43 +08:00
build: use regex for locale file name validation
This commit is contained in:
@@ -2,6 +2,8 @@ import { existsSync, readdirSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import process from 'node:process';
|
||||
|
||||
const LOCALE_FILE_NAME_PATTERN = /^[a-z]{2}-[A-Z]{2}\.ts$/;
|
||||
|
||||
export interface IDiscoverUniverUiLocalesOptions {
|
||||
rootDir?: string;
|
||||
uiPackageDir?: string;
|
||||
@@ -53,7 +55,7 @@ export function discoverUniverUiLocales(options: IDiscoverUniverUiLocalesOptions
|
||||
}
|
||||
|
||||
return readdirSync(localeDir, { withFileTypes: true })
|
||||
.filter((entry) => entry.isFile() && entry.name.endsWith('.ts'))
|
||||
.filter((entry) => entry.isFile() && LOCALE_FILE_NAME_PATTERN.test(entry.name))
|
||||
.map((entry) => path.basename(entry.name, '.ts'))
|
||||
.sort((left, right) => left.localeCompare(right));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user