Releases: ItemConsulting/xp-codegen-plugin
Sort imports in contentTypeIndex and xDataIndex files
There was an issue where this was not deterministic, and Linux and Mac outputted different files.
Full Changelog: 2.1.0...2.2.0
Rename `XP.XData` to `XpXData`
This makes this library conform to the official types released
from Enonic.
Full Changelog: 2.0.1...2.1.0
Fix issue where java-plugin is affected by this plugins filter
Bugfixes
- Fix problem with HTML-files not included in builds
Generate all files in ./.xp-codegen directory
2.0.0 release
1. Changes to output directory
It isn't considered best practice to generate files into the ./src directory, so all files will be generated into the ./.xp-codegen directory instead.
The directory structure inside ./.xp-codegen is the same as inside the ./src/main/resouces directory, so we can do a trick in tsconfig.json where we set two rootDirs, and "overlays" ./.xp-codegen over ./src/main/resouces.
Do the following change to you tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"strict": true,
"sourceMap": true,
"allowJs": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"strictNullChecks": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"module": "commonjs",
"moduleResolution": "node",
"types": ["node", "enonic-types"],
+ "rootDirs": [
+ "./src/main/resources",
+ "./.xp-codegen"
+ ],
},
"include": [
+ "./.xp-codegen/**/*",
"./src/main/resources/**/*"
],
"exclude": ["./build/*"]
}You will still need to change all the interface imports in your application (sorry about that), but the new syntax is much nicer if you ask me.
// The old way to import
-import type { Article } from "../../content-types/article/article";
-import type { Employee } from "../../content-types/employee/employee";
// The new way to import
+import type { Article, Employee } from "../../content-types";
// Or you can access globally defined type like this:
+type Article = XP.ContentTypes["com.mysite.app:article"];The globally declared XP.ContentTypes interface will allow us to do some really cool stuff in enonic-types, since can have the association between the name of the content type, and the structure of the data.
2. Remove other Gradle tasks then generateTypeScript
The other Gradle tasks were either little used, or useless, so all other tasks then generateTypeScript has been removed.
generateTypeScript will now generate .d.ts files (not .ts files). A benefit with this is that .d.ts files doesn't emit any JavaScript when running Webpack.
3. Changes to part configs
Part configs has also gotten new paths to be imported from, and can now be found in index.d.ts in the same directory.
Lets say we have a part parts/article-view/article-view.ts.
-import type { ArticleViewConfig } from "./article-view-config.ts";
+import type { ArticleView } from ".";4. Arrays in interfaces
We have changed the interfaces used for Arrays from Array<T> to Array<T> | T. This is to reflect the structure XP actually returns, and force the developer to use forceArray().
Note
If XP only have one entry in the array, it will return that value instead of anArraywith one value.
5. __typename for interfaces
Example:
// WARNING: This file was automatically generated by "no.item.xp.codegen". You may lose your changes if you edit it.
export interface Article {
/**
* Preface
*/
preface: string;
/**
* Body
*/
body: string;
+
+ /**
+ * GraphQL name. Also used for separating unions in TypeScript
+ */
+ __typename?: "no_mysite_app_Article_Data";
}This attribute is never set in TypeScript-land, only in GraphQL-land. But it exists in the interface to allow us to split discrete unions cleanly. We can now have tools that looks up the type name based on the shape of the data.
6. Generated XData interface
A new global declaration can be found under ./site/x-data/index.d.ts, and can be accessed globally by XP.XData. This will have the structure of the x-data fields specified in the application.
If you have 3rd party x-data that is being used, you can also declare those as globals, and the interfaces will be merged.
Enjoy the new release everybody! And sorry about changing all the import paths! 😬
Fix bug for mixins on Windows
Thanks to @MartinEngen for fixing an issue with using mixins on windows.
Prettier output
Changes:
- Generated TypeScript interfaces will now have the same indentation as prettier uses (for compatibility)
- Configuration option
singleQuote: booleanto output with'instead of"has been added. - Configuration option
prependTexthas been added, that lets the developer change the warning message on the first to to what they want. This can include disabeling prettier for this file with/* eslint-disable prettier/prettier */
Example
jar {
dependsOn += generateTypeScript {
singleQuote = true
prependText = "// This is a different message"
}
}Add multichoice support in OptionSet
- Support for having multiple options selected in OptionSets at the same time has been added.
- Default file names has been set to the the postfix "-config". This way new xml-types will have that by default (like
tasks).
Add alternative for outputting *.d.ts files
Thank you to Edward Grönroos for all the work in this release!
Fix filetype for 'codegen-output'
This release sets the correct file extention for files based on 'codegen-output'.
Validation for Date, Time and DateTime
Validation for generated io-ts code has been added for the following input types:
- Date
- Time
- DateTime
I uses the RegexpValidatedString type from enonic-wizardry for this. Validation will now fail for these input types if they don't fit the required regex.