Skip to content

Commit

Permalink
Initial spring-boot generator.
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Jul 25, 2021
1 parent 07f1e4a commit c9021e0
Show file tree
Hide file tree
Showing 15 changed files with 640 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cli/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ const defaultCommands = {
desc: 'Run a module or custom generator',
argument: ['[generator]'],
},
'spring-boot': {
desc: 'Create a Spring Boot application (alpha)',
},
'spring-service': {
alias: 'service',
desc: 'Create a new Spring service bean',
Expand Down
1 change: 1 addition & 0 deletions generators/generator-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const Generators = {
GENERATOR_PAGE: 'page',
GENERATOR_PROJECT_NAME: 'project-name',
GENERATOR_SERVER: 'server',
GENERATOR_SPRING_BOOT: 'spring-boot',
};

module.exports = Generators;
80 changes: 80 additions & 0 deletions generators/spring-boot/__snapshots__/generator.spec.cjs.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`JHipster spring-boot generator with add option and default config should write only spring-boot files and match snapshot 1`] = `
Object {
".yo-rc.json": Object {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/JhipsterApp.java": Object {
"stateCleared": "modified",
},
"src/main/resources/application.properties": Object {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/JhipsterAppTests.java": Object {
"stateCleared": "modified",
},
}
`;

exports[`JHipster spring-boot generator with default config should write java files and match snapshot 1`] = `
Object {
".editorconfig": Object {
"stateCleared": "modified",
},
".gitattributes": Object {
"stateCleared": "modified",
},
".gitignore": Object {
"stateCleared": "modified",
},
".huskyrc": Object {
"stateCleared": "modified",
},
".lintstagedrc.js": Object {
"stateCleared": "modified",
},
".mvn/wrapper/MavenWrapperDownloader.java": Object {
"stateCleared": "modified",
},
".mvn/wrapper/maven-wrapper.jar": Object {
"stateCleared": "modified",
},
".mvn/wrapper/maven-wrapper.properties": Object {
"stateCleared": "modified",
},
".prettierignore": Object {
"stateCleared": "modified",
},
".prettierrc.yml": Object {
"stateCleared": "modified",
},
".yo-rc.json": Object {
"stateCleared": "modified",
},
"README.md": Object {
"stateCleared": "modified",
},
"mvnw": Object {
"stateCleared": "modified",
},
"mvnw.cmd": Object {
"stateCleared": "modified",
},
"package.json": Object {
"stateCleared": "modified",
},
"pom.xml": Object {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/JhipsterApp.java": Object {
"stateCleared": "modified",
},
"src/main/resources/application.properties": Object {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/JhipsterAppTests.java": Object {
"stateCleared": "modified",
},
}
`;
27 changes: 27 additions & 0 deletions generators/spring-boot/config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright 2013-2021 the original author or authors from the JHipster project.
*
* This file is part of the JHipster project, see https://www.jhipster.tech/
* for more information.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** Config required at .yo-rc.json */
const requiredConfig = {};

/** Default config for templates */
const defaultConfig = {
...requiredConfig,
};

module.exports = { requiredConfig, defaultConfig };
23 changes: 23 additions & 0 deletions generators/spring-boot/constants.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Copyright 2013-2021 the original author or authors from the JHipster project.
*
* This file is part of the JHipster project, see https://www.jhipster.tech/
* for more information.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const SPRING_BOOT_VERSION = '2.5.2';

module.exports = {
SPRING_BOOT_VERSION,
};
46 changes: 46 additions & 0 deletions generators/spring-boot/files.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright 2013-2021 the original author or authors from the JHipster project.
*
* This file is part of the JHipster project, see https://www.jhipster.tech/
* for more information.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const { SRC_MAIN_JAVA_DIR, SRC_MAIN_RESOURCES_DIR, SRC_TEST_JAVA_DIR } = require('../java/constants.cjs');

module.exports.files = {
springBootProject: [
{
templates: ['pom.xml.jhi.spring-boot'],
},
{
path: SRC_MAIN_RESOURCES_DIR,
templates: ['application.properties.jhi'],
},
{
path: SRC_MAIN_JAVA_DIR,
templates: [
{ file: 'package/Application.java.jhi', renameTo: generator => `${generator.packageFolder}/${generator.javaMainClass}.java.jhi` },
],
},
{
path: SRC_TEST_JAVA_DIR,
templates: [
{
file: 'package/ApplicationTests.java.jhi',
renameTo: generator => `${generator.packageFolder}/${generator.javaMainClass}Tests.java.jhi`,
},
],
},
],
};
58 changes: 58 additions & 0 deletions generators/spring-boot/generator.spec.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Copyright 2013-2021 the original author or authors from the JHipster project.
*
* This file is part of the JHipster project, see https://www.jhipster.tech/
* for more information.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const expect = require('expect');
const path = require('path');

const { basicTests, testBlueprintSupport } = require('../../test/support/index.cjs');
const { skipPrettierHelpers: helpers } = require('../../test/utils/utils');
const { requiredConfig, defaultConfig } = require('./config.cjs');

const generatorPath = path.join(__dirname, 'index.cjs');

describe('JHipster spring-boot generator', () => {
basicTests({
requiredConfig,
defaultConfig,
customPrompts: {},
generatorPath,
});
describe('blueprint support', () => testBlueprintSupport('spring-boot'));
describe('with', () => {
describe('default config', () => {
let runResult;
before(async () => {
runResult = await helpers.run(generatorPath);
});
it('should write java files and match snapshot', () => {
expect(runResult.getStateSnapshot()).toMatchSnapshot();
});
});
});
describe('with add option and', () => {
describe('default config', () => {
let runResult;
before(async () => {
runResult = await helpers.run(generatorPath).withOptions({ add: true });
});
it('should write only spring-boot files and match snapshot', () => {
expect(runResult.getStateSnapshot()).toMatchSnapshot();
});
});
});
});
Loading

0 comments on commit c9021e0

Please sign in to comment.