public QmlTSWatcher(string frontendPath) { try { Globals.frontendRestInPeaceFolder = frontendPath + "/RestInPeace"; if (!Directory.Exists(Globals.frontendRestInPeaceFolder)) { Directory.CreateDirectory(Globals.frontendRestInPeaceFolder); } FileHelper.DeleteFilesWithExtensions(Globals.frontendRestInPeaceFolder, ".js", ".mjs", ".ts"); Globals.frontendQmlPagesFolder = frontendPath + "/QmlPages"; Globals.frontendQmlScriptsFolder = frontendPath + "/Scripts"; if (!Helper.ReadKeyIfNotOk(QmlTSFormsReader.AnalyseFiles(frontendPath))) { Environment.Exit(-1); } if (!Helper.ReadKeyIfNotOk(QmlMJSFunctionWriter.WriteFiles())) { Environment.Exit(-1); } Helper.ReadKeyIfNotOk(QmlTSScriptWriter.WriteFiles()); Helper.ReadKeyIfNotOk(QmlTSEntityWriter.WriteFiles(CSharpEntityReader.fileList)); Helper.ReadKeyIfNotOk(QmlTSEnumWriter.WriteFiles(CSharpEnumReader.fileList)); Helper.ReadKeyIfNotOk(QmlTSFormsWriter.WriteFiles()); Helper.ReadKeyIfNotOk(QmlTSUIWriter.WriteFiles(Globals.frontendQmlPagesFolder)); Helper.ReadKeyIfNotOk(QmlJSUpdater.UpdateJavascriptUIFiles()); Helper.ReadKeyIfNotOk(QmlBasicComponents.WriteTypescriptDefinitionsToFrontend()); Helper.ReadKeyIfNotOk(CppComponents.WriteTypescriptDefinitionsToFrontend()); Helper.ReadKeyIfNotOk(DTSWriter.WriteTypescriptEventHandler()); Helper.ReadKeyIfNotOk(QmlTSResourceWriter.WriteFiles(frontendPath)); Logger.LogInfoIfDebugLevel(DebugLevels.Basic | DebugLevels.Files | DebugLevels.Functions | DebugLevels.All, "SUCCESS"); } catch (Exception e) { Logger.LogError(e); } }
static public bool WriteTypescriptDefinitionsToFrontend() { var list = GetCppComponents(); Logger.LogInfoIfDebugLevel(DebugLevels.Basic | DebugLevels.Files | DebugLevels.Functions | DebugLevels.All, "Writing Qt Typescript definition files to " + Globals.frontendRestInPeaceFolder); foreach (var basicElement in list) { if (!DTSWriter.WriteTypescriptDefinitionToFrontEnd(basicElement)) { return(false); } } return(true); }
static private bool WriteTypescriptComponentFile(EQmlFile eQmlFormFile) { try { string tsComponentFileName = eQmlFormFile.name + ".d.ts"; string completeFilePath = Globals.frontendRestInPeaceFolder + "/" + tsComponentFileName; Logger.LogInfoIfDebugLevel(DebugLevels.Files | DebugLevels.Functions | DebugLevels.All, "\t" + tsComponentFileName); StringBuilder fileContent = new StringBuilder(); fileContent.Append("\n"); DTSWriter.WriteTypescriptImports(eQmlFormFile, ref fileContent); fileContent.Append("\n"); if (!string.IsNullOrEmpty(eQmlFormFile.extendsElementName)) { fileContent.Append("export declare class " + eQmlFormFile.name + " extends " + eQmlFormFile.extendsElementName + " {\n"); } else { fileContent.Append("export declare class " + eQmlFormFile.name + " {\n"); } foreach (EQMLFormProperty eQmlFormProperty in eQmlFormFile.propertyList) { fileContent.Append("\t" + eQmlFormProperty.name + ": " + eQmlFormProperty.type + ";\n"); } fileContent.Append("\n"); foreach (EQmlSignal eQmlSignal in eQmlFormFile.signalList) { fileContent.Append("\t" + eQmlSignal.name + ": MySimpleEvent<" + eQmlSignal.argTypeName + ">;\n"); } foreach (ETypescriptFunction eTypescriptFunction in eQmlFormFile.functionList) { fileContent.Append("\t" + eTypescriptFunction.signature + ": " + eTypescriptFunction.returnType + ";\n"); } fileContent.Append("}"); //Logger.LogInfo(newFileContent.ToString()); string oldContent = ""; if (File.Exists(completeFilePath)) { oldContent = File.ReadAllText(completeFilePath); } if (fileContent.ToString() != oldContent) { File.WriteAllText(completeFilePath, fileContent.ToString()); } return(true); } catch (Exception e) { Logger.LogError(e); } return(false); }