mirror of
https://github.com/valitydev/rbk-templator.git
synced 2024-11-06 16:55:16 +00:00
Java service generator added
This commit is contained in:
parent
b308afde60
commit
6ba56e1b49
75
generators/service-generator.js
Normal file
75
generators/service-generator.js
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
module.exports = {
|
||||||
|
description: 'Create a java service project structure',
|
||||||
|
prompts: [
|
||||||
|
{
|
||||||
|
type: 'input',
|
||||||
|
name: 'name',
|
||||||
|
message: 'Как называется ваш проект?',
|
||||||
|
validate: function (value) {
|
||||||
|
if (value.length === 0) {
|
||||||
|
return "Вы не ввели имя!";
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'input',
|
||||||
|
name: 'description',
|
||||||
|
message: 'Введите описание вашего сервиса (maven.description):'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'input',
|
||||||
|
name: 'path',
|
||||||
|
message: 'В какой директории создать шаблон? [.]'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'confirm',
|
||||||
|
name: 'withBuildUtils',
|
||||||
|
message: 'Хотите ли вы подключить build_utils?'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
type: 'add',
|
||||||
|
path: '{{pathHelper path}}src/main/java/com/rbkmoney/{{lowerCase name}}/{{sentenceCase name}}Application.java',
|
||||||
|
templateFile: 'plop-templates/service/java-app.java'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'add',
|
||||||
|
path: '{{pathHelper path}}src/main/resources/application.properties',
|
||||||
|
templateFile: 'plop-templates/service/spring.properties'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'add',
|
||||||
|
path: '{{pathHelper path}}src/test/resources/logback-test.xml',
|
||||||
|
templateFile: 'plop-templates/service/service-logback.xml'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'add',
|
||||||
|
path: '{{pathHelper path}}src/test/java/com/rbkmoney/{{lowerCase name}}/{{sentenceCase name}}ApplicationTest.java',
|
||||||
|
templateFile: 'plop-templates/service/java-app-test.java'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'add',
|
||||||
|
path: '{{pathHelper path}}Jenkinsfile',
|
||||||
|
templateFile: 'plop-templates/service/service' +
|
||||||
|
'-jenkinsfile'
|
||||||
|
},
|
||||||
|
(answers) => {
|
||||||
|
if (answers.withBuildUtils) {
|
||||||
|
let git = require('simple-git')(answers.path);
|
||||||
|
git.subModule(["add", "-b", "master", "git@github.com:rbkmoney/build_utils.git", "build_utils"]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'add',
|
||||||
|
path: '{{pathHelper path}}.gitignore',
|
||||||
|
templateFile: 'plop-templates/gitignore-template'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'add',
|
||||||
|
path: '{{pathHelper path}}pom.xml',
|
||||||
|
templateFile: 'plop-templates/service/service-pom.xml'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
5
helpers/path-helper.js
Normal file
5
helpers/path-helper.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
module.exports = function (path) {
|
||||||
|
if (path && path.lastIndexOf("/") === (path.length - 1))
|
||||||
|
path = path.substring(0, path.lastIndexOf("/"));
|
||||||
|
return path ? path + "/" : "";
|
||||||
|
};
|
16
plop-templates/service/java-app-test.java
Normal file
16
plop-templates/service/java-app-test.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package com.rbkmoney.{{lowerCase name}};
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest(classes = {{sentenceCase name}}Application.class)
|
||||||
|
public class {{sentenceCase name}}ApplicationTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void contextLoads() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
15
plop-templates/service/java-app.java
Normal file
15
plop-templates/service/java-app.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package com.rbkmoney.{{lowerCase name}};
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||||
|
|
||||||
|
@ServletComponentScan
|
||||||
|
@SpringBootApplication
|
||||||
|
public class {{sentenceCase name}}Application extends SpringApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run({{sentenceCase name}}Application.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
plop-templates/service/service-jenkinsfile
Normal file
16
plop-templates/service/service-jenkinsfile
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#!groovy
|
||||||
|
build('{{lowerCase name}}', 'java-maven') {
|
||||||
|
checkoutRepo()
|
||||||
|
loadBuildUtils()
|
||||||
|
|
||||||
|
def javaServicePipeline
|
||||||
|
runStage('load JavaService pipeline') {
|
||||||
|
javaServicePipeline = load("build_utils/jenkins_lib/pipeJavaService.groovy")
|
||||||
|
}
|
||||||
|
|
||||||
|
def serviceName = env.REPO_NAME
|
||||||
|
def mvnArgs = '-DjvmArgs="-Xmx256m"'
|
||||||
|
def useJava11 = true
|
||||||
|
|
||||||
|
javaServicePipeline(serviceName, useJava11, mvnArgs)
|
||||||
|
}
|
10
plop-templates/service/service-logback.xml
Normal file
10
plop-templates/service/service-logback.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration>
|
||||||
|
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
|
||||||
|
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
|
||||||
|
|
||||||
|
<root level="warn">
|
||||||
|
<appender-ref ref="CONSOLE"/>
|
||||||
|
</root>
|
||||||
|
<logger name="com.rbkmoney.woody" level="ALL"/>
|
||||||
|
</configuration>
|
130
plop-templates/service/service-pom.xml
Normal file
130
plop-templates/service/service-pom.xml
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.rbkmoney</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>2.1.1.RELEASE</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>{{lowerCase name}}</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>{{sentenceCase name}}</name>
|
||||||
|
<description>{{description}}</description>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
<java.version>11</java.version>
|
||||||
|
<server.port>8022</server.port>
|
||||||
|
<exposed.ports>${server.port}</exposed.ports>
|
||||||
|
<dockerfile.base.service.tag>81f57f9ef5e5854c27659c9f56f59cdb2b7c43e5</dockerfile.base.service.tag>
|
||||||
|
<shared.resources.version>0.3.2</shared.resources.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.rbkmoney</groupId>
|
||||||
|
<artifactId>shared-resources</artifactId>
|
||||||
|
<version>${shared.resources.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
|
<version>4.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.rbkmoney.woody</groupId>
|
||||||
|
<artifactId>woody-thrift</artifactId>
|
||||||
|
<version>1.1.15</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.rbkmoney</groupId>
|
||||||
|
<artifactId>spring-boot-starter-metrics-statsd</artifactId>
|
||||||
|
<version>1.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.4</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>${project.build.directory}/maven-shared-archive-resources</directory>
|
||||||
|
<targetPath>${project.build.directory}</targetPath>
|
||||||
|
<includes>
|
||||||
|
<include>Dockerfile</include>
|
||||||
|
</includes>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>${project.build.directory}/maven-shared-archive-resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
<excludes>
|
||||||
|
<exclude>Dockerfile</exclude>
|
||||||
|
</excludes>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>2.1.1.RELEASE</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-remote-resources-plugin</artifactId>
|
||||||
|
<version>1.6.0</version>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven.shared</groupId>
|
||||||
|
<artifactId>maven-filtering</artifactId>
|
||||||
|
<version>1.3</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<configuration>
|
||||||
|
<resourceBundles>
|
||||||
|
<resourceBundle>com.rbkmoney:shared-resources:${shared.resources.version}</resourceBundle>
|
||||||
|
</resourceBundles>
|
||||||
|
<attachToMain>false</attachToMain>
|
||||||
|
<attachToTest>false</attachToTest>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>process</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
10
plop-templates/service/spring.properties
Normal file
10
plop-templates/service/spring.properties
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
server.port=@server.port@
|
||||||
|
management.security.flag=false
|
||||||
|
spring.application.name=@project.name@
|
||||||
|
info.version=@project.version@
|
||||||
|
info.stage=dev
|
||||||
|
|
||||||
|
management.metrics.export.statsd.flavor=etsy
|
||||||
|
#management.metrics.export.statsd.enabled=true
|
||||||
|
#management.metrics.export.statsd.host=localhost
|
||||||
|
#management.metrics.export.statsd.port=8125
|
36
plopfile.js
36
plopfile.js
@ -1,38 +1,16 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
let protoGenerator = require('./generators/proto-generator');
|
let protoGenerator = require('./generators/proto-generator');
|
||||||
|
let serviceGenerator = require('./generators/service-generator');
|
||||||
|
let pathHelper = require('./helpers/path-helper');
|
||||||
let chalk = require('chalk');
|
let chalk = require('chalk');
|
||||||
|
|
||||||
module.exports = function (plop) {
|
module.exports = function (plop) {
|
||||||
plop.setWelcomeMessage(chalk.blue("КАКОЙ ") + chalk.red("ПРОЕКТ ") + chalk.blue("ВАМ ") + chalk.red("ЗАПИЛИТЬ???"));
|
plop.setWelcomeMessage(chalk.blue("КАКОЙ ") + chalk.red("ПРОЕКТ ") + chalk.blue("ВАМ ") + chalk.red("ЗАПИЛИТЬ???"));
|
||||||
plop.addHelper('pathHelper', function (path) {
|
|
||||||
if (path && path.lastIndexOf("/") === (path.length - 1))
|
// helpers
|
||||||
path = path.substring(0, path.lastIndexOf("/"));
|
plop.addHelper('pathHelper', pathHelper);
|
||||||
return path ? path + "/" : "";
|
|
||||||
});
|
|
||||||
// generators
|
// generators
|
||||||
plop.setGenerator('java-proto', protoGenerator);
|
plop.setGenerator('java-proto', protoGenerator);
|
||||||
|
plop.setGenerator('java-service', serviceGenerator);
|
||||||
|
|
||||||
plop.setGenerator('java-service', {
|
|
||||||
description: 'Create a java service project structure',
|
|
||||||
prompts: [
|
|
||||||
{
|
|
||||||
type: 'input',
|
|
||||||
name: 'name',
|
|
||||||
message: 'Как называется ваш протокол? (без "-proto")'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
actions: [
|
|
||||||
(answers) => {
|
|
||||||
console.log(`You choose: \n
|
|
||||||
- name: ${answers.name}`);
|
|
||||||
return '';
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'add',
|
|
||||||
path: 'app/tests/{{lowerCase path}}/{{lowerCase name}}.thrift',
|
|
||||||
templateFile: 'plop-templates/modules/proto.thrift'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user