tech.jhipster.lite.generator.init.domain.InitModuleFactory Maven / Gradle / Ivy
package tech.jhipster.lite.generator.init.domain;
import static tech.jhipster.lite.module.domain.JHipsterModule.*;
import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.file.JHipsterDestination;
import tech.jhipster.lite.module.domain.file.JHipsterSource;
import tech.jhipster.lite.module.domain.npm.NpmVersions;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
import tech.jhipster.lite.shared.error.domain.Assert;
public class InitModuleFactory {
private static final JHipsterSource SOURCE = from("init");
private static final JHipsterDestination DESTINATION = to(".");
private final NpmVersions npmVersions;
public InitModuleFactory(NpmVersions npmVersions) {
Assert.notNull("npmVersions", npmVersions);
this.npmVersions = npmVersions;
}
public JHipsterModule buildModule(JHipsterModuleProperties properties) {
//@formatter:off
return moduleBuilder(properties)
.context()
.put("dasherizedBaseName", properties.projectBaseName().kebabCase())
.put("nodeMajorVersion", npmVersions.nodeVersion().majorVersion())
.put("endOfLine", endOfLine(properties))
.and()
.files()
.batch(SOURCE, DESTINATION)
.addTemplate("README.md")
.addTemplate("package.json")
.addTemplate(".editorconfig")
.and()
.add(SOURCE.file("gitignore"), to(".gitignore"))
.add(SOURCE.file("gitattributes"), to(".gitattributes"))
.and()
.build();
//@formatter:on
}
private String endOfLine(JHipsterModuleProperties properties) {
return properties.getOrDefaultString("endOfLine", "lf");
}
}