2

I am following this article to configure leprechaun, I am using Sitecore serialization. I can see serialization is working fine but model file is not generating and throwing error as mentioned below.

dotnet leprechaun /c C:\SWP\xxxxx\\Leprechaun.config
1>    _                             _                       
1>   | |    ___ _ __  _ __ ___  ___| |__   __ _ _   _ _ __  
1>   | |   / _ \ '_ \| '__/ _ \/ __| '_ \ / _` | | | | '_ \ 
1>   | |__|  __/ |_) | | |  __/ (__| | | | (_| | |_| | | | |
1>   |_____\___| .__/|_|  \___|\___|_| |_|\__,_|\__,_|_| |_|
1>             |_|                           Version 2.2.2.0
1>  
1>                   @@                 .###@@::;%%&&00'
1>                  @><@               .###@@::;%%&&00'
1>            ________)               .###@@::;%%&&00'
1>           |        |              .###@@::;%%&&00'
1>      _   _|===LI===|_            .###@@::;%%&&00'
1>     / \_(____________)          .###@@::;%%&&00'
1>     \  / (88 o  o 88)          .###@@::;%%&&00'
1>      \/\  88:  7 :88`         .###@@::;%%&&00'
1>       \/\ '88'=='88'         .###@@::;%%&&00'
1>        \ \__'8888'__________.###@@::;%%&&00'
1>         \___<\""/>_____/_/_.###@@::;%%&&00'
1>            /  ><  \       .###@@::;%%&&00'
1>          / __/--\__\     (oO@OoO@@o@oO@@o)
1>          '-.______.-'    /`"""""""""""""`\
1>            _|_||_|_     |                 |
1>         ___LI)||(LI___  |                 |
1>        (   ~~ || ~~   )  \               /
1>         `-----''-----`    '.___________.'
1>   
1>C:\SWP\xxxxx\src\platform\Platform.wpp.targets(12,3): error MSB3073: The command "dotnet leprechaun /c C:\SWP\xxxxx\\Leprechaun.config" exited with code 1.
1>Done executing task "Exec" -- FAILED. 

Please find below the leprechaun config 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="src/*/*.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="Test.Base" abstract="true">
            <!-- More than one output file can be specified (comma-delimited) -->
            <codeGenerator scripts="$(configDirectory)/CodeGen/JssTypeScript.csx" outputFile="$(configDirectory)\src\test\.generated\templates\models\TestTemplate.model.ts" />
            <templatePredicate rootNamespace="$(layer).$(module)">
                <include name="templates" path="/sitecore/templates/$(layer)/$(module)" />
            </templatePredicate>
        </configuration>
    </configurations>

    <!-- 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" name="filter">
            <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>

Moreover, When I downloaded latest code and run cli with set config file that is not the latest version and complaining about orchestrator type.

1 Answer 1

1

As per this config Leprechaun codegenerator generate only csharp code.

<codeGenerator type="Leprechaun.CodeGen.Roslyn.CSharpScriptCodeGenerator, Leprechaun.CodeGen.Roslyn" singleInstance="true" />

And here we are trying to generate typescript file using JSSTypeScript.csx. so that will not work.

<codeGenerator scripts="$(configDirectory)/CodeGen/JssTypeScript.csx" outputFile="$(configDirectory)\src\test\.generated\templates\models\TestTemplate.model.ts" />

As per this document it looks Leprechaun support csharp code generation. https://github.com/blipson89/Leprechaun

I hope this will help to find the issue.

3
  • Hi Praveen, Thanks for the reply, I replaced it with the default script generator though there is a same response.
    – user13074
    May 5, 2023 at 7:11
  • Leprechaun - as its readme doc, it looks, it provides only csharp code generation, not typescript. did you write typescriptcodegenerator to replace CSharpScriptCodeGenerator? May 5, 2023 at 7:17
  • Yes Perveen, we have implemented our own generator for typescript that is working fine for Sitecore 10 Helix framework.
    – user13074
    May 5, 2023 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.