Skip to content

Commit

Permalink
update generator-jhipster to 8.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jhipster-bot committed Sep 26, 2024
1 parent 22de23b commit 1dbcba6
Show file tree
Hide file tree
Showing 22 changed files with 3,601 additions and 3,727 deletions.
31 changes: 31 additions & 0 deletions .blueprint/cli/commands.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* 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 defaultCommands = {
'generate-sample': {
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;
61 changes: 61 additions & 0 deletions .blueprint/generate-sample/command.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* 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 { GENERATOR_APP } from 'generator-jhipster/generators';
import { getSamples } from './get-samples.mjs';

/**
* @type {import('generator-jhipster').JHipsterCommandDefinition}
*/
const command = {
arguments: {
sampleName: {
type: String,
},
},
configs: {
sampleName: {
prompt: gen => ({
when: !gen.all,
type: 'list',
message: 'which sample do you want to generate?',
choices: async () => getSamples(gen.templatePath(gen.samplesFolder)),
}),
scope: 'generator',
},
all: {
description: 'Generate every sample in a workspace',
cli: {
type: Boolean,
},
scope: 'generator',
},
samplesFolder: {
description: 'Path to the samples folder',
cli: {
type: String,
},
default: 'samples',
scope: 'generator',
},
},
options: {},
import: [GENERATOR_APP],
};

export default command;
49 changes: 49 additions & 0 deletions .blueprint/generate-sample/generator.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { readdir } from 'node:fs/promises';
import { readFileSync } from 'node:fs';
import BaseGenerator from 'generator-jhipster/generators/base';

export default class extends BaseGenerator {
sampleName;
all;
samplesFolder;

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

get [BaseGenerator.WRITING]() {
return this.asWritingTaskGroup({
async copySample() {
const samplesFolder = `${this.samplesFolder ?? 'samples'}/`;
if (this.all) {
this.copyTemplate(`${samplesFolder}*.jdl`, '');
} else {
this.copyTemplate(`${samplesFolder}${this.sampleName}`, this.sampleName, { noGlob: true });
}
},
});
}

get [BaseGenerator.END]() {
return this.asEndTaskGroup({
async generateSample() {
const packageJson = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url)));
const projectVersion = `${packageJson.version}-git`;

await this.composeWithJHipster('jdl', {
generatorArgs: this.all ? await readdir(this.templatePath('samples')) : [this.sampleName],
generatorOptions: {
skipJhipsterDependencies: true,
insight: false,
skipChecks: true,
projectVersion,
...(this.all ? { workspaces: true, monorepository: true } : { skipInstall: true }),
},
});
},
async jhipsterInfo() {
await this.composeWithJHipster('info');
},
});
}
}
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'));
};
2 changes: 2 additions & 0 deletions .blueprint/generate-sample/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';
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;
29 changes: 29 additions & 0 deletions .blueprint/github-build-matrix/generator.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { appendFileSync, existsSync } 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, queueCommandTasks: true, jhipsterBootstrap: false });
}

get [BaseGenerator.WRITING]() {
return this.asWritingTaskGroup({
async buildMatrix() {
const samplesFolder = this.samplesFolder ?? 'samples';
const samples = await getSamples(this.templatePath(`../../generate-sample/templates/${samplesFolder}`));
const matrix = buildMatrix({ samples, 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';
5 changes: 2 additions & 3 deletions .github/workflows/generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ jobs:
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
cache: 'npm'
- run: git config --global user.name "JHipster Bot"; git config --global user.email "[email protected]"; git config --global init.defaultBranch main
- run: npm ci
- run: npm run test
7 changes: 3 additions & 4 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Prettier configuration

printWidth: 140
singleQuote: true
tabWidth: 2
useTabs: false

# js and ts rules:
arrowParens: avoid
bracketSameLine: false
plugins:
- prettier-plugin-packagejson
3 changes: 2 additions & 1 deletion .yo-rc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
}
},
"githubWorkflows": true,
"jhipsterVersion": "7.7.0",
"jhipsterVersion": "8.7.1",
"js": true,
"localBlueprint": false,
"packageJsonType": "module",
"prettierDefaultIndent": 2,
"projectName": "JHipster Migrate Blueprint",
"sampleWritten": true,
Expand Down
2 changes: 2 additions & 0 deletions cli/cli-customizations.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This file will not be overwritten by generate-blueprint
module.exports = {};
14 changes: 10 additions & 4 deletions cli/cli.cjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/env node

const { dirname, join } = require('path');
const { dirname, basename, join } = require('path');
const { version, bin } = require('../package.json');

// Get package name to use as namespace.
// Allows blueprints to be aliased.
const packagePath = dirname(__dirname);
const packageFolderName = basename(packagePath);
const devBlueprintPath = join(packagePath, '.blueprint');
const blueprint = packageFolderName.startsWith('jhipster-') ? `generator-${packageFolderName}` : packageFolderName;

(async () => {
const { runJHipster, done, logger } = await import('generator-jhipster/cli');
Expand All @@ -15,14 +17,18 @@ const devBlueprintPath = join(packagePath, '.blueprint');
runJHipster({
executableName,
executableVersion: version,
defaultCommand: 'migrate',
defaultCommand: 'app',
devBlueprintPath,
commands: require('./commands.cjs'),
blueprints: {
[blueprint]: version,
},
printBlueprintLogo: () => {
console.log('===================== JHipster migrate =====================');
console.log('===================== JHipster Migrate =====================');
console.log('');
},
lookups: [{ packagePaths: [packagePath] }],
commands: require('./commands.cjs'),
...require('./cli-customizations.cjs'),
}).catch(done);

process.on('unhandledRejection', up => {
Expand Down
14 changes: 10 additions & 4 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import globals from 'globals';
import prettierRecommended from 'eslint-plugin-prettier/recommended';
import jhipsterRecommended from 'generator-jhipster/eslint/recommended';
import prettier from 'eslint-plugin-prettier/recommended';
import jhipster from 'generator-jhipster/eslint/recommended';

// Workaround for jhipster export issue.
delete jhipster.recommended.recommended;
// jhipster-needle-eslint-add-import - JHipster will add additional import here

export default [
{
Expand All @@ -10,6 +14,8 @@ export default [
},
},
},
jhipsterRecommended,
prettierRecommended,
{ ignores: ['coverage/**'] },
jhipster.recommended,
// jhipster-needle-eslint-add-config - JHipster will add additional config here
prettier,
];
11 changes: 4 additions & 7 deletions generators/migrate/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import chalk from 'chalk';

const choices = '(none, current, bundled, any npm version)';

/**
* @type {import('generator-jhipster').JHipsterCommandDefinition}
*/
const command = {
import { asCommand } from 'generator-jhipster';

export default asCommand({
options: {},
configs: {
sourceCli: {
Expand Down Expand Up @@ -86,6 +85,4 @@ const command = {
scope: 'generator',
},
},
};

export default command;
});
Loading

0 comments on commit 1dbcba6

Please sign in to comment.