Skip to content

Commit

Permalink
Merge pull request #364 from mshima/generator-jhipster-8.5.0
Browse files Browse the repository at this point in the history
regenerate local blueprint
  • Loading branch information
DanielFran authored Jun 2, 2024
2 parents 3e43773 + a1bb2de commit 7169f80
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 38 deletions.
20 changes: 20 additions & 0 deletions .blueprint/generate-sample/command.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
* 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';

/**
* @type {import('generator-jhipster').JHipsterCommandDefinition}
*/
Expand All @@ -26,6 +28,24 @@ const command = {
type: String,
},
},
configs: {
sampleName: {
prompt: gen => ({
when: !gen.all,
type: 'list',
message: 'which sample do you want to generate?',
choices: async () => readdir(gen.templatePath('samples')),
}),
scope: 'generator',
},
all: {
description: 'Generate every sample in a workspace',
cli: {
type: Boolean,
},
scope: 'generator',
},
},
options: {},
import: [GENERATOR_APP],
};
Expand Down
31 changes: 12 additions & 19 deletions .blueprint/generate-sample/generator.mjs
Original file line number Diff line number Diff line change
@@ -1,48 +1,44 @@
import { readdir } from 'node:fs/promises';
import { readFileSync } from 'node:fs';
import process from 'node:process';
import BaseGenerator from 'generator-jhipster/generators/base';
import command from './command.mjs';

export default class extends BaseGenerator {
sampleName;
all;

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

get [BaseGenerator.INITIALIZING]() {
return this.asInitializingTaskGroup({
async parseCommand() {
await this.parseCurrentJHipsterCommand();
},
async initializeOptions() {
this.parseJHipsterArguments(command.arguments);
if (this.sampleName && !this.sampleName.endsWith('.jdl')) {
this.sampleName += '.jdl';
}
this.parseJHipsterOptions(command.options);
},
});
}

get [BaseGenerator.PROMPTING]() {
return this.asPromptingTaskGroup({
async askForSample() {
if (!this.sampleName) {
const answers = await this.prompt({
type: 'list',
name: 'sampleName',
message: 'which sample do you want to generate?',
choices: async () => readdir(this.templatePath('samples')),
});
this.sampleName = answers.sampleName;
}
await this.promptCurrentJHipsterCommand();
},
});
}

get [BaseGenerator.WRITING]() {
return this.asWritingTaskGroup({
async copySample() {
this.copyTemplate(`samples/${this.sampleName}`, this.sampleName, { noGlob: true });
if (this.all) {
this.copyTemplate('samples/*.jdl', '');
} else {
this.copyTemplate(`samples/${this.sampleName}`, this.sampleName, { noGlob: true });
}
},
});
}
Expand All @@ -53,17 +49,14 @@ export default class extends BaseGenerator {
const packageJson = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url)));
const projectVersion = `${packageJson.version}-git`;

process.env.JHI_PROFILE = 'dev';

await this.composeWithJHipster('jdl', {
generatorArgs: [this.sampleName],
generatorArgs: this.all ? await readdir(this.templatePath('samples')) : [this.sampleName],
generatorOptions: {
skipJhipsterDependencies: true,
insight: false,
skipChecks: true,
skipInstall: true,
reproducible: true,
projectVersion,
...(this.all ? { workspaces: true, monorepository: true } : { skipInstall: true }),
},
});
},
Expand Down
22 changes: 22 additions & 0 deletions .blueprint/github-build-matrix/build-matrix.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { readdir } from 'fs/promises';
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 = async samplesFolder => {
const samples = await readdir(samplesFolder);
return {
include: Object.values(
fromMatrix({
...defaultMatrix,
'sample-name': samples.filter(sample => !sample.includes('disabled')),
}),
),
};
};
18 changes: 3 additions & 15 deletions .blueprint/github-build-matrix/generator.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { existsSync, appendFileSync } from 'node:fs';
import os from 'node:os';
import { readdir } from 'node:fs/promises';
import BaseGenerator from 'generator-jhipster/generators/base';
import { RECOMMENDED_NODE_VERSION, RECOMMENDED_JAVA_VERSION } from 'generator-jhipster';
import { buildMatrix } from './build-matrix.mjs';

export default class extends BaseGenerator {
constructor(args, opts, features) {
Expand All @@ -12,23 +11,12 @@ export default class extends BaseGenerator {
get [BaseGenerator.WRITING]() {
return this.asWritingTaskGroup({
async buildMatrix() {
const samples = await readdir(this.templatePath('../../generate-sample/templates/samples'));
const matrix = {
include: samples
.filter(sample => !sample.includes('disabled'))
.map(sample => ({
'sample-name': sample,
'node-version': RECOMMENDED_NODE_VERSION,
'java-version': RECOMMENDED_JAVA_VERSION,
'build-tool': sample.includes('gradle') ? 'gradle' : 'maven',
})),
};
const matrix = await buildMatrix(this.templatePath('../../generate-sample/templates/samples'));
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' });
} else {
console.log(matrixoutput);
}
},
});
Expand Down
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"env": {
"node": true,
"es2020": true
"es2022": true
},
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"parserOptions": {
"ecmaVersion": 11,
"ecmaVersion": 13,
"sourceType": "module"
},
"overrides": [
Expand Down
1 change: 1 addition & 0 deletions .yo-rc.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"written": true
}
},
"githubWorkflows": true,
"jhipsterVersion": "8.2.1",
"js": true,
"localBlueprint": false,
Expand Down
4 changes: 2 additions & 2 deletions .yo-resolve
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
!package.json skip

generators/**
README.md
1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export default defineConfig({
pool: 'forks',
hookTimeout: 20000,
exclude: [...defaultExclude.filter(val => val !== '**/cypress/**'), '**/templates/**', '**/resources/**'],
setupFiles: ['./vitest.test-setup.ts'],
},
});

0 comments on commit 7169f80

Please sign in to comment.