rokojori-godot/rokojori-cpp-generator/builds/create-cpp.js

75 lines
3.7 KiB
JavaScript

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const CppCreator_1 = require("./cpp-creation/CppCreator");
const TypeRegistration_1 = require("./cpp-creation/TypeRegistration");
const Files_1 = require("./library/Files");
const RJLog_1 = require("./library/RJLog");
const Texts_1 = require("./library/Texts");
class CreateCpp {
static main() {
return __awaiter(this, void 0, void 0, function* () {
RJLog_1.RJLog.log("Clear old cpp files");
yield this.clearCppFiles();
RJLog_1.RJLog.log("Generate cpp files from definitions");
let files = yield this.getCppFiles();
for (let file of files) {
var cppFilePath = Texts_1.Texts.joinPaths(CppCreator_1.CppCreator.definitionsPath, file);
yield CppCreator_1.CppCreator.createCppFiles(cppFilePath);
}
RJLog_1.RJLog.log("Copy raw cpp files");
yield this.copyRaw();
RJLog_1.RJLog.log("Register types");
yield TypeRegistration_1.TypeRegistration.createRegistrations();
});
}
;
static clearCppFiles() {
return __awaiter(this, void 0, void 0, function* () {
let allFiles = yield Files_1.Files.getFiles(CppCreator_1.CppCreator.outputPath);
let cppFiles = allFiles.filter(file => CreateCpp.cppExtensionRegex.test(file));
for (let cppFile of cppFiles) {
let fullPath = Texts_1.Texts.joinPaths(CppCreator_1.CppCreator.outputPath, cppFile);
//RJLog.log( "deleting", fullPath );
yield Files_1.Files.delete(fullPath);
}
});
}
static getCppFiles() {
return __awaiter(this, void 0, void 0, function* () {
let files = yield Files_1.Files.getFiles(CppCreator_1.CppCreator.definitionsPath);
files = files.filter(f => !f.startsWith("_"));
return Promise.resolve(files);
});
}
static copyRaw() {
return __awaiter(this, void 0, void 0, function* () {
let files = yield Files_1.Files.getFilesRecursive(CppCreator_1.CppCreator.rawPath);
for (let i = 0; i < files.length; i++) {
let fileName = Texts_1.Texts.fileName(files[i]);
if (fileName.startsWith("_") || !CreateCpp.cppExtensionRegex.test(fileName)) {
continue;
}
let fullPath = Texts_1.Texts.joinPaths(CppCreator_1.CppCreator.rawPath, files[i]);
let isDirectory = yield Files_1.Files.isDirectory(fullPath);
if (isDirectory) {
continue;
}
let outputFullPath = Texts_1.Texts.joinPaths(CppCreator_1.CppCreator.outputPath, fileName);
// RJLog.log( "copying:", fileName, "\n" + fullPath, "\n", outputFullPath );
yield Files_1.Files.copy(fullPath, outputFullPath);
}
});
}
}
CreateCpp.cppExtensionRegex = /\.(h|cpp)$/;
CreateCpp.main();
//# sourceMappingURL=create-cpp.js.map