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
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Format TypeScript files with Biome
|
# Format TypeScript files with tsfmt
|
||||||
echo "Formatting TypeScript files..."
|
echo "Formatting TypeScript files..."
|
||||||
|
|
||||||
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
||||||
|
|
||||||
# Check if biome.json files match
|
# Check if tsfmt.json files match
|
||||||
if ! cmp -s ../spine-ts/biome.json ../tests/biome.json; then
|
if ! cmp -s ../spine-ts/tsfmt.json ../tests/tsfmt.json; then
|
||||||
echo -e "\033[1;31mERROR: spine-ts/biome.json and tests/biome.json differ!\033[0m"
|
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"
|
echo -e "\033[1;31mPlease sync them to ensure consistent formatting.\033[0m"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Format TypeScript files
|
# Format TypeScript files
|
||||||
cd ../spine-ts && npx biome format --write . && cd ../formatters
|
cd ../spine-ts && npm run format && cd ../formatters
|
||||||
cd ../tests && npx biome format --write --config-path ../spine-ts . && 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 fs from 'node:fs';
|
||||||
import * as path from 'node:path';
|
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;
|
if (!fs.existsSync(dir)) return files;
|
||||||
|
|
||||||
fs.readdirSync(dir).forEach(name => {
|
fs.readdirSync(dir).forEach(name => {
|
||||||
@ -32,7 +32,7 @@ fs.readdirSync('.').forEach(name => {
|
|||||||
|
|
||||||
if (allFiles.length > 0) {
|
if (allFiles.length > 0) {
|
||||||
console.log(`Formatting ${allFiles.length} TypeScript files...`);
|
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 {
|
} else {
|
||||||
console.log('No TypeScript files found to format.');
|
console.log('No TypeScript files found to format.');
|
||||||
}
|
}
|
||||||
@ -4,7 +4,7 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"compare": "tsx compare-with-reference-impl.ts",
|
"compare": "tsx compare-with-reference-impl.ts",
|
||||||
"format": "npx tsfmt -r ./**/*.ts",
|
"format": "npx -y typescript-formatter -r ./**/*.ts",
|
||||||
"lint": "npx biome lint ."
|
"lint": "npx biome lint ."
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import type { LspCliResult, SymbolInfo } from '@mariozechner/lsp-cli';
|
|||||||
|
|
||||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
function ensureOutputDir(): string {
|
function ensureOutputDir (): string {
|
||||||
const outputDir = path.resolve(__dirname, '../output');
|
const outputDir = path.resolve(__dirname, '../output');
|
||||||
if (!fs.existsSync(outputDir)) {
|
if (!fs.existsSync(outputDir)) {
|
||||||
fs.mkdirSync(outputDir, { recursive: true });
|
fs.mkdirSync(outputDir, { recursive: true });
|
||||||
@ -17,7 +17,7 @@ function ensureOutputDir(): string {
|
|||||||
return outputDir;
|
return outputDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateLspData(outputDir: string): string {
|
function generateLspData (outputDir: string): string {
|
||||||
const outputFile = path.join(outputDir, 'spine-libgdx-symbols.json');
|
const outputFile = path.join(outputDir, 'spine-libgdx-symbols.json');
|
||||||
const projectDir = path.resolve(__dirname, '../../spine-libgdx');
|
const projectDir = path.resolve(__dirname, '../../spine-libgdx');
|
||||||
const srcDir = path.join(projectDir, 'spine-libgdx/src');
|
const srcDir = path.join(projectDir, 'spine-libgdx/src');
|
||||||
@ -58,11 +58,11 @@ function generateLspData(outputDir: string): string {
|
|||||||
return outputFile;
|
return outputFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
function analyzeClasses(symbols: SymbolInfo[]): Map<string, ClassInfo> {
|
function analyzeClasses (symbols: SymbolInfo[]): Map<string, ClassInfo> {
|
||||||
const classMap = new Map<string, ClassInfo>();
|
const classMap = new Map<string, ClassInfo>();
|
||||||
const srcPath = path.resolve(__dirname, '../../spine-libgdx/spine-libgdx/src/');
|
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;
|
if (symbol.kind !== 'class' && symbol.kind !== 'enum' && symbol.kind !== 'interface') return;
|
||||||
|
|
||||||
// Filter: only process symbols in spine-libgdx/src, excluding SkeletonSerializer
|
// Filter: only process symbols in spine-libgdx/src, excluding SkeletonSerializer
|
||||||
@ -147,7 +147,7 @@ function analyzeClasses(symbols: SymbolInfo[]): Map<string, ClassInfo> {
|
|||||||
return classMap;
|
return classMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
function findAccessibleTypes(
|
function findAccessibleTypes (
|
||||||
classMap: Map<string, ClassInfo>,
|
classMap: Map<string, ClassInfo>,
|
||||||
startingTypes: string[]
|
startingTypes: string[]
|
||||||
): Set<string> {
|
): Set<string> {
|
||||||
@ -156,7 +156,7 @@ function findAccessibleTypes(
|
|||||||
const visited = new Set<string>();
|
const visited = new Set<string>();
|
||||||
|
|
||||||
// Helper to find all concrete subclasses of a type
|
// 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[] = [];
|
const concreteClasses: string[] = [];
|
||||||
|
|
||||||
if (!classMap.has(typeName)) return concreteClasses;
|
if (!classMap.has(typeName)) return concreteClasses;
|
||||||
@ -281,7 +281,7 @@ function findAccessibleTypes(
|
|||||||
return accessible;
|
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 exclusionsPath = path.resolve(__dirname, '../java-exclusions.txt');
|
||||||
const types = new Set<string>();
|
const types = new Set<string>();
|
||||||
const methods = new Map<string, 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 };
|
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);
|
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) {
|
if (isGetter) {
|
||||||
return exclusions.methods.get(className)?.has(propertyName) || false;
|
return exclusions.methods.get(className)?.has(propertyName) || false;
|
||||||
} else {
|
} 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 allProperties: PropertyInfo[] = [];
|
||||||
const visited = new Set<string>();
|
const visited = new Set<string>();
|
||||||
const classInfo = classMap.get(className);
|
const classInfo = classMap.get(className);
|
||||||
@ -351,7 +351,7 @@ function getAllProperties(classMap: Map<string, ClassInfo>, className: string, s
|
|||||||
const typeParamMap = new Map<string, string>();
|
const typeParamMap = new Map<string, string>();
|
||||||
|
|
||||||
// Helper to build parameter mappings for a specific supertype
|
// 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 mapping = new Map<string, string>();
|
||||||
const currentInfo = classMap.get(currentClass);
|
const currentInfo = classMap.get(currentClass);
|
||||||
if (!currentInfo || !currentInfo.superTypeDetails) return mapping;
|
if (!currentInfo || !currentInfo.superTypeDetails) return mapping;
|
||||||
@ -373,7 +373,7 @@ function getAllProperties(classMap: Map<string, ClassInfo>, className: string, s
|
|||||||
return mapping;
|
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
|
// Resolve generic type parameters
|
||||||
if (typeMap.has(type)) {
|
if (typeMap.has(type)) {
|
||||||
return typeMap.get(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)
|
// 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;
|
if (visited.has(currentClass)) return;
|
||||||
visited.add(currentClass);
|
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)
|
// 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 implementations: string[] = [];
|
||||||
const visited = new Set<string>();
|
const visited = new Set<string>();
|
||||||
|
|
||||||
function findImplementations(currentType: string) {
|
function findImplementations (currentType: string) {
|
||||||
if (visited.has(currentType)) return;
|
if (visited.has(currentType)) return;
|
||||||
visited.add(currentType);
|
visited.add(currentType);
|
||||||
|
|
||||||
@ -518,7 +518,7 @@ function findAllImplementations(classMap: Map<string, ClassInfo>, typeName: stri
|
|||||||
return [...new Set(implementations)].sort(); // Remove duplicates and sort
|
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 startingTypes = ['SkeletonData', 'Skeleton', 'AnimationState'];
|
||||||
const accessibleTypes = findAccessibleTypes(classMap, startingTypes);
|
const accessibleTypes = findAccessibleTypes(classMap, startingTypes);
|
||||||
|
|
||||||
@ -681,7 +681,7 @@ function analyzeForSerialization(classMap: Map<string, ClassInfo>, symbolsFile:
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main () {
|
||||||
try {
|
try {
|
||||||
// Ensure output directory exists
|
// Ensure output directory exists
|
||||||
const outputDir = ensureOutputDir();
|
const outputDir = ensureOutputDir();
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import type { Property, SerializerIR } from './generate-serializer-ir';
|
|||||||
|
|
||||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
function transformType(javaType: string): string {
|
function transformType (javaType: string): string {
|
||||||
// Remove package prefixes
|
// Remove package prefixes
|
||||||
const simpleName = javaType.includes('.') ? javaType.split('.').pop()! : javaType;
|
const simpleName = javaType.includes('.') ? javaType.split('.').pop()! : javaType;
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ function transformType(javaType: string): string {
|
|||||||
return simpleName;
|
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[] = [];
|
const lines: string[] = [];
|
||||||
|
|
||||||
// Transform field access for C++: add _ prefix except for Color fields
|
// Transform field access for C++: add _ prefix except for Color fields
|
||||||
@ -132,7 +132,7 @@ function generatePropertyCode(property: Property, indent: string, enumMappings:
|
|||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateCppFromIR(ir: SerializerIR): string {
|
function generateCppFromIR (ir: SerializerIR): string {
|
||||||
const cppOutput: string[] = [];
|
const cppOutput: string[] = [];
|
||||||
|
|
||||||
// Generate C++ file header
|
// Generate C++ file header
|
||||||
@ -417,7 +417,7 @@ function generateCppFromIR(ir: SerializerIR): string {
|
|||||||
return cppOutput.join('\n');
|
return cppOutput.join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main () {
|
||||||
try {
|
try {
|
||||||
// Read the IR file
|
// Read the IR file
|
||||||
const irFile = path.resolve(__dirname, '../output/serializer-ir.json');
|
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));
|
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 lines: string[] = [];
|
||||||
const accessor = `obj.${property.getter}`;
|
const accessor = `obj.${property.getter}`;
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ function generatePropertyCode(property: Property, indent: string, method?: Write
|
|||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateJavaFromIR(ir: SerializerIR): string {
|
function generateJavaFromIR (ir: SerializerIR): string {
|
||||||
const javaOutput: string[] = [];
|
const javaOutput: string[] = [];
|
||||||
|
|
||||||
// Generate Java file header
|
// Generate Java file header
|
||||||
@ -287,7 +287,7 @@ function generateJavaFromIR(ir: SerializerIR): string {
|
|||||||
return javaOutput.join('\n');
|
return javaOutput.join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main () {
|
||||||
try {
|
try {
|
||||||
// Read the IR file
|
// Read the IR file
|
||||||
const irFile = path.resolve(__dirname, '../output/serializer-ir.json');
|
const irFile = path.resolve(__dirname, '../output/serializer-ir.json');
|
||||||
|
|||||||
@ -87,7 +87,7 @@ interface SerializedAnalysisResult {
|
|||||||
typeProperties: [string, PropertyInfo[]][];
|
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 exclusionsPath = path.resolve(__dirname, '../java-exclusions.txt');
|
||||||
const types = new Set<string>();
|
const types = new Set<string>();
|
||||||
const methods = new Map<string, 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 };
|
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
|
// Handle null annotations
|
||||||
const isNullable = propType.includes('@Null');
|
const isNullable = propType.includes('@Null');
|
||||||
propType = propType.replace(/@Null\s+/g, '').trim();
|
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
|
// Convert arrays back to Maps
|
||||||
const classMap = new Map(analysisData.classMap);
|
const classMap = new Map(analysisData.classMap);
|
||||||
const abstractTypes = new Map(analysisData.abstractTypes);
|
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
|
// Handle null annotations
|
||||||
const isNullable = prop.type.includes('@Null');
|
const isNullable = prop.type.includes('@Null');
|
||||||
let propType = prop.type.replace(/@Null\s+/g, '').trim();
|
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 {
|
try {
|
||||||
// Read analysis result
|
// Read analysis result
|
||||||
const analysisFile = path.resolve(__dirname, '../output/analysis-result.json');
|
const analysisFile = path.resolve(__dirname, '../output/analysis-result.json');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user