* build: add @biomejs/biome as a dependency * chore: add biome extension to vscode recommendations * chore: migrate from prettier to biome for code formatting Update VSCode settings to use Biome as the default formatter for multiple languages Add Biome to code actions on save and reorder search exclude patterns * build: add biome.json configuration file for code formatting * build: migrate from prettier to biome for formatting Update package.json scripts and biome.json configuration to use biome instead of prettier for code formatting. Adjust biome formatter includes/excludes patterns for better file matching. * refactor(eslint): remove unused prettier config and imports * chore: update biome.json configuration - Enable linter and set custom rules - Change jsxQuoteStyle to single quotes - Add json parser configuration - Set formatWithErrors to true * chore: migrate biome config from json to jsonc format The new jsonc format allows for comments in the configuration file, making it more maintainable and easier to document configuration choices. * style(biome): update ignore patterns and jsx quote style Update file ignore patterns from `/*` to `/**` for consistency Change jsxQuoteStyle from single to double quotes for alignment with project standards * refactor: simplify error type annotations from Error | any to any The change standardizes error handling by using 'any' type instead of union types with Error | any, making the code more consistent and reducing unnecessary type complexity. * chore: exclude tailwind.css from biome formatting * style: standardize quote usage and fix JSX formatting - Replace single quotes with double quotes in CSS imports and selectors - Fix JSX element closing bracket alignment and formatting - Standardize JSON formatting in package.json files * Revert "style: standardize quote usage and fix JSX formatting" This reverts commit0947f8505d. * fix: remove json import assertion for biome compatibility The import assertion syntax is not supported by biome, so it was replaced with a standard import statement. * style: change quote styles in biome.jsonc to use single quotes for JSX and double quotes for JS * style: change quote style from double to single in biome config * style: change JSX quote style from single to double * chore: update biome.jsonc to use single quotes for CSS formatting * chore: update biome config and format commands - Exclude tailwind.css from linter includes - Add biome lint to format commands * style: format JSX closing brackets for better readability * style: set bracketSameLine to true in biome config The change aligns with common JSX formatting preferences where brackets on the same line improve readability for many developers * Revert "style: format JSX closing brackets for better readability" This reverts commitd442c934ee. * style: format code and clean up whitespace - Remove unnecessary whitespace in CSS and TS files - Format package.json files to consistent style - Reorder tsconfig.json properties alphabetically - Improve code formatting in React components * style(biome): update biome.jsonc config with clearer comment Add explanation for keeping bracketSameLine as true to minimize changes in current PR while noting false would be better for future * chore: remove prettier dependency and format package.json files - Remove prettier from dependencies as it's no longer needed - Reformat package.json files for better readability * chore: replace prettier with biome for code formatting Remove all prettier-related configuration, dependencies, and references Update formatting scripts and documentation to use biome instead Adjust electron-builder config to exclude biome.jsonc * build: replace prettier with biome for formatting Use biome as the default formatter instead of prettier for better performance and modern tooling support * ci(i18n): replace prettier with biome for i18n formatting Update the auto-i18n workflow to use Biome instead of Prettier for formatting translated files. This change simplifies the dependencies by removing multiple Prettier plugins and using a single tool for formatting. * fix(i18n): Auto update translations for PR #10170 * style: format package.json files by consolidating array formatting Consolidate multi-line array formatting into single-line format for better readability and consistency across package.json files * Revert "fix(i18n): Auto update translations for PR #10170" This reverts commita7edd32efd. * ci(workflows): specify biome config path in auto-i18n workflow * chore: update biome.jsonc to use lexicographic sort order for json keys * ci(workflows): update biome format command to use --config-path flag * chore: exclude package.json from biome formatting * ci: update biome.jsonc linter configuration Update linter includes to target specific files and modify useSortedClasses rule * chore: reorder search exclude patterns in vscode settings * style(OGCard): reorder tailwind classes for consistent styling * fix(biome): update tailwind classes sorting to safe and warn level * docs(dev): update ide setup instructions in dev docs Replace Prettier with Biome as the recommended formatter and clarify editor options * build(extension-table-plus): replace prettier with biome for formatting - Add biome.json configuration file - Update package.json to use biome instead of prettier - Remove prettier from dependencies - Update lint script to use biome format * chore: replace biome.json with biome.jsonc for extended configuration Update biome configuration file to use JSONC format for comments and more detailed settings * chore: remove unused biome.jsonc configuration file --------- Co-authored-by: GitHub Action <action@github.com>
136 lines
4.5 KiB
TypeScript
136 lines
4.5 KiB
TypeScript
import { exec } from 'child_process'
|
|
import * as fs from 'fs/promises'
|
|
import * as linguistLanguages from 'linguist-languages'
|
|
import * as path from 'path'
|
|
import { promisify } from 'util'
|
|
|
|
const execAsync = promisify(exec)
|
|
|
|
type LanguageData = {
|
|
type: string
|
|
aliases?: string[]
|
|
extensions?: string[]
|
|
}
|
|
|
|
const LANGUAGES_FILE_PATH = path.join(__dirname, '../packages/shared/config/languages.ts')
|
|
|
|
/**
|
|
* Extracts and filters necessary language data from the linguist-languages package.
|
|
* @returns A record of language data.
|
|
*/
|
|
function extractAllLanguageData(): Record<string, LanguageData> {
|
|
console.log('🔍 Extracting language data from linguist-languages...')
|
|
const languages = Object.entries(linguistLanguages).reduce(
|
|
(acc, [name, langData]) => {
|
|
const { type, extensions, aliases } = langData as any
|
|
|
|
// Only include languages with extensions or aliases
|
|
if ((extensions && extensions.length > 0) || (aliases && aliases.length > 0)) {
|
|
acc[name] = {
|
|
type: type || 'programming',
|
|
...(extensions && { extensions }),
|
|
...(aliases && { aliases })
|
|
}
|
|
}
|
|
return acc
|
|
},
|
|
{} as Record<string, LanguageData>
|
|
)
|
|
console.log(`✅ Extracted ${Object.keys(languages).length} languages.`)
|
|
return languages
|
|
}
|
|
|
|
/**
|
|
* Generates the content for the languages.ts file.
|
|
* @param languages The language data to include in the file.
|
|
* @returns The generated file content as a string.
|
|
*/
|
|
function generateLanguagesFileContent(languages: Record<string, LanguageData>): string {
|
|
console.log('📝 Generating languages.ts file content...')
|
|
const sortedLanguages = Object.fromEntries(Object.entries(languages).sort(([a], [b]) => a.localeCompare(b)))
|
|
|
|
const languagesObjectString = JSON.stringify(sortedLanguages, null, 2)
|
|
|
|
const content = `/**
|
|
* Code language list.
|
|
* Data source: linguist-languages
|
|
*
|
|
* ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
|
|
* THIS FILE IS AUTOMATICALLY GENERATED BY A SCRIPT. DO NOT EDIT IT MANUALLY!
|
|
* Run \`yarn update:languages\` to update this file.
|
|
* ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
|
|
*
|
|
*/
|
|
|
|
type LanguageData = {
|
|
type: string;
|
|
aliases?: string[];
|
|
extensions?: string[];
|
|
};
|
|
|
|
export const languages: Record<string, LanguageData> = ${languagesObjectString};
|
|
`
|
|
console.log('✅ File content generated.')
|
|
return content
|
|
}
|
|
|
|
/**
|
|
* Formats a file using Biome.
|
|
* @param filePath The path to the file to format.
|
|
*/
|
|
async function format(filePath: string): Promise<void> {
|
|
console.log('🎨 Formatting file with Biome...')
|
|
try {
|
|
await execAsync(`yarn biome format --write ${filePath}`)
|
|
console.log('✅ Biome formatting complete.')
|
|
} catch (e: any) {
|
|
console.error('❌ Biome formatting failed:', e.stdout || e.stderr)
|
|
throw new Error('Biome formatting failed.')
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Checks a file with TypeScript compiler.
|
|
* @param filePath The path to the file to check.
|
|
*/
|
|
async function checkTypeScript(filePath: string): Promise<void> {
|
|
console.log('🧐 Checking file with TypeScript compiler...')
|
|
try {
|
|
await execAsync(`yarn tsc --noEmit --skipLibCheck ${filePath}`)
|
|
console.log('✅ TypeScript check passed.')
|
|
} catch (e: any) {
|
|
console.error('❌ TypeScript check failed:', e.stdout || e.stderr)
|
|
throw new Error('TypeScript check failed.')
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Main function to update the languages.ts file.
|
|
*/
|
|
async function updateLanguagesFile(): Promise<void> {
|
|
console.log('🚀 Starting to update languages.ts...')
|
|
try {
|
|
const extractedLanguages = extractAllLanguageData()
|
|
const fileContent = generateLanguagesFileContent(extractedLanguages)
|
|
|
|
await fs.writeFile(LANGUAGES_FILE_PATH, fileContent, 'utf-8')
|
|
console.log(`✅ Successfully wrote to ${LANGUAGES_FILE_PATH}`)
|
|
|
|
await format(LANGUAGES_FILE_PATH)
|
|
await checkTypeScript(LANGUAGES_FILE_PATH)
|
|
|
|
console.log('🎉 Successfully updated languages.ts file!')
|
|
console.log(`📊 Contains ${Object.keys(extractedLanguages).length} languages.`)
|
|
} catch (error) {
|
|
console.error('❌ An error occurred during the update process:', (error as Error).message)
|
|
// No need to restore backup as we write only at the end of successful generation.
|
|
process.exit(1)
|
|
}
|
|
}
|
|
|
|
if (require.main === module) {
|
|
updateLanguagesFile()
|
|
}
|
|
|
|
export { updateLanguagesFile }
|