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
3 changes: 3 additions & 0 deletions .github/workflows/generator-generate-blueprint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ jobs:
env:
# generate-sample uses JHI_FOLDER_APP to generate the application.
JHI_FOLDER_APP: ${{ github.workspace }}/base/generator-jhipster-foo
- name: 'Test Blueprint'
run: npm test
working-directory: ${{ github.workspace }}/generator-jhipster-foo
- name: 'GENERATION: project'
run: jhipster-foo --defaults --client-test-frameworks cypress --skip-jhipster-dependencies
env:
Expand Down
20 changes: 14 additions & 6 deletions generators/generate-blueprint/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import { camelCase, snakeCase, upperFirst } from 'lodash-es';

import { mutateData } from '../../lib/utils/object.ts';
import { PRIORITY_NAMES_LIST as BASE_PRIORITY_NAMES_LIST } from '../base-core/priorities.ts';
import BaseSimpleApplicationGenerator from '../base-simple-application/index.ts';

Expand All @@ -38,6 +39,7 @@ import type {
Config as GenerateBlueprintConfig,
Features as GenerateBlueprintFeatures,
Options as GenerateBlueprintOptions,
TemplateData,
} from './types.ts';

export class GenerateBlueprintBaseGenerator extends BaseSimpleApplicationGenerator<
Expand Down Expand Up @@ -175,9 +177,11 @@ export default class extends GenerateBlueprintBaseGenerator {
},
async writingGenerators({ application }) {
if (!application.generators) return;
const { javascriptBlueprint, upperFirstCamelCaseBaseName } = application;
const templateExtension = application.javascriptBlueprint ? 'mjs' : 'ts';
const outputExtension = application.javascriptBlueprint ? application.blueprintMjsExtension : 'ts';
for (const generator of Object.keys(application.generators)) {
const generatorContext: TemplateData = { ...application } as TemplateData;
const subGeneratorStorage = this.getSubGeneratorStorage(generator);
const subGeneratorConfig = subGeneratorStorage.getAll();
const priorities: { name: string; asTaskGroup: string; constant: string }[] = (subGeneratorConfig[PRIORITIES] || []).map(
Expand All @@ -188,19 +192,23 @@ export default class extends GenerateBlueprintBaseGenerator {
}),
);
const customGenerator = !lookupGeneratorsNamespaces().includes(generator);
const jhipsterGenerator = customGenerator || subGeneratorConfig.sbs ? 'base-application' : generator;
const generatorClass = upperFirst(camelCase(jhipsterGenerator));
const hasCustomBaseGenerator = customGenerator && !javascriptBlueprint;
mutateData(generatorContext, {
jhipsterGenerator: customGenerator ? 'base-application' : generator,
parentGenerator: ctx =>
hasCustomBaseGenerator ? `${upperFirstCamelCaseBaseName}Application` : upperFirst(camelCase(ctx.jhipsterGenerator)),
parentGeneratorImport: ctx =>
hasCustomBaseGenerator ? '../base-generator.ts' : `generator-jhipster/generators/${ctx.jhipsterGenerator}`,
});

const subTemplateData = {
...application,
...generatorContext,
application,
...defaultSubGeneratorConfig(),
...subGeneratorConfig,
generator,
parentGenerator: customGenerator ? generatorClass : generatorClass,
customGenerator,
jhipsterGenerator,
subGenerator: generator,
generatorClass,
priorities,
};
await this.writeFiles<typeof subTemplateData>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
"strict": true,
<%_ } _%>
"skipLibCheck": true /* Skip type checking all .d.ts files. */
"skipLibCheck": false /* Skip type checking all .d.ts files. */
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
});
-&>
<%_ if (!application.dynamic) { _%>
import <%- generatorClass %>Generator from 'generator-jhipster/generators/<%- jhipsterGenerator %>';
import <%- parentGenerator %>Generator from 'generator-jhipster/generators/<%- jhipsterGenerator %>';
<%_ } _%>
<%_ if (priorities.find(priority => priority.name === 'initializing')) { _%>
import command from './command.<%- blueprintMjsExtension %>';
Expand All @@ -35,19 +35,19 @@ import command from './command.<%- blueprintMjsExtension %>';
// eslint-disable-next-line import/prefer-default-export
export async function createGenerator(env) {
/** @type {typeof import('generator-jhipster/generators/<%- jhipsterGenerator %>').default} */
let <%- generatorClass %>Generator;
let <%- parentGenerator %>Generator;
try {
// Try to use locally installed generator-jhipster
<%- generatorClass %>Generator = (await import('generator-jhipster/generators/<%- jhipsterGenerator %>')).default;
<%- parentGenerator %>Generator = (await import('generator-jhipster/generators/<%- jhipsterGenerator %>')).default;
} catch {
// Fallback to the currently running jhipster.
const jhipsterGenerator = 'jhipster:<%- generator %>';
<%- generatorClass %>Generator = await env.requireGenerator(jhipsterGenerator);
<%- parentGenerator %>Generator = await env.requireGenerator(jhipsterGenerator);
}

return class extends <%- generatorClass %>Generator {
return class extends <%- parentGenerator %>Generator {
<%_ } else { _%>
export default class extends <%- generatorClass %>Generator {
export default class extends <%- parentGenerator %>Generator {
<%_ } _%>
constructor(args, opts, features) {
super(args, opts, {
Expand All @@ -73,7 +73,7 @@ export default class extends <%- generatorClass %>Generator {
<&- fragments.<%- priority.name %>Section() -&>
<& if (!fragments.<%- priority.name %>Section()) { -&>

get [<%- generatorClass %>Generator.<%- priority.constant %>]() {
get [<%- parentGenerator %>Generator.<%- priority.constant %>]() {
return this.<%- priority.asTaskGroup %>({
<%_ if (!sbs && !customGenerator) { _%>
...super.<%- priority.name %>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@
});
-&>
<%_ if (!application.dynamic) { _%>
<%_ if (customGenerator) { _%>
import <%- parentGenerator %>Generator, { type Features, type Options } from '../base-generator.ts';
<%_ } else { _%>
import <%- parentGenerator %>Generator, { type Features, type Options } from 'generator-jhipster/generators/<%- jhipsterGenerator %>';
<%_ } _%>
import <%- parentGenerator %>Generator, { type Features, type Options } from '<%- parentGeneratorImport %>';
<%_ } _%>
<%_ if (priorities.find(priority => priority.name === 'initializing')) { _%>
import command from './command.<%- blueprintMjsExtension %>';
Expand Down
3 changes: 2 additions & 1 deletion generators/generate-blueprint/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export type TemplateData = Application & {
generator: string;
customGenerator: boolean;
jhipsterGenerator: string;
generatorClass: string;
parentGenerator: string;
parentGeneratorImport: string;
priorities: {
name: string;
asTaskGroup: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { defineConfig } from 'eslint/config';
import prettier from 'eslint-plugin-prettier/recommended';
import globals from 'globals';
<%_ if (typescriptEslint) { _%>
import tseslint from 'typescript-eslint';
import ts from 'typescript-eslint';
<%_ } _%>
<&- fragments.importsSection() -&>
// jhipster-needle-eslint-add-import - JHipster will add additional import here
Expand All @@ -41,6 +41,23 @@ export default defineConfig(
},
},
},
<%_ if (typescriptEslint) { _%>
{
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',
},
},
<%_ } _%>
<&- fragments.configSection() -&>
// jhipster-needle-eslint-add-config - JHipster will add additional config here
<%_ if (locals.clientFrameworkAngular) { _%>
Expand Down
Loading