No description, website, or topics provided.
JavaScript HTML Java TypeScript CSS Kotlin Shell
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
generators
lib
samples
test
.editorconfig
.eslintignore
.eslintrc
.gitignore
README.md
gulpfile.js
package.json
sample-descriptor.js

README.md

Generator Nuxeo Metamodel

Build Status devDependency Status

Introduction

This project is the metamodel used by the nuxeo/generator-nuxeo project, a Yeoman generator for Nuxeo. It defines what can be generated with the generator using a simple description format.

Format description

Each folder is a generator; you can pass several generator names to the yo nuxeo command.

A basic field explanation can be found on the descriptor sample file.

Descriptor dependency, ordering, skip

Using the Generator Inheritance

The descriptor file is handled using the require node module; you need to use module.exports to export your descriptor in a descriptor.js file.

A descriptor can depend from another one. For instance, an operation generator depends on the default generator, which checks if a project initialization is needed. The default value is default.

module.exports = {
  depends: 'default'
};
Using Skip and Ensure Fields

Sometimes, you can't use a generator because the target project is not suitable, or you do not want to generate something twice. You have two ways to do that:

  • using the skip method; useful when you do not want to generate it several times. The skip value is a function where this is the generator.
  • using the ensure method; useful when you'd stop the generation due to some context issues. The skip value is a function where this is the generator.

For instance, the single-module generator is skipped when there is already a pom.xml file.

module.exports = {
  skip: function() {
    return this.fs.exists('pom.xml');
  },
  ...
};

For instance, the package generator can't be executed on a single module project:

module.exports = {
  ensure: function() {
    return this.config['multi'];
  },
  ...
};

Using type Field

The type field is useful when you are in a multi-module archetype. As the main module is a pom; you can chose in which submodule you'd like to force the generation. If you do not use the type field, user can set it using the --type option on the generator. The default value is core. The submodule is automatically added to the parent pom.xml file if needed.

module.exports = {
  type: 'core',
  ...
}

Configuration

Storing project configuration can be done using the config field; and can be read later to skip some generator; or having a default value for a parameter... And you'll be able to read them using this.config.read('mykey').

module.exports = {
  config: {
    multi: true
  },    
  ...
}

Parameters

The params field defines which parameters are prompted to the user. Prompting is handled by Inquirer.js, you can read their documentation to have a full explanation of each type.

To sum up:

{
 type: 'input',
 name: 'package',
 message: 'Operation package:',
 store: true,
 validate: function(value) {
   return value.split('.').length === 0 ? '' : true;
 },
 filter: function(answer) {
   return answer.replace(/\s+/g, '.');
 }
}
  • type: is the type of the input input, checkbox,...
  • name: variable name
  • message: message displayed to help the user answering
  • validate: function to ensure the user input is right
  • filter: function called after the user input finished to change it

Java classes

Define main or test Java classes to be generated to a java-main, or java-test field. For both, each entry is an object with a src and a dest entries. The src value should refer to a local file in the classes folder; and dest only to the expected filename. The package is handled automatically from the package parameter of your generator. The when function is not mandatory, it makes possible to skip some classes generation depending of the answers values.

module.exports = {
  'main-java': [{
    src: "operation.java",
    dest: "{{s.camelize(operation_name)}}.java",
    when: function(answers) {
      return true;
    }
  }],
  'test-java': [{
    src: "test.java",
    dest: "Test{{s.camelize(operation_name)}}.java",
    when: function(answers) {
      return true;
    }
  }],
}

Templates

All files/folders present in the templates folder are rendered with a simple rendering engine with parameters in its context. To template in a file path, escape it using {{param}}.

In the templating context, you have access to underscore.string to have some useful methods.

Other templates' plain files are using ejs to be rendered; with also underscore.string exposed in the s variable.

 src/main/java/{{s.unpackagize(package)}}/.empty
 ctx = {
   package: 'org.nuxeo.readme'
 }
 Will create a folder: src/main/java/org/nuxeo/readme

You can also ignore some files during the templating symtem. To do that, add a templates-ignore containing an array of regex that matches the ignored files.

'templates-ignore': [/\.html$/, /.+xx.+/],

Contributions

Contributions are handled a similar way than java classes;

contributions: [{
  src: "operation.xml",
  dest: "{{s.dasherize(s.decapitalize(operation_name))}}-operation-contrib.xml"
}],

Dependencies

Adding dependencies to the target pom.xml file. A dependency is described with its GAV: <groupId>:<artifactId>[:<version>[:<extension>[:<classifier>]]].

It also allows to add all 'parent child modules' as project dependencies, useful for the Package project's pom.xml.

dependencies: [
  "org.nuxeo.ecm.automation:nuxeo-automation-core",
  "org.nuxeo.ecm.automation:nuxeo-automation-test:::test"
]
or
dependencies: 'inherited'

Post Installation Commands

Post installation commands are run inside the corresponding module folder in case of a multi-module project. Useful to install npm or bower dependencies at install time.

install: [{
  cmd: 'npm', // The command to spawn.
  args: ['arg1', 'arg2'], // Arguments passed to the command without any modification.
  opts: {
    something: true,
    default: 'value'
  } // And command options if needed. Check https://www.npmjs.com/package/dargs to understand the conversion logic.
}]

Licensing

Apache License, Version 2.0

About Nuxeo

Nuxeo dramatically improves how content-based applications are built, managed and deployed, making customers more agile, innovative and successful. Nuxeo provides a next generation, enterprise ready platform for building traditional and cutting-edge content oriented applications. Combining a powerful application development environment with SaaS-based tools and a modular architecture, the Nuxeo Platform and Products provide clear business value to some of the most recognizable brands including Verizon, Electronic Arts, Sharp, FICO, the U.S. Navy, and Boeing. Nuxeo is headquartered in New York and Paris. More information is available at www.nuxeo.com.