Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contribution #431

Merged
merged 3 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .blueprint/cli/commands.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const defaultCommands = {
desc: 'Generate a test sample',
blueprint: '@jhipster/jhipster-dev',
},
synchronize: {
desc: 'Synchronize templates from generator-jhipster',
blueprint: '@jhipster/jhipster-dev',
},
};

export default defaultCommands;
40 changes: 40 additions & 0 deletions .blueprint/synchronize/command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright 2013-2024 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 command = {
configs: {
newFiles: {
description: 'Add new files only',
cli: {
type: Boolean,
},
scope: 'generator',
},
convert: {
description: 'Apply Partial Java files to Kotlin files convertion',
cli: {
type: Boolean,
alias: 'c',
},
scope: 'generator',
},
},
import: [],
};

export default command;
88 changes: 88 additions & 0 deletions .blueprint/synchronize/generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* Copyright 2013-2024 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.
*/
import { basename, dirname, join, relative } from 'path';
import { fileURLToPath } from 'url';
import { existsSync } from 'fs';
import BaseGenerator from 'generator-jhipster/generators/base';
import { globby } from 'globby';
import { passthrough } from '@yeoman/transform';
import { convertToKotlinFile } from '../../generators/kotlin/support/index.js';

const __dirname = dirname(fileURLToPath(import.meta.url));
const jhipster8Generators = join(__dirname, '../../node_modules/generator-jhipster/dist/generators');

export default class SynchronizeGenerator extends BaseGenerator {
constructor(args, options, features) {
super(args, options, { queueCommandTasks: true, ...features });
}

get [BaseGenerator.DEFAULT]() {
return this.asDefaultTaskGroup({
default() {
if (this.options.convert === false) {
return;
}
this.queueTransformStream(
{
name: 'convert to kt file',
filter: file => file.path.endsWith('.kt.ejs'),
},
passthrough(file => {
file.contents = Buffer.from(
file.contents
.toString()
.replaceAll(';\n', '\n')
.replaceAll('\nimport static ', '\nimport ')
.replaceAll('public class ', 'class ')
.replaceAll('.class', '::class')
.replaceAll(/ (?:extends|implements) (\w+)/g, ' : $1')
.replaceAll(/ (?:extends|implements) /g, ' : ')
.replaceAll(/@Override\n(\s*)/g, 'override ')
.replaceAll(/\n( {4})(private |)?(?:final )?(\w+) (\w+)(\n| = )/g, '\n$1$2lateinit var $4: $3$5')
.replaceAll(/private static final (\w+) /g, 'private val ')
.replaceAll(/(?:public |protected )?(\w+) (\w+)\((.*)\) {/g, 'fun $2($3): $1 {')
.replaceAll(': void', ''),
);
}),
);
},
});
}

get [BaseGenerator.WRITING]() {
return this.asWritingTaskGroup({
async writing() {
const files = await globby(`${jhipster8Generators}/**/*.java.ejs`);
const ktTemplatesPath = this.destinationPath('generators/spring-boot/templates');
for (const file of files.filter(
file => !file.includes('/spring-data-couchbase/') && !['GeneratedByJHipster.java.ejs'].includes(basename(file)),
)) {
const relativeDestinationFile = convertToKotlinFile(relative(jhipster8Generators, file))
.replace('spring-boot/templates/', '')
.replace('server/templates/', '')
.replace(/(?:(?:.*)\/generators\/)?(.*)\/templates/, '$1');
const destinationFile = join(ktTemplatesPath, relativeDestinationFile);
if (this.options.newFiles !== true || !existsSync(destinationFile)) {
this.copyTemplate(file, destinationFile);
}
}
},
});
}
}
20 changes: 20 additions & 0 deletions .blueprint/synchronize/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright 2013-2024 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.
*/
export { default } from './generator.js';
export { default as command } from './command.js';
2 changes: 1 addition & 1 deletion .yo-resolve
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
generators/**
generators/*.*
.prettierrc.yml skip
cli/cli.cjs skip
README.md skip
21 changes: 15 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

## To run the application in development

### Step 1 👍 : install [yeoman](https://yeoman.io/)

`npm install -g yo | yarn global add yo`

### Step 2 ✌️ : to setup JHipster-Kotlin generator
### Step 1 ✌️ : to setup JHipster-Kotlin generator

`git clone https://github.com/jhipster/jhipster-kotlin`

Expand All @@ -18,7 +14,7 @@

( 🏁 Kudos, you just setup JHipster-Kotlin and linked to it locally )

### Step 3 🤟 : before generating your application, go to your application folder
### Step 2 🤟 : before generating your application, go to your application folder

`yarn link "generator-jhipster-kotlin"`

Expand All @@ -32,6 +28,19 @@ or

Fix / Code / Document and create a pull request 💯

### Synchronizing generator-jhipster templates

Run:

```sh
khipster synchronize
```

In the conflict resolution, check diff and press `i` if the template is synchronized.
`i` choice will add that file to be ignored in `.yo-resolve` file.

When synchronization is done revert `.yo-resolve` file to the initial previous state.

### Regular Contributor Guidelines

These are some of the guidelines that we would like you to follow if you are a regular contributor to the project
Expand Down
Loading