Skip to content
Draft
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
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import type { JHipsterCommandDefinition } from 'generator-jhipster';
import { getGithubSamplesGroup, getGithubSamplesGroups } from 'generator-jhipster/ci';

import type Generator from './generator.js';

const DEFAULT_SAMPLES_GROUP = 'samples';

/**
* @type {import('generator-jhipster').JHipsterCommandDefinition}
*/
const command = {
arguments: {
sampleName: {
Expand Down Expand Up @@ -59,7 +59,7 @@ const command = {
when: !gen.all,
type: 'select',
message: 'which sample do you want to generate?',
choices: async answers => {
choices: async (answers: any) => {
const samples = await getGithubSamplesGroup(gen.templatePath(), answers.samplesGroup ?? gen.samplesGroup);
return Object.keys(samples.samples);
},
Expand All @@ -75,6 +75,6 @@ const command = {
},
},
import: ['app'],
};
} as const satisfies JHipsterCommandDefinition<Generator>;

export default command;
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,13 @@ import { getGithubSamplesGroup } from 'generator-jhipster/ci';
import BaseCoreGenerator from 'generator-jhipster/generators/base-core';

export default class extends BaseCoreGenerator {
/** @type {string | undefined} */
samplesFolder;
/** @type {string} */
samplesGroup;
/** @type {string} */
sampleName;
/** @type {boolean} */
all;
/** @type {string} */
sampleType;
/** @type {string} */
sampleFile;
/** @type {any} */
generatorOptions;
samplesFolder?: string;
samplesGroup!: string;
sampleName!: string;
all?: boolean;
sampleType?: string;
sampleFile?: string;
generatorOptions: any;

get [BaseCoreGenerator.WRITING]() {
return this.asAnyTaskGroup({
Expand All @@ -40,7 +33,7 @@ export default class extends BaseCoreGenerator {
'sample-folder': sampleFolder = samplesPath,
generatorOptions,
templateOptions = {},
} = samples[sampleName];
} = samples[sampleName] as any;

this.generatorOptions = generatorOptions;
this.sampleType = sampleType === 'jdl-ejs' ? 'jdl' : sampleType;
Expand Down Expand Up @@ -92,7 +85,7 @@ export default class extends BaseCoreGenerator {
}

getDefaultComposeOptions() {
const packageJson = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url)));
const packageJson = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), { encoding: 'utf-8' }));
const projectVersion = `${packageJson.version}-git`;
return {
skipJhipsterDependencies: true,
Expand Down
2 changes: 0 additions & 2 deletions .blueprint/generate-sample/index.mjs

This file was deleted.

2 changes: 2 additions & 0 deletions .blueprint/generate-sample/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './generator.ts';
export { default as command } from './command.ts';
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* @type {import('generator-jhipster').JHipsterCommandDefinition}
*/
import type { JHipsterCommandDefinition } from 'generator-jhipster';

const command = {
configs: {
samplesFolder: {
Expand All @@ -19,6 +18,6 @@ const command = {
scope: 'generator',
},
},
};
} as const satisfies JHipsterCommandDefinition;

export default command;
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import { beforeAll, describe, expect, it } from 'vitest';
import { basename, join } from 'path';
import { basename, join } from 'node:path';

import { getGithubSamplesGroups } from 'generator-jhipster/ci';
import { defaultHelpers as helpers, runResult } from 'generator-jhipster/testing';
import { createTestHelpers, typedResult } from 'generator-jhipster/testing';

import type Generator from './index.js';

const helpers = createTestHelpers<Generator>({
importMeta: import.meta,
});
const result = typedResult<Generator>();
const generator = basename(import.meta.dirname);

describe(`generator - ${generator}`, async () => {
const groups = await getGithubSamplesGroups(join(import.meta.dirname, '../generate-sample/templates/'));
for (const workflow of groups.map(sample => sample.split('.')[0])) {
describe(`with ${workflow}`, () => {
beforeAll(async () => {
await helpers.runJHipster(join(import.meta.dirname, 'index.mjs'), { prepareEnvironment: true }).withArguments(workflow);
await helpers.runDefault().withArguments(workflow);
});

it('should match matrix value', () => {
expect(runResult.generator.matrix).toMatchSnapshot();
expect(result.generator.matrix).toMatchSnapshot();
});
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { join } from 'node:path';

import { convertToGitHubMatrix, getGithubOutputFile, getGithubSamplesGroup, setGithubTaskOutput } from 'generator-jhipster/ci';
import {
type GitHubMatrixOutput,
convertToGitHubMatrix,
getGithubOutputFile,
getGithubSamplesGroup,
setGithubTaskOutput,
} from 'generator-jhipster/ci';
import BaseCoreGenerator from 'generator-jhipster/generators/base-core';

export default class extends BaseCoreGenerator {
/** @type {string} */
samplesFolder;
/** @type {string} */
samplesGroup;
/** @type {object} */
matrix;
samplesFolder?: string;
samplesGroup?: string;
matrix?: GitHubMatrixOutput;

get [BaseCoreGenerator.WRITING]() {
return this.asAnyTaskGroup({
Expand Down
2 changes: 0 additions & 2 deletions .blueprint/github-build-matrix/index.mjs

This file was deleted.

2 changes: 2 additions & 0 deletions .blueprint/github-build-matrix/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './generator.ts';
export { default as command } from './command.ts';
2 changes: 1 addition & 1 deletion .github/workflows/build-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
with:
generator-path: generator-jhipster-entity-audit
if: always()
- run: cli.cjs generate-sample --all
- run: cli.cts generate-sample --all
continue-on-error: true
- run: npm run backend:build-cache --workspaces
continue-on-error: true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- id: build
run: |
npm install
./cli/cli.cjs github-build-matrix
./cli/cli.cts github-build-matrix
samples:
name: ${{ matrix.job-name || matrix.sample }}
runs-on: ${{ matrix.os }}
Expand All @@ -56,7 +56,7 @@ jobs:
binary-dir: ${{ github.workspace }}/generator-jhipster-entity-audit/cli/
- run: npm install
working-directory: ${{ github.workspace }}/generator-jhipster-entity-audit
- run: cli.cjs generate-sample ${{ matrix.sample }} --skip-jhipster-dependencies --skip-install ${{ matrix.extra-args }}
- run: cli.cts generate-sample ${{ matrix.sample }} --skip-jhipster-dependencies --skip-install ${{ matrix.extra-args }}
- uses: jhipster/actions/compare-sample@v1
id: compare
if: >-
Expand Down
2 changes: 1 addition & 1 deletion .yo-rc.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
}
},
"githubWorkflows": true,
"javascriptBlueprint": true,
"javascriptBlueprint": false,
"jhipsterVersion": "9.1.0",
"js": true,
"localBlueprint": false,
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions cli/cli.cjs → cli/cli.cts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ const blueprint = packageFolderName.startsWith('jhipster-') ? `generator-${packa
console.log('');
},
lookups: [{ packagePaths: [packagePath] }],
...require('./cli-customizations.cjs'),
...require('./cli-customizations.cts'),
}).catch(done);

process.on('unhandledRejection', up => {
process.on('unhandledRejection', (up: any) => {
logger.error('Unhandled promise rejection at:');
logger.fatal(up);
});
Expand Down
23 changes: 21 additions & 2 deletions eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,37 @@ import { defineConfig } from 'eslint/config';
import prettier from 'eslint-plugin-prettier/recommended';
import jhipster from 'generator-jhipster/eslint';
import globals from 'globals';
import ts from 'typescript-eslint';
// jhipster-needle-eslint-add-import - JHipster will add additional import here

export default defineConfig(
export default defineConfig([
{
languageOptions: {
globals: {
...globals.node,
},
},
},
{
files: ['**/*.ts'],
...ts.configs.recommended[0],
...ts.configs.stylistic[0],
languageOptions: {
parser: ts.parser,
parserOptions: {
project: ['./tsconfig.json'],
},
},
rules: {
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/consistent-type-definitions': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-this-alias': 'off',
},
},
{ ignores: ['coverage/**'] },
jhipster.recommended,
// jhipster-needle-eslint-add-config - JHipster will add additional config here
prettier,
);
]);
5 changes: 0 additions & 5 deletions generators/angular-audit/command.js

This file was deleted.

5 changes: 5 additions & 0 deletions generators/angular-audit/command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { JHipsterCommandDefinition } from 'generator-jhipster';

export default {
configs: {},
} as const satisfies JHipsterCommandDefinition;
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { beforeAll, describe, expect, it } from 'vitest';

import { defaultHelpers as helpers, result } from 'generator-jhipster/testing';
import { createTestHelpers, typedResult } from 'generator-jhipster/testing';

const SUB_GENERATOR = 'angular-audit';
const SUB_GENERATOR_NAMESPACE = `jhipster-entity-audit:${SUB_GENERATOR}`;
import type Generator from './generator.js';

const helpers = createTestHelpers<Generator>({
importMeta: import.meta,
defaultGenerator: 'jhipster-entity-audit:angular-audit',
});
const result = typedResult<Generator>();

describe('SubGenerator angular-audit of entity-audit JHipster blueprint', () => {
describe('run', () => {
beforeAll(async function () {
await helpers
.run(SUB_GENERATOR_NAMESPACE)
.runDefault()
.withJHipsterConfig()
.withOptions({
ignoreNeedlesError: true,
Expand Down
2 changes: 0 additions & 2 deletions generators/angular-audit/index.js

This file was deleted.

2 changes: 2 additions & 0 deletions generators/angular-audit/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './generator.ts';
export { default as command } from './command.ts';
50 changes: 50 additions & 0 deletions generators/base-generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import type { JHipsterCommandDefinition } from 'generator-jhipster';
import BaseApplicationGenerator from 'generator-jhipster/generators/base-application';
import type { Source as LiquibaseSource } from 'generator-jhipster/generators/liquibase';
import type {
Application as SpringBootApplication,
Config as SpringBootConfig,
Entity as SpringBootEntity,
Options as SpringBootOptions,
Source as SpringBootSource,
} from 'generator-jhipster/generators/spring-boot';

type EntityAuditBlueprintConfig = {
auditFramework?: string;
auditPage?: boolean;
entityAuditEventChangelogDate?: string;
};

type EntityAuditEntity = SpringBootEntity & {
enableAudit: boolean;
entityAuditEventType?: string;
entityAuditEnumValue?: string;
requiresPersistableImplementation?: boolean;
};

export type EntityAuditApplication = SpringBootApplication<EntityAuditEntity> & {
entityAuditEventChangelogDate: string;
auditedEntities: string[];
};

type EntityAuditSource = SpringBootSource &
LiquibaseSource & {
addEntityToAuditedEntityEnum: (param: {
entityAuditEnumValue?: string;
entityAbsoluteClass: string;
entityAuditEventType?: string;
}) => void;
};

export class EntityAuditApplicationGenerator extends BaseApplicationGenerator<
EntityAuditEntity,
EntityAuditApplication,
SpringBootConfig,
SpringBootOptions,
EntityAuditSource
> {
initialRun?: boolean;
declare blueprintConfig: EntityAuditBlueprintConfig;
}

export const asCommand = <const Def extends JHipsterCommandDefinition<EntityAuditApplicationGenerator>>(command: Def): Def => command;
10 changes: 6 additions & 4 deletions generators/client/command.js → generators/client/command.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { asCommand } from 'generator-jhipster';
import type { JHipsterCommandDefinition } from 'generator-jhipster';

export default asCommand({
import type Generator from './generator.js';

export default {
configs: {
auditPage: {
description: 'Generate client page',
Expand All @@ -12,9 +14,9 @@ export default asCommand({
message: 'Do you want to add an audit log page for entities?',
},
configure: gen => {
gen.blueprintConfig.auditPage = (gen.blueprintConfig.auditFramework ?? 'no') !== 'no';
gen.blueprintConfig!.auditPage = (gen.blueprintConfig!.auditFramework ?? 'no') !== 'no';
},
scope: 'blueprint',
},
},
});
} as const satisfies JHipsterCommandDefinition<Generator>;
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { beforeAll, describe, expect, it } from 'vitest';

import { defaultHelpers as helpers, result } from 'generator-jhipster/testing';
import { createTestHelpers, typedResult } from 'generator-jhipster/testing';

const SUB_GENERATOR = 'client';
const BLUEPRINT_NAMESPACE = `jhipster:${SUB_GENERATOR}`;
import type Generator from './generator.js';

const helpers = createTestHelpers<Generator>({
importMeta: import.meta,
defaultGenerator: 'jhipster:client',
});
const result = typedResult<Generator>();

describe('SubGenerator client of entity-audit JHipster blueprint', () => {
describe('run', () => {
beforeAll(async function () {
await helpers
.run(BLUEPRINT_NAMESPACE)
.runDefault()
.withJHipsterConfig()
.withOptions({
ignoreNeedlesError: true,
Expand Down
Loading
Loading