mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[ts] Use correct typescript-formatter package
This commit is contained in:
parent
8972ba5dc8
commit
46e38c0356
@ -1,18 +1,18 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Format TypeScript files with Biome
|
||||
# Format TypeScript files with tsfmt
|
||||
echo "Formatting TypeScript files..."
|
||||
|
||||
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
||||
|
||||
# Check if biome.json files match
|
||||
if ! cmp -s ../spine-ts/biome.json ../tests/biome.json; then
|
||||
echo -e "\033[1;31mERROR: spine-ts/biome.json and tests/biome.json differ!\033[0m"
|
||||
# Check if tsfmt.json files match
|
||||
if ! cmp -s ../spine-ts/tsfmt.json ../tests/tsfmt.json; then
|
||||
echo -e "\033[1;31mERROR: spine-ts/tsfmt.json and tests/tsfmt.json differ!\033[0m"
|
||||
echo -e "\033[1;31mPlease sync them to ensure consistent formatting.\033[0m"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Format TypeScript files
|
||||
cd ../spine-ts && npx biome format --write . && cd ../formatters
|
||||
cd ../tests && npx biome format --write --config-path ../spine-ts . && cd ../formatters
|
||||
cd ../spine-ts && npm run format && cd ../formatters
|
||||
cd ../tests && npm run format -r && cd ../formatters
|
||||
@ -2,7 +2,7 @@ import { execSync } from 'node:child_process';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
|
||||
function findTypeScriptFiles(dir: string, files: string[] = []): string[] {
|
||||
function findTypeScriptFiles (dir: string, files: string[] = []): string[] {
|
||||
if (!fs.existsSync(dir)) return files;
|
||||
|
||||
fs.readdirSync(dir).forEach(name => {
|
||||
@ -32,7 +32,7 @@ fs.readdirSync('.').forEach(name => {
|
||||
|
||||
if (allFiles.length > 0) {
|
||||
console.log(`Formatting ${allFiles.length} TypeScript files...`);
|
||||
execSync(`npx tsfmt -r ${allFiles.join(' ')}`, { stdio: 'inherit' });
|
||||
execSync(`npx -y typescript-formatter -r ${allFiles.join(' ')}`, { stdio: 'inherit' });
|
||||
} else {
|
||||
console.log('No TypeScript files found to format.');
|
||||
}
|
||||
@ -4,7 +4,7 @@
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"compare": "tsx compare-with-reference-impl.ts",
|
||||
"format": "npx tsfmt -r ./**/*.ts",
|
||||
"format": "npx -y typescript-formatter -r ./**/*.ts",
|
||||
"lint": "npx biome lint ."
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@ -9,7 +9,7 @@ import type { LspCliResult, SymbolInfo } from '@mariozechner/lsp-cli';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
function ensureOutputDir(): string {
|
||||
function ensureOutputDir (): string {
|
||||
const outputDir = path.resolve(__dirname, '../output');
|
||||
if (!fs.existsSync(outputDir)) {
|
||||
fs.mkdirSync(outputDir, { recursive: true });
|
||||
@ -17,7 +17,7 @@ function ensureOutputDir(): string {
|
||||
return outputDir;
|
||||
}
|
||||
|
||||
function generateLspData(outputDir: string): string {
|
||||
function generateLspData (outputDir: string): string {
|
||||
const outputFile = path.join(outputDir, 'spine-libgdx-symbols.json');
|
||||
const projectDir = path.resolve(__dirname, '../../spine-libgdx');
|
||||
const srcDir = path.join(projectDir, 'spine-libgdx/src');
|
||||
@ -58,11 +58,11 @@ function generateLspData(outputDir: string): string {
|
||||
return outputFile;
|
||||
}
|
||||
|
||||
function analyzeClasses(symbols: SymbolInfo[]): Map<string, ClassInfo> {
|
||||
function analyzeClasses (symbols: SymbolInfo[]): Map<string, ClassInfo> {
|
||||
const classMap = new Map<string, ClassInfo>();
|
||||
const srcPath = path.resolve(__dirname, '../../spine-libgdx/spine-libgdx/src/');
|
||||
|
||||
function processSymbol(symbol: SymbolInfo, parentName?: string) {
|
||||
function processSymbol (symbol: SymbolInfo, parentName?: string) {
|
||||
if (symbol.kind !== 'class' && symbol.kind !== 'enum' && symbol.kind !== 'interface') return;
|
||||
|
||||
// Filter: only process symbols in spine-libgdx/src, excluding SkeletonSerializer
|
||||
@ -147,7 +147,7 @@ function analyzeClasses(symbols: SymbolInfo[]): Map<string, ClassInfo> {
|
||||
return classMap;
|
||||
}
|
||||
|
||||
function findAccessibleTypes(
|
||||
function findAccessibleTypes (
|
||||
classMap: Map<string, ClassInfo>,
|
||||
startingTypes: string[]
|
||||
): Set<string> {
|
||||
@ -156,7 +156,7 @@ function findAccessibleTypes(
|
||||
const visited = new Set<string>();
|
||||
|
||||
// Helper to find all concrete subclasses of a type
|
||||
function findConcreteSubclasses(typeName: string, addToQueue: boolean = true): string[] {
|
||||
function findConcreteSubclasses (typeName: string, addToQueue: boolean = true): string[] {
|
||||
const concreteClasses: string[] = [];
|
||||
|
||||
if (!classMap.has(typeName)) return concreteClasses;
|
||||
@ -281,7 +281,7 @@ function findAccessibleTypes(
|
||||
return accessible;
|
||||
}
|
||||
|
||||
function loadExclusions(): { types: Set<string>, methods: Map<string, Set<string>>, fields: Map<string, Set<string>> } {
|
||||
function loadExclusions (): { types: Set<string>, methods: Map<string, Set<string>>, fields: Map<string, Set<string>> } {
|
||||
const exclusionsPath = path.resolve(__dirname, '../java-exclusions.txt');
|
||||
const types = new Set<string>();
|
||||
const methods = new Map<string, Set<string>>();
|
||||
@ -329,11 +329,11 @@ function loadExclusions(): { types: Set<string>, methods: Map<string, Set<string
|
||||
return { types, methods, fields };
|
||||
}
|
||||
|
||||
function isTypeExcluded(typeName: string, exclusions: ReturnType<typeof loadExclusions>): boolean {
|
||||
function isTypeExcluded (typeName: string, exclusions: ReturnType<typeof loadExclusions>): boolean {
|
||||
return exclusions.types.has(typeName);
|
||||
}
|
||||
|
||||
function isPropertyExcluded(className: string, propertyName: string, isGetter: boolean, exclusions: ReturnType<typeof loadExclusions>): boolean {
|
||||
function isPropertyExcluded (className: string, propertyName: string, isGetter: boolean, exclusions: ReturnType<typeof loadExclusions>): boolean {
|
||||
if (isGetter) {
|
||||
return exclusions.methods.get(className)?.has(propertyName) || false;
|
||||
} else {
|
||||
@ -341,7 +341,7 @@ function isPropertyExcluded(className: string, propertyName: string, isGetter: b
|
||||
}
|
||||
}
|
||||
|
||||
function getAllProperties(classMap: Map<string, ClassInfo>, className: string, symbolsFile: string, exclusions: ReturnType<typeof loadExclusions>): PropertyInfo[] {
|
||||
function getAllProperties (classMap: Map<string, ClassInfo>, className: string, symbolsFile: string, exclusions: ReturnType<typeof loadExclusions>): PropertyInfo[] {
|
||||
const allProperties: PropertyInfo[] = [];
|
||||
const visited = new Set<string>();
|
||||
const classInfo = classMap.get(className);
|
||||
@ -351,7 +351,7 @@ function getAllProperties(classMap: Map<string, ClassInfo>, className: string, s
|
||||
const typeParamMap = new Map<string, string>();
|
||||
|
||||
// Helper to build parameter mappings for a specific supertype
|
||||
function buildTypeParamMapping(currentClass: string, targetSupertype: string): Map<string, string> {
|
||||
function buildTypeParamMapping (currentClass: string, targetSupertype: string): Map<string, string> {
|
||||
const mapping = new Map<string, string>();
|
||||
const currentInfo = classMap.get(currentClass);
|
||||
if (!currentInfo || !currentInfo.superTypeDetails) return mapping;
|
||||
@ -373,7 +373,7 @@ function getAllProperties(classMap: Map<string, ClassInfo>, className: string, s
|
||||
return mapping;
|
||||
}
|
||||
|
||||
function resolveType(type: string, typeMap: Map<string, string> = new Map()): string {
|
||||
function resolveType (type: string, typeMap: Map<string, string> = new Map()): string {
|
||||
// Resolve generic type parameters
|
||||
if (typeMap.has(type)) {
|
||||
return typeMap.get(type)!;
|
||||
@ -383,7 +383,7 @@ function getAllProperties(classMap: Map<string, ClassInfo>, className: string, s
|
||||
}
|
||||
|
||||
// Collect properties in inheritance order (most specific first)
|
||||
function collectProperties(currentClass: string, inheritanceLevel: number = 0, currentTypeMap: Map<string, string> = new Map()) {
|
||||
function collectProperties (currentClass: string, inheritanceLevel: number = 0, currentTypeMap: Map<string, string> = new Map()) {
|
||||
if (visited.has(currentClass)) return;
|
||||
visited.add(currentClass);
|
||||
|
||||
@ -468,11 +468,11 @@ function getAllProperties(classMap: Map<string, ClassInfo>, className: string, s
|
||||
}
|
||||
|
||||
// Helper to find all implementations of a type (both concrete and abstract)
|
||||
function findAllImplementations(classMap: Map<string, ClassInfo>, typeName: string, concreteOnly: boolean = false): string[] {
|
||||
function findAllImplementations (classMap: Map<string, ClassInfo>, typeName: string, concreteOnly: boolean = false): string[] {
|
||||
const implementations: string[] = [];
|
||||
const visited = new Set<string>();
|
||||
|
||||
function findImplementations(currentType: string) {
|
||||
function findImplementations (currentType: string) {
|
||||
if (visited.has(currentType)) return;
|
||||
visited.add(currentType);
|
||||
|
||||
@ -518,7 +518,7 @@ function findAllImplementations(classMap: Map<string, ClassInfo>, typeName: stri
|
||||
return [...new Set(implementations)].sort(); // Remove duplicates and sort
|
||||
}
|
||||
|
||||
function analyzeForSerialization(classMap: Map<string, ClassInfo>, symbolsFile: string): AnalysisResult {
|
||||
function analyzeForSerialization (classMap: Map<string, ClassInfo>, symbolsFile: string): AnalysisResult {
|
||||
const startingTypes = ['SkeletonData', 'Skeleton', 'AnimationState'];
|
||||
const accessibleTypes = findAccessibleTypes(classMap, startingTypes);
|
||||
|
||||
@ -681,7 +681,7 @@ function analyzeForSerialization(classMap: Map<string, ClassInfo>, symbolsFile:
|
||||
};
|
||||
}
|
||||
|
||||
async function main() {
|
||||
async function main () {
|
||||
try {
|
||||
// Ensure output directory exists
|
||||
const outputDir = ensureOutputDir();
|
||||
|
||||
@ -7,7 +7,7 @@ import type { Property, SerializerIR } from './generate-serializer-ir';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
function transformType(javaType: string): string {
|
||||
function transformType (javaType: string): string {
|
||||
// Remove package prefixes
|
||||
const simpleName = javaType.includes('.') ? javaType.split('.').pop()! : javaType;
|
||||
|
||||
@ -28,7 +28,7 @@ function transformType(javaType: string): string {
|
||||
return simpleName;
|
||||
}
|
||||
|
||||
function generatePropertyCode(property: Property, indent: string, enumMappings: { [enumName: string]: { [javaValue: string]: string } }): string[] {
|
||||
function generatePropertyCode (property: Property, indent: string, enumMappings: { [enumName: string]: { [javaValue: string]: string } }): string[] {
|
||||
const lines: string[] = [];
|
||||
|
||||
// Transform field access for C++: add _ prefix except for Color fields
|
||||
@ -132,7 +132,7 @@ function generatePropertyCode(property: Property, indent: string, enumMappings:
|
||||
return lines;
|
||||
}
|
||||
|
||||
function generateCppFromIR(ir: SerializerIR): string {
|
||||
function generateCppFromIR (ir: SerializerIR): string {
|
||||
const cppOutput: string[] = [];
|
||||
|
||||
// Generate C++ file header
|
||||
@ -417,7 +417,7 @@ function generateCppFromIR(ir: SerializerIR): string {
|
||||
return cppOutput.join('\n');
|
||||
}
|
||||
|
||||
async function main() {
|
||||
async function main () {
|
||||
try {
|
||||
// Read the IR file
|
||||
const irFile = path.resolve(__dirname, '../output/serializer-ir.json');
|
||||
|
||||
@ -7,7 +7,7 @@ import type { Property, SerializerIR, WriteMethod } from './generate-serializer-
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
function generatePropertyCode(property: Property, indent: string, method?: WriteMethod): string[] {
|
||||
function generatePropertyCode (property: Property, indent: string, method?: WriteMethod): string[] {
|
||||
const lines: string[] = [];
|
||||
const accessor = `obj.${property.getter}`;
|
||||
|
||||
@ -113,7 +113,7 @@ function generatePropertyCode(property: Property, indent: string, method?: Write
|
||||
return lines;
|
||||
}
|
||||
|
||||
function generateJavaFromIR(ir: SerializerIR): string {
|
||||
function generateJavaFromIR (ir: SerializerIR): string {
|
||||
const javaOutput: string[] = [];
|
||||
|
||||
// Generate Java file header
|
||||
@ -287,7 +287,7 @@ function generateJavaFromIR(ir: SerializerIR): string {
|
||||
return javaOutput.join('\n');
|
||||
}
|
||||
|
||||
async function main() {
|
||||
async function main () {
|
||||
try {
|
||||
// Read the IR file
|
||||
const irFile = path.resolve(__dirname, '../output/serializer-ir.json');
|
||||
|
||||
@ -87,7 +87,7 @@ interface SerializedAnalysisResult {
|
||||
typeProperties: [string, PropertyInfo[]][];
|
||||
}
|
||||
|
||||
function loadExclusions(): { types: Set<string>, methods: Map<string, Set<string>>, fields: Map<string, Set<string>> } {
|
||||
function loadExclusions (): { types: Set<string>, methods: Map<string, Set<string>>, fields: Map<string, Set<string>> } {
|
||||
const exclusionsPath = path.resolve(__dirname, '../java-exclusions.txt');
|
||||
const types = new Set<string>();
|
||||
const methods = new Map<string, Set<string>>();
|
||||
@ -135,7 +135,7 @@ function loadExclusions(): { types: Set<string>, methods: Map<string, Set<string
|
||||
return { types, methods, fields };
|
||||
}
|
||||
|
||||
function analyzePropertyType(propType: string, classMap: Map<string, ClassInfo>): Property {
|
||||
function analyzePropertyType (propType: string, classMap: Map<string, ClassInfo>): Property {
|
||||
// Handle null annotations
|
||||
const isNullable = propType.includes('@Null');
|
||||
propType = propType.replace(/@Null\s+/g, '').trim();
|
||||
@ -244,7 +244,7 @@ function analyzePropertyType(propType: string, classMap: Map<string, ClassInfo>)
|
||||
};
|
||||
}
|
||||
|
||||
function generateSerializerIR(analysisData: SerializedAnalysisResult): SerializerIR {
|
||||
function generateSerializerIR (analysisData: SerializedAnalysisResult): SerializerIR {
|
||||
// Convert arrays back to Maps
|
||||
const classMap = new Map(analysisData.classMap);
|
||||
const abstractTypes = new Map(analysisData.abstractTypes);
|
||||
@ -431,7 +431,7 @@ function generateSerializerIR(analysisData: SerializedAnalysisResult): Serialize
|
||||
};
|
||||
}
|
||||
|
||||
function analyzePropertyWithDetails(prop: PropertyInfo, propName: string, getter: string, classMap: Map<string, ClassInfo>): Property {
|
||||
function analyzePropertyWithDetails (prop: PropertyInfo, propName: string, getter: string, classMap: Map<string, ClassInfo>): Property {
|
||||
// Handle null annotations
|
||||
const isNullable = prop.type.includes('@Null');
|
||||
let propType = prop.type.replace(/@Null\s+/g, '').trim();
|
||||
@ -536,7 +536,7 @@ function analyzePropertyWithDetails(prop: PropertyInfo, propName: string, getter
|
||||
};
|
||||
}
|
||||
|
||||
async function main() {
|
||||
async function main () {
|
||||
try {
|
||||
// Read analysis result
|
||||
const analysisFile = path.resolve(__dirname, '../output/analysis-result.json');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user