Skip to content

Instantly share code, notes, and snippets.

@daivagna
Last active November 7, 2023 13:41
Show Gist options
  • Save daivagna/192533837ef6138f99ca083c14759ca8 to your computer and use it in GitHub Desktop.
Save daivagna/192533837ef6138f99ca083c14759ca8 to your computer and use it in GitHub Desktop.
Leprechaun configuration file
<?xml version="1.0" encoding="utf-8" ?>
<!--
GETTING STARTED WITH LEPRECHAUN
1. Make a COPY of this file to store your base Leprechaun configuration.
- This file should go in source control.
- It can go anywhere under your project, in some global location (like say /src)
2. Alter the Sample.Base configuration below, in your copy, to define the model conventions of your project.
- Where to find serialized item files
- Where generated code is stored
- Which code generator(s) you want to use (e.g. Constants, Synthesis, etc)
- Ignored field names
- Use of variables ($(layer) and $(module)) allow you to define conventions once and reuse them on module configs,
assuming module configs are named as 'Layer.Module'
3. Define config files for each Helix module in your project.
- Normally these should be placed alongside the module's source code
- These do not need to be deployed to the website at all
- These are not Sitecore config patches. See the sample below in the 'import' comments.
4. Alter the 'import' attribute on your base config file to find all your module configuration files
5. Run `Leprechaun.Console.exe -c "path\to\Leprechaun.MyCopy.config"` to generate your code
AVAILABLE VARIABLES IN CONFIG:
$(layer) - the Helix-style layer of the configuration (assumes config is named Layer.Module)
$(module) the Helix-style module of the configuration
$(configurationName) - the full name of the configuration
$(configDirectory) - the full path to the directory containing the root Leprechaun config file being used
NOTE: variables cannot be used on the 'import' declaration. Paths there are always relative to $(configDirectory).
-->
<leprechaun>
<!--
Use the 'import' attribute to load module configurations from other files.
This enables you to store modules' codegen configurations alongside their source for improved discoverability.
Wildcards are allowed (* and **). Relative paths are allowed, and are relative to the base config file path.
Multiple path globs are also allowed, semicolon delimited (e.g. c:\*\foo.config;d:\foo.config)
A module configuration would normally 'extend' a base config defined here that embeds the project's conventions.
For example, a module config file might contain:
<configuration name="Feature.ModuleName" extends="Sample.Base">
</configuration>
Each configuration can override anything that is in defaults or the 'extends' configuration. For more info, see
https://kamsar.net/index.php/2017/02/Unicorn-4-Part-III-Configuration-Enhancements/ (the technique is the same as Unicorn)
-->
<configurations import="**\*.module.json">
<!--
Base code generation configuration.
Use this abstract configuration to override the <defaults> where needed.
(leave defaults alone to make config upgrades simpler)
-->
<configuration name="LeprechaunDemo.Base" abstract="true">
<!-- More than one output file can be specified (comma-delimited) -->
<codeGenerator scripts="$(configDirectory)/CodeGen/JssTypeScript.csx"
outputFile="$(configDirectory)\src\sxastarter\.GeneratedTypeScriptModel\$(layer).$(module).model.ts" />
<templatePredicate rootNamespace="Sample.$(layer).$(module)">
<include name="templates" path="/sitecore/templates/$(layer)/$(module)" />
</templatePredicate>
</configuration>
</configurations>
7
<!-- Config shared across all configurations -->
<shared name="Shared">
<orchestrator type="Leprechaun.InputProviders.Sitecore.SitecoreOrchestrator, Leprechaun.InputProviders.Sitecore" singleInstance="true" />
<inputProvider type="Leprechaun.InputProviders.Sitecore.SitecoreInputProvider, Leprechaun.InputProviders.Sitecore" singleInstance="true" />
<watcher type="Leprechaun.InputProviders.Sitecore.SitecoreWatcher, Leprechaun.InputProviders.Sitecore" singleInstance="true" />
<!--
If you need to override a field type, you can add a <fieldType> child node in metadataGenerator.
Example:
<metadataGenerator type="Leprechaun.MetadataGeneration.StandardTemplateMetadataGenerator, Leprechaun" singleInstance="true">
<fieldType id="{00000000-0000-0000-0000-000000000000}" type="datetime" />
<fieldType id="{11111111-1111-1111-1111-111111111111}" type="droptree" />
</metadataGenerator>
Be sure that your .CSX file is setup to handle this in the GetFieldType(...) method.
-->
<metadataGenerator type="Leprechaun.MetadataGeneration.StandardTemplateMetadataGenerator, Leprechaun" singleInstance="true" />
<!--
You can disable the validators (not recommended) by adding the following attributes to the architectureValidator:
- allowFieldNamesIdenticalToTemplateName="true"
- allowNovelFieldNames="true"
-->
<architectureValidator type="Leprechaun.Validation.StandardArchitectureValidator, Leprechaun" singleInstance="true" />
<architectureValidatorLogger type="Leprechaun.Validation.StandardArchitectureValidatorLogger, Leprechaun" singleInstance="true" />
<logger type="Leprechaun.Execution.ConsoleLogger, Leprechaun" singleInstance="true" />
<loggerFactory type="Leprechaun.InputProviders.Sitecore.ConsoleLoggerFactory, Leprechaun.InputProviders.Sitecore" singleInstance="true" />
</shared>
<!-- Defaults all configurations inherit unless overridden -->
<defaults>
<!--
The code generator does what it sounds like.
Note the Roslyn codegen requires 'scripts' and 'outputFile' parameters which are not provided by default.
-->
<codeGenerator type="Leprechaun.CodeGen.Roslyn.CSharpScriptCodeGenerator, Leprechaun.CodeGen.Roslyn" singleInstance="true" />
<!--
The template filter defines what items are included as templates from the data store.
The name MUST match up with the include name found in the .module.json
case-insensitive
-->
<templatePredicate type="Leprechaun.InputProviders.Sitecore.Filters.SitecoreTemplatePredicate, Leprechaun.InputProviders.Sitecore" rootNamespace="$(layer).$(module)" singleInstance="true">
<include name="Templates" path="/sitecore/templates/$(layer)/$(module)" />
</templatePredicate>
<fieldFilter type="Leprechaun.Filters.StandardFieldFilter, Leprechaun" singleInstance="true">
<!--
Excludes can either be field names (wildcards supported) or field IDs (e.g. <exclude fieldId="guid" />)
Note that these are TEMPLATE FIELD excludes (ignore on code generation), not excluding reading serialized item fields.
-->
<exclude name="__*" />
</fieldFilter>
<typeNameGenerator type="Leprechaun.MetadataGeneration.StandardTypeNameGenerator, Leprechaun" singleInstance="true" namespaceRootPath="/sitecore/templates/$(layer)/$(module)" keepLeadingUnderscores="false" />
<templateReader type="Leprechaun.InputProviders.Sitecore.TemplateReaders.SitecoreTemplateReader, Leprechaun.InputProviders.Sitecore" singleInstance="true">
<excludedBaseTemplate id="{8CA06D6A-B353-44E8-BC31-B528C7306971}" name="Rendering Parameters Template" />
</templateReader>
<serializationFormatter
type="Leprechaun.InputProviders.Sitecore.YamlSerializationFormatterWrapper, Leprechaun.InputProviders.Sitecore"
singleInstance="true" />
<logger type="Leprechaun.Execution.ConsoleLogger, Leprechaun" singleInstance="true" />
<!-- configRootDirectory should be the path to your sitecore.json file -->
<moduleConfigReader type="Leprechaun.InputProviders.Sitecore.ModuleConfigurationReader, Leprechaun.InputProviders.Sitecore" configRootDirectory="$(configDirectory)" singleInstance="true" />
<loggerFactory type="Leprechaun.InputProviders.Sitecore.ConsoleLoggerFactory, Leprechaun.InputProviders.Sitecore" singleInstance="true" />
<rootConfigurationManager type="Sitecore.DevEx.Configuration.FilesystemConfigurationManager, Sitecore.DevEx.Configuration" singleInstance="true" />
<serializationModuleConfigurationManager
type="Sitecore.DevEx.Serialization.Client.Datasources.Filesystem.Configuration.FilesystemSerializationModuleConfigurationManager, Sitecore.DevEx.Serialization.Client"
singleInstance="true" />
</defaults>
</leprechaun>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment