TypeLite generate external modules? - typelite

I am trying to generate external modules rather than a type definition file. I believe I need to do the following:
Change the extension of the file to .ts instead of .d.ts.
Generate one file per module.
Add the key word "Export" in front of each interface and enum.
I was easily able to change the extension of the file by changing the "output extension" setting in the tt file.
I cannot figure out how to split the modules into separate files.
I cannot figure out how to add the Export key word to each interface.

TypeLITE doesn't support generating multiple files. This feature has been requested by several users, but I am not aware of a simple way to generate multiple files from the single tt file.
export keyword can't be added without changing source code of the library (TsGenerator.cs). This is very specific requirement, so I probably won't add it to the library.

TypeLite is a good project but lacking in Documentation and examples, it's open source so anyone can contribute and make it better.
As for creating a file per class i solved it using the code below.
private static void GenerateTypeScriptContracts(string assemblyFile, string outputPath)
{
// Clean TS Folder
System.IO.DirectoryInfo di = new DirectoryInfo(outputPath);
foreach (FileInfo file in di.GetFiles())
{
file.Delete();
}
// --
var assembly = Assembly.LoadFrom(assemblyFile);
// If you want a subset of classes from this assembly, filter them here
var models = assembly.GetTypes();
foreach (var model in models)
{
var generator = new TypeScriptFluent()
.WithConvertor<Guid>(c => "string")
.WithMemberFormatter((identifier) => Char.ToLower(identifier.Name[0]) + identifier.Name.Substring(1));
generator.ModelBuilder.Add(model);
// Generate TS interface definitions
var tsClassDefinitions = generator.Generate(TsGeneratorOutput.Properties | TsGeneratorOutput.Fields);
File.WriteAllText(Path.Combine(outputPath, "I" + model.FullName.Replace("ProjectName.DtoModels.", "") + ".ts"), tsClassDefinitions);
}
}

Related

How to exclude UnityEditor reference from asmdef?

How to exclude UnityEditor reference from asmdef?
Why I need it:
I have an asmdef file. For example, it is MyAssembly/MyAssembly.asmdef. The MyAssembly contains a lot of features and each feature staff is placed in its own folder. And some of these features has a code that is needed only in editor, and it refers to UnityEditor namespace. Such editor code is placed into an Editor folder.
But as you know, Editor folder name means nothing in terms of asmdef usage. So I add AssemblyDefenitionReference in each folder and refer it to the MyAssemblyEditor.asmdef assembly definition. So the paths looks like this:
MyAssembly/MyAssembly.asmdef
MyAssembly/Editor/MyAssemblyEditor.asmdef - this folder contains no code. It's needed just to place asmdef, because it's not allowed to place two asmdefs in a single folder.
MyAssembly/SomeFeature/Editor/*feature editor staff*
MyAssembly/SomeFeature/Editor/Editor.asmref - refers to MyAssemblyEditor.asmdef
MyAssembly/SomeFeature/*feature staff*
All this works good. But the problem is that, when some developer adds a new feature, he can forget to add a reference to the MyAssemblyEditor.asmdef in the editor folder. And there are no any errors will be shown in this case. This mistake will be revealed only when the build will be cooked. But I'd like that using of UnityEditor in MyAssembly will be instantly marked as an error.
Feel free to suggest other solution for this problem.
This thread got me thinking I can use CsprojPostprocessor to remove all references to UnityEditor from my csproj file. I wrote such class:
using System.Text.RegularExpressions;
using UnityEditor;
// ReSharper disable once CheckNamespace
public class CsprojPostprocessor : AssetPostprocessor
{
public static string OnGeneratedCSProject(string path, string content)
{
if (!path.EndsWith("Editor.csproj") && !path.EndsWith("Tests.csproj"))
{
var newContent =
Regex.Replace(content, "<Reference Include=\"UnityEditor(.|\n)*?</Reference>", "");
return newContent;
}
return content;
}
}
It also can be done with an xml parser or something.
The only thing, that confuse me is that this mechanism is badly documented and doesn't look like something simple users should use. So I use it at my own risk, but looks like there is no guarantee it will be strongly supported in future.

SAP custom translations for standard SAPUI5 application

I am currently implementing an extension to a standard application from SAP Marketing.
The extension contains new texts that need to be translated into different languages. In my previous extensions I could use the translation key of the standard application for my extension as well. The first line in the i18n.properties file in this case was always structured as follows:
# SAPUI5 TRANSLATION-KEY XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
However, in the standard app that I'm currently editing, it looks like this:
# This is the resource bundle for Campaigns
# __ldi.translation.uuid = 8e965d5e-c905-4b60-ac2a-205abb14046
In transaction se63, the translation key (is it even a translation key?) is not found - either with hyphens or without. Furthermore, in the standard app, the translations are kept in a single file for each language (e.g., i18n_de.properties). That's why I'm not sure if there's even a translation key for this standard app.
I don't want to create a new translation key for my extension and use this one. Once I did this, all the translations of the standard app had to be maintained for the new translation key as well.
Is anyone familiar with this type of translation? How can I maintain the translations for my extension?
Best Regards,
Christian
I found some solution to my problem:
I generated a new translation key by running program /UI5/TEXT_FILE_GEN_TRANS_KEY in transaction se38
I created a new folder i18n and added a i18nCustom.properties file to it. Then I added the translation key and default translations to the file just like for a regular i18n.properties file.
In the next step, I added the following code to the sap.ui5 property of the extension's manifest.json file to initiate the custom translation file:
"models": {
"i18nCustom": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "<Your Component>.i18n.i18nCustom"
}
}
}
Please note that you have to use something like {i18nCustom>property} in your view now instead of using i18n model.
To enhance the standard translation file with the custom one, I added the following code to the BaseController. You could also add the code only in the controller whose view is using the custom translations.
onBeforeRendering: function() {
var i18n = this.getModel("i18n"); // Get the standard i18n file
var sBundleURL = this.getModel("i18nCustom").getResourceBundle().oUrlInfo.url;
i18n.enhance({bundleUrl:sBundleURL}); // Merge the custom i18n file with the standard one
}
Hope this helps if someone has the same problem.

Extracting data from owl file using java,gwt,eclipse

I have to display content from the owl file namely the class names.. onto my browser, I am using GWT,eclipse to do so, could some one tell me the following :-
1)how do I integrate the owl file with the eclipse project?
2)How do I run queries from my java project to extract class names from the owl file?
3)Where can I get the protege api to nclude into my project?!
You could just store your .owl file anywhere inside your project or on any other location on your harddrive. You just provide a path to it, when you load/store it (see code below).
Take a look at the OWLAPI, it allows you to load an existing ontology and retrieve all classes from it. Your code could look like this:
private static void loadAndPrintEntities() {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI documentIRI = IRI.create("file:///C:/folder/", "your_rontology.owl");
try {
OWLOntology ontology = manager.loadOntologyFromOntologyDocument(documentIRI);
//Prints all axioms, not just classes
ontology.axioms().forEach(a -> System.out.println(a));
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
}
}
Rather than trying to integrate the Protegé API into your project, I suggest you write a plugin for Protegé. There are some great examples that should get you started. Import this project into Eclipse, modify the content, build your plugin and drop it into Protegé. That's it, you're ready to go!

How do I write a Webpack plugin to generate index.js files on demand?

In general, I want to know how to do code-generation/fabrication in a Webpack plugin on demand. I want to generate contents for files that do not exist when they are "required."
Specifically, I want a plugin that, when I require a directory, automatically requires all files in that directory (recursively).
For example, suppose we have the directory structure:
foo
bar.js
baz.js
main.js
And main.js has:
var foo = require("./foo");
// ...
I want webpack to automatically generate foo/index.js:
module.exports = {
bar: require("./bar"),
baz: require("./baz")
};
I've read most of the webpack docs. github.com/webpack/docs/wiki/How-to-write-a-plugin has an example of generating assets. However, I can't find an example of how to generate an asset on demand. It seems this should be a Resolver, but resolvers seem to only output file paths, not file contents.
Actually for your use case:
Specifically, I want a plugin that, when I require a directory, automatically requires all files in that directory (recursively).
you don't need a plugin. See How to load all files in a subdirectories using webpack without require statements
Doing code-generation/fabrication on demand can be done in JavaScript quite easily, why would you restrict your code generation specifically to only applied, when "required" by WebPack?
As NodeJS itself will look for an index.js, if you require a directory, you can quite easily generate arbitrary exports:
//index.js generating dynamic exports
var time = new Date();
var dynamicExport = {
staticFn : function() {
console.log('Time is:', time);
}
}
//dynamically create a function as a property in dynamicExport
//here you could add some file processing logic that is requiring stuff on demand and export it accordingly
dynamicExport['dyn' + time.getDay()] = function() {
console.log('Take this Java!');
}
module.exports = dynamicExport;

Using resource files (CultureInfo) in C# class file

I need a help with using resource files in C# class files.
My code:
class errorMessages
{
private static ResourceManager LocRM = new ResourceManager("Project1.languageFile", typeof(errorMessages).Assembly);
public static void XMLParseError(String msg)
{
MessageBox.Show(LocRM.GetString("XMLParseError") + "\n" + msg, LocRM.GetString("error"),
MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
}
+ created 2 .resx files named languageFile.en.resx and languageFile.pl-PL.resx in main Project1 folder
Now I want to use String from languageFile, in my class errorMessages, specified to localization which was set before. How can I do it?
I tried to add my Strings to WinForm .resx file, but that's clearing my data with any edit of WinForm.
I found answer for my question by myself, so I will write that solution, I hope it will help somebody.
Default resources file is located in [projectName]/Properties. I you want to add manually localizable resource files, you need to do that this way:
right click on Project in Solution Explorer -> Add new item -> resource file
Then set the name of file to Resources.[language].resx - in my case that are two files, Resources.pl-PL.resx and Resources.en.resx. After file is created, move it to Properties directory.
Now you can add your resources and use it this way:
MessageBox.Show(Project1.Properties.Resources.XMLParseError, Project1.Properties.Resources.information,
MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
Now chosen String will be in language setted in CultureInfo, or, if there is no that resource, default Resource file will be used.
source: MSDN - How to: Create a Localized Version of a Resource File