89 lines
2.2 KiB
TypeScript
89 lines
2.2 KiB
TypeScript
import { CppCreator } from "./cpp-creation/CppCreator";
|
|
import { TypeRegistration } from "./cpp-creation/TypeRegistration";
|
|
import { Files } from "./library/Files";
|
|
import { MatchResult } from "./library/MatchResult";
|
|
import { RJLog } from "./library/RJLog";
|
|
import { Texts } from "./library/Texts";
|
|
|
|
class CreateCpp
|
|
{
|
|
static async main()
|
|
{
|
|
RJLog.log( "Clear old cpp files" );
|
|
await this.clearCppFiles();
|
|
|
|
RJLog.log( "Generate cpp files from definitions" );
|
|
let files = await this.getCppFiles();
|
|
|
|
for ( let file of files )
|
|
{
|
|
var cppFilePath = Texts.joinPaths( CppCreator.definitionsPath, file );
|
|
await CppCreator.createCppFiles( cppFilePath);
|
|
}
|
|
|
|
RJLog.log( "Copy raw cpp files" );
|
|
await this.copyRaw();
|
|
|
|
RJLog.log( "Register types" );
|
|
await TypeRegistration.createRegistrations();
|
|
|
|
}
|
|
|
|
static cppExtensionRegex = /\.(h|cpp)$/;;
|
|
|
|
static async clearCppFiles()
|
|
{
|
|
let allFiles = await Files.getFiles( CppCreator.outputPath );
|
|
|
|
let cppFiles = allFiles.filter( file => CreateCpp.cppExtensionRegex.test( file ) );
|
|
|
|
for ( let cppFile of cppFiles )
|
|
{
|
|
let fullPath = Texts.joinPaths( CppCreator.outputPath, cppFile );
|
|
|
|
//RJLog.log( "deleting", fullPath );
|
|
await Files.delete( fullPath );
|
|
}
|
|
}
|
|
|
|
static async getCppFiles()
|
|
{
|
|
let files = await Files.getFiles( CppCreator.definitionsPath );
|
|
files = files.filter( f => ! f.startsWith( "_" ) );
|
|
|
|
return Promise.resolve( files );
|
|
}
|
|
|
|
static async copyRaw()
|
|
{
|
|
let files = await Files.getFilesRecursive( CppCreator.rawPath );
|
|
|
|
for ( let i = 0; i < files.length; i++ )
|
|
{
|
|
let fileName = Texts.fileName( files[ i ] );
|
|
|
|
if ( fileName.startsWith( "_" ) || ! CreateCpp.cppExtensionRegex.test( fileName ) )
|
|
{
|
|
continue;
|
|
}
|
|
|
|
let fullPath = Texts.joinPaths( CppCreator.rawPath, files[ i ] );
|
|
let isDirectory = await Files.isDirectory( fullPath );
|
|
|
|
if ( isDirectory )
|
|
{
|
|
continue;
|
|
}
|
|
|
|
let outputFullPath = Texts.joinPaths( CppCreator.outputPath, fileName );
|
|
|
|
// RJLog.log( "copying:", fileName, "\n" + fullPath, "\n", outputFullPath );
|
|
|
|
await Files.copy( fullPath, outputFullPath );
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
CreateCpp.main();
|