0.0.22 • Published 4 years ago

enonic-ts-codegen v0.0.22

Weekly downloads
63
License
MIT
Repository
github
Last release
4 years ago

DEPRECATED


WARNING: This project has been deprecated, and is not being maintained anymore.

Please use the new and much better XP Codegen Gradle Plugin instead.


No Maintenance Intended

Code generation tool that creates TypeScript interfaces based on xmls in Enonic XP. It can create interfaces for:

  • Content types
  • Pages
  • Parts
  • Site
  • Layout
  • Macros
  • Id-provider
  • Mixins

It is recommended to let Gradle run this tool on every build, so that we always have a tight cupling between the xmls and TypeScript-code.

Example

Given that we have a content-type described in content-types/article/article.xml:

<?xml version="1.0" encoding="UTF-8"?>
<content-type>
  <display-name>Article</display-name>
  <super-type>base:structured</super-type>
  <form>
    <input name="title" type="TextLine">
      <label>Title of the article</label>
      <occurrences minimum="1" maximum="1"/>
    </input>

    <input name="body" type="HtmlArea">
      <label>Main text body</label>
      <occurrences minimum="0" maximum="1"/>
    </input>
  </form>
</content-type>

Running enonic-ts-codegen will generate the a TypeScript-interface in the file content-types/article/article.ts:

export interface Article {
  /** Title of the article */
  title: string;
 
  /** Main text body */
  body?: string;
}

This interface will describe the data shape for this content type. Note that body can be undefined since occurrences/@minimum is 0 for body, so the key becomes body?, since the value can be undefined.

CLI

xml-to-ts.js is a command line utility that can generate TypeScript interfaces.

  • Build it: npm run build or npm run build:cli
  • Run it from the command line: node bin/xml-to-ts.js my-xml-file.xml

Gradle

xml-to-ts.js can be run automatically as part of theenonic project deploy process. First, add the dependency with npm install enonic-ts-codegen --save, and then add a task to build.gradle, for example:

task generateTypeScriptInterfaces( type: NodeTask, dependsOn: npmInstall ) {
    description = 'Generate TypeScript interfaces'
    environment = [ 'NODE_ENV': nodeEnvironment() ]
    args = [ '--project', '.', '--write-to-file' ]
    script = file( 'node_modules/enonic-ts-codegen/bin/index.js' )
}

To run the task as part of the deploy process, add it to the jar block:

jar {
  // ... other dependencies

  dependsOn += generateTypeScriptInterfaces

  // ...
}
0.0.21

4 years ago

0.0.22

4 years ago

0.0.20

4 years ago

0.0.18

4 years ago

0.0.19

4 years ago

0.0.17

4 years ago

0.0.16

4 years ago

0.0.15

4 years ago

0.0.14

4 years ago

0.0.13

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

5 years ago