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

Update generator-jhipster to 8.6.0 #262

Merged
merged 3 commits into from
Jun 25, 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',
},
'github-build-matrix': {
desc: 'Build a matrix of jobs for github actions',
blueprint: '@jhipster/jhipster-dev',
},
};

export default defaultCommands;
12 changes: 10 additions & 2 deletions .blueprint/generate-sample/command.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { readdir } from 'node:fs/promises';
import { GENERATOR_APP } from 'generator-jhipster/generators';
import { getSamples } from './get-samples.mjs';

/**
* @type {import('generator-jhipster').JHipsterCommandDefinition}
Expand All @@ -34,7 +34,7 @@ const command = {
when: !gen.all,
type: 'list',
message: 'which sample do you want to generate?',
choices: async () => readdir(gen.templatePath('samples')),
choices: async () => getSamples(gen.templatePath(gen.samplesFolder)),
}),
scope: 'generator',
},
Expand All @@ -45,6 +45,14 @@ const command = {
},
scope: 'generator',
},
samplesFolder: {
description: 'Path to the samples folder',
cli: {
type: String,
},
default: 'samples',
scope: 'generator',
},
},
options: {},
import: [GENERATOR_APP],
Expand Down
18 changes: 11 additions & 7 deletions .blueprint/generate-sample/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import BaseGenerator from 'generator-jhipster/generators/base';
export default class extends BaseGenerator {
sampleName;
all;
samplesFolder;

constructor(args, opts, features) {
super(args, opts, { ...features, jhipsterBootstrap: false });
Expand All @@ -15,11 +16,6 @@ export default class extends BaseGenerator {
async parseCommand() {
await this.parseCurrentJHipsterCommand();
},
async initializeOptions() {
if (this.sampleName && !this.sampleName.endsWith('.jdl')) {
this.sampleName += '.jdl';
}
},
});
}

Expand All @@ -31,13 +27,21 @@ export default class extends BaseGenerator {
});
}

get [BaseGenerator.LOADING]() {
return this.asLoadingTaskGroup({
async loadCommand() {
await this.loadCurrentJHipsterCommandConfig(this);
},
});
}

get [BaseGenerator.WRITING]() {
return this.asWritingTaskGroup({
async copySample() {
if (this.all) {
this.copyTemplate('samples/*.jdl', '');
this.copyTemplate(`${this.samplesFolder}/*.jdl`, '');
} else {
this.copyTemplate(`samples/${this.sampleName}`, this.sampleName, { noGlob: true });
this.copyTemplate(`${this.samplesFolder}/${this.sampleName}`, this.sampleName, { noGlob: true });
}
},
});
Expand Down
11 changes: 11 additions & 0 deletions .blueprint/generate-sample/get-samples.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { readdir, stat } from 'node:fs/promises';
import { extname } from 'path';

export const getSamples = async samplesFolder => {
const filenames = await readdir(samplesFolder);
const entries = await Promise.all(filenames.map(async filename => [filename, await stat(`${samplesFolder}/${filename}`)]));
return entries
.filter(([filename, statResult]) => extname(filename) === '.jdl' || statResult.isDirectory())
.map(([filename]) => filename)
.filter(filename => !filename.includes('disabled'));
};
24 changes: 24 additions & 0 deletions .blueprint/github-build-matrix/build-matrix.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { RECOMMENDED_JAVA_VERSION, RECOMMENDED_NODE_VERSION } from 'generator-jhipster';
import { fromMatrix } from 'generator-jhipster/testing';

const defaultMatrix = {
os: ['ubuntu-latest'],
'node-version': [RECOMMENDED_NODE_VERSION],
'java-version': [RECOMMENDED_JAVA_VERSION],
'default-environment': ['prod'],
};

export const buildMatrix = ({ samples, samplesFolder }) => {
return {
include: Object.values(
fromMatrix({
...defaultMatrix,
'sample-name': samples,
}),
).map(sample => ({
...sample,
'job-name': sample['sample-name'],
'extra-args': `--samples-folder ${samplesFolder}`,
})),
};
};
18 changes: 18 additions & 0 deletions .blueprint/github-build-matrix/command.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @type {import('generator-jhipster').JHipsterCommandDefinition}
*/
const command = {
configs: {
samplesFolder: {
description: 'Samples folder',
cli: {
type: String,
},
default: 'samples',
scope: 'generator',
},
},
options: {},
};

export default command;
44 changes: 44 additions & 0 deletions .blueprint/github-build-matrix/generator.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { existsSync, appendFileSync } from 'node:fs';
import os from 'node:os';
import BaseGenerator from 'generator-jhipster/generators/base';
import { getSamples } from '../generate-sample/get-samples.mjs';
import { buildMatrix } from './build-matrix.mjs';

export default class extends BaseGenerator {
samplesFolder;

constructor(args, opts, features) {
super(args, opts, { ...features, jhipsterBootstrap: false });
}

get [BaseGenerator.INITIALIZING]() {
return this.asInitializingTaskGroup({
async parseCommand() {
await this.parseCurrentJHipsterCommand();
},
});
}

get [BaseGenerator.LOADING]() {
return this.asLoadingTaskGroup({
async loadCommand() {
await this.loadCurrentJHipsterCommandConfig(this);
},
});
}

get [BaseGenerator.WRITING]() {
return this.asWritingTaskGroup({
async buildMatrix() {
const samples = await getSamples(this.templatePath(`../../generate-sample/templates/${this.samplesFolder}`));
const matrix = buildMatrix({ samples, samplesFolder: this.samplesFolder });
const matrixoutput = `matrix<<EOF${os.EOL}${JSON.stringify(matrix)}${os.EOL}EOF${os.EOL}`;
const filePath = process.env['GITHUB_OUTPUT'];
console.log(matrixoutput);
if (filePath && existsSync(filePath)) {
appendFileSync(filePath, matrixoutput, { encoding: 'utf8' });
}
},
});
}
}
2 changes: 2 additions & 0 deletions .blueprint/github-build-matrix/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './generator.mjs';
export { default as command } from './command.mjs';
35 changes: 0 additions & 35 deletions .eslintrc.json

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ permissions:
contents: read
jobs:
applications:
name: ${{ matrix.audit-framework }} ${{ matrix.build-tool }}) ${{ matrix.suite }} (${{ matrix.os }}
name: ${{ matrix.audit-framework }}, ${{ matrix.build-tool }}, ${{ matrix.suite }} (${{ matrix.os }})
runs-on: ${{ matrix.os }}
defaults:
run:
Expand All @@ -49,7 +49,7 @@ jobs:
build-tool: [maven, gradle]
audit-framework: [custom, javers]
suite:
- postgresql-mvc-jwt
- postgresql-mvc-jwt.jdl
steps:
#----------------------------------------------------------------------
# Install all tools and check configuration
Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package-lock.json
.git

# blueprint rules:
**/templates/**/
generators/**/templates/**/
1 change: 1 addition & 0 deletions .yo-rc.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"written": true
}
},
"githubWorkflows": true,
"jhipsterVersion": "7.9.2",
"js": true,
"localBlueprint": false,
Expand Down
15 changes: 15 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import globals from 'globals';
import prettierRecommended from 'eslint-plugin-prettier/recommended';
import jhipsterRecommended from 'generator-jhipster/eslint/recommended';

export default [
{
languageOptions: {
globals: {
...globals.node,
},
},
},
jhipsterRecommended,
prettierRecommended,
];
Loading
Loading