Converting "Deleting a single file from trash" code to an Add-On

PLACE FOR BLOG

Converting "Deleting a single file from trash" code to an Add-On

Converting "Deleting a single file from trash" code to an Add-On

marija

To begin with, I would like to ellaborate on what I think defines an Episerver AddOn:

  1. It is a nuget package that depends on some Episerver functionality
  2. It is marked with proper Episerver tags (EPiServerModulePackage & EPiServerPublicModulePackage)
  3. It has specific structure that Episerver installation expects
  4. It is useful for X number of Episerver CMS and/or Commerce instances

While this seem clear, still, an AddOn shouldn't be mixed with a simple nuget package that adds the files to solution (talking mostly about no 3.). You can still, ofc, create a nuget package that add the files to the solution. In some cases, this is desirable: when you don't want to type in same things over and over again, but you still need to change the implementation a lot. I have this little admin tool, where I literaly have a comment:

    // this is the place where you do "something" with 
    // each of the content items you are iterating through

If I wanted to make it an add-on, either I could remove this and leave the "something" part to a ContentInitializableModule or I would need to have an idea what useful thing this package could do instead (focusing on no 4.).

As opposed to this example, Grzegorz's Deleting a single file from trash is a splendid example of an Add-On - everybody needs this! (Just check out the comments :))

What I needed to do is the following:

  1. Renamed AddOn.Initial to SingleContentItemTrasher
  2. Grabbed the files and copied them in a structure that felt logical to me, see SingleContentItemTrasher github
  3. Changed alloy.extendedWastebasket to singleContentItemTrasher.extendedWastebasket (just because it felt right)
  4. Commented out the stylesheet import from TrashWidget.js, since it can be loaded through required resources.
  5. Changed the "App" (_getRestPath) in storeInitializer to SingleFileTrashed (it should match the assembly).
  6. modules.config looks a bit different, including the CSS loading and the paths are different.
  7. Added proper episerver dependencies to nuspec file.
  8. Added ClientResources to the package by adding this to Packager/Main.targets file:
    <ItemGroup>
      <ClientResources Include="$(SolutionDir)\ClientResources\**\*" />
    </ItemGroup>
    <Copy SourceFiles="@(ClientResources)" DestinationFiles="@(ClientResources -> '$(TmpOutDir)\content\$(Version)\ClientResources\%(RecursiveDir)%(Filename)%(Extension)')"/>

The speed of doing this amazed me: it took me less than 2h (including testing on two different Episerver versions), even though I haven't written the code myself!

UPDATE: I have also now renamed everything now to SingleContentItemTrasher, since it does not delete files but Episerver content items. I have also fixed the following issue.

LEAVE A COMMENT