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

generate-blueprint: adjusts #27406

Merged
merged 7 commits into from
Sep 24, 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
6 changes: 6 additions & 0 deletions generators/app/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ exports[`generator - app with default config should match snapshot 1`] = `
"cacheProviderRedis": false,
"camelizedBaseName": "jhipster",
"capitalizedBaseName": "Jhipster",
"cjsExtension": ".cjs",
"clientDistDir": "target/classes/static/",
"clientFramework": "angular",
"clientFrameworkAngular": true,
Expand Down Expand Up @@ -609,6 +610,7 @@ exports[`generator - app with default config should match snapshot 1`] = `
"messageBrokerPulsar": false,
"microfrontend": false,
"microfrontends": undefined,
"mjsExtension": ".mjs",
"monorepository": undefined,
"nativeLanguage": "en",
"nativeLanguageDefinition": {
Expand Down Expand Up @@ -889,6 +891,7 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"cacheProviderRedis": false,
"camelizedBaseName": "jhipster",
"capitalizedBaseName": "Jhipster",
"cjsExtension": ".cjs",
"clientDistDir": "target/classes/static/",
"clientFramework": "angular",
"clientFrameworkAngular": true,
Expand Down Expand Up @@ -1242,6 +1245,7 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"messageBrokerPulsar": false,
"microfrontend": undefined,
"microfrontends": undefined,
"mjsExtension": ".mjs",
"monorepository": undefined,
"nativeLanguage": "en",
"nativeLanguageDefinition": {
Expand Down Expand Up @@ -1521,6 +1525,7 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"cacheProviderRedis": false,
"camelizedBaseName": "jhipster",
"capitalizedBaseName": "Jhipster",
"cjsExtension": ".cjs",
"clientDistDir": "target/classes/static/",
"clientFramework": "no",
"clientFrameworkAngular": false,
Expand Down Expand Up @@ -1879,6 +1884,7 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"messageBrokerPulsar": false,
"microfrontend": false,
"microfrontends": undefined,
"mjsExtension": ".mjs",
"monorepository": undefined,
"nativeLanguage": "en",
"nativeLanguageDefinition": {
Expand Down
13 changes: 5 additions & 8 deletions generators/generate-blueprint/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ export const files = asWriteFilesSection<any>({
'.github/workflows/generator.yml',
'.prettierignore.jhi.blueprint',
{ sourceFile: 'eslint.config.js.jhi.blueprint', destinationFile: ctx => `${ctx.eslintConfigFile}.jhi.blueprint` },
{
sourceFile: 'README.md',
override: data => !data.ignoreExistingGenerators,
},
'README.md',
'tsconfig.json',
'vitest.config.ts',
'.blueprint/cli/commands.mjs',
Expand Down Expand Up @@ -68,21 +65,21 @@ export const generatorFiles = asWriteFilesSection<any>({
path: 'generators/generator',
to: ctx => `${ctx.application.blueprintsPath}${ctx.generator}`,
templates: [
{ sourceFile: 'index.mjs', destinationFile: ctx => (ctx.js ? 'index.js' : 'index.mjs') },
{ sourceFile: 'index.mjs', destinationFile: ctx => `index.${ctx.blueprintMjsExtension}` },
{
sourceFile: 'command.mjs',
destinationFile: ctx => (ctx.js ? 'command.js' : 'command.mjs'),
destinationFile: ctx => `command.${ctx.blueprintMjsExtension}`,
override: data => !data.ignoreExistingGenerators,
},
{
sourceFile: 'generator.mjs.jhi',
destinationFile: ctx => (ctx.js ? 'generator.js.jhi' : 'generator.mjs.jhi'),
destinationFile: ctx => `generator.${ctx.blueprintMjsExtension}.jhi`,
override: data => !data.ignoreExistingGenerators,
},
{
condition: data => !data.generator.startsWith('entity') && !data.application[LOCAL_BLUEPRINT_OPTION],
sourceFile: 'generator.spec.mjs',
destinationFile: data => (data.js ? 'generator.spec.js' : 'generator.spec.mjs'),
destinationFile: data => `generator.spec.${data.blueprintMjsExtension}`,
override: data => !data.ignoreExistingGenerators,
},
],
Expand Down
33 changes: 26 additions & 7 deletions generators/generate-blueprint/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,10 @@ export default class extends BaseGenerator {
preparePath() {
this.application.blueprintsPath = this.application[LOCAL_BLUEPRINT_OPTION] ? '.blueprint/' : 'generators/';
},
prepare() {
prepare({ application }) {
const { cli, cliName, baseName } = this.application;
this.application.githubRepository = this.jhipsterConfig.githubRepository ?? `jhipster/generator-jhipster-${baseName}`;
application.blueprintMjsExtension = this.application.js ? 'js' : 'mjs';
if (cli) {
this.application.cliName = cliName ?? `jhipster-${baseName}`;
}
Expand All @@ -212,7 +213,7 @@ export default class extends BaseGenerator {
async cleanup({ control }) {
await control.cleanupFiles({
'8.5.1': ['.eslintrc.json'],
'8.7.2': ['vitest.test-setup.ts'],
'8.7.2': ['.eslintignore', 'vitest.test-setup.ts'],
});
},
async writing({ application }) {
Expand All @@ -229,7 +230,7 @@ export default class extends BaseGenerator {
});
this.jhipsterConfig.sampleWritten = true;
},
async writingGenerators() {
async writingGenerators({ application }) {
if (!this.application[GENERATORS]) return;
const { skipWorkflows, ignoreExistingGenerators } = this;
for (const generator of Object.keys(this.application[GENERATORS])) {
Expand All @@ -243,9 +244,9 @@ export default class extends BaseGenerator {
const customGenerator = !Object.values(GENERATOR_LIST).includes(generator);
const jhipsterGenerator = customGenerator || subGeneratorConfig.sbs ? 'base-application' : generator;
const subTemplateData = {
...application,
skipWorkflows,
ignoreExistingGenerators,
js: this.application.js,
application: this.application,
...defaultSubGeneratorConfig(),
...subGeneratorConfig,
Expand All @@ -272,12 +273,30 @@ export default class extends BaseGenerator {

get postWriting() {
return this.asPostWritingTaskGroup({
upgrade() {
upgrade({ application }) {
if (!this.application[GENERATORS]) return;
if (!this.isJhipsterVersionLessThan('8.7.2')) return;
for (const generator of Object.keys(this.application[GENERATORS])) {
const extension = this.application.js ? 'js' : 'mjs';
const generatorSpec = `${this.application.blueprintsPath}${generator}/generator.spec.${extension}`;
const commandFile = `${this.application.blueprintsPath}${generator}/command.${application.blueprintMjsExtension}`;
this.editFile(commandFile, content =>
content
.replace(
`/**
* @type {import('generator-jhipster').JHipsterCommandDefinition}
*/`,
`import { asCommand } from 'generator-jhipster';
`,
)
.replace('const command = ', 'export default asCommand(')
.replace(
`
};`,
'});',
)
.replace('export default command;', ''),
);

const generatorSpec = `${this.application.blueprintsPath}${generator}/generator.spec.${application.blueprintMjsExtension}`;
this.editFile(generatorSpec, content => content.replaceAll(/blueprint: '([\w-]*)'/g, "blueprint: ['$1']"));
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
npm install
./cli/cli.cjs github-build-matrix
samples:
name: ${{ matrix.sample-name }}
name: ${{ matrix.job-name || matrix.sample-name }}
runs-on: ubuntu-latest
needs: build-matrix
defaults:
Expand All @@ -48,19 +48,17 @@ jobs:
maven-cache: true
gradle-cache: true
binary-dir: ${{ github.workspace }}/generator-jhipster-<%= baseName %>/cli/
- name: 'Install blueprint'
run: npm install
- run: npm install
working-directory: ${{ github.workspace }}/generator-jhipster-<%= baseName %>
- name: 'Generate Project'
run: cli.cjs generate-sample ${{ matrix.sample-name }} --skip-jhipster-dependencies --force
- run: cli.cjs generate-sample ${{ matrix.sample-name }} --skip-jhipster-dependencies ${{ matrix.extra-args }}
- uses: jhipster/actions/compare-sample@v0
id: compare
if: >-
github.event.pull_request &&
!contains(github.event.pull_request.labels.*.name, 'pr: disable-compare')
with:
generator-path: generator-jhipster-<%= baseName %>
cmd: cli.cjs generate-sample ${{ matrix.sample-name }} --skip-jhipster-dependencies --force --skip-install
cmd: cli.cjs generate-sample ${{ matrix.sample-name }} --skip-jhipster-dependencies --skip-install ${{ matrix.extra-args }}
- run: npm run ci:backend:test
if: steps.compare.outputs.equals != 'true'
id: backend
Expand All @@ -73,15 +71,15 @@ jobs:
- run: npm run ci:e2e:run --if-present
if: steps.compare.outputs.equals != 'true'
id: e2e
- name: 'BACKEND: Store failure logs'
- name: Store backend test failure logs
uses: actions/upload-artifact@v4
if: always() && steps.backend.outcome == 'failure'
with:
name: log-${{ matrix.sample-name }}
path: |
${{ github.workspace }}/app/build/test-results/**/*.xml
${{ github.workspace }}/app/target/surefire-reports
- name: 'E2E: Store failure screenshots'
- name: Store cypress screenshots
uses: actions/upload-artifact@v4
if: always() && steps.e2e.outcome == 'failure'
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import <%= generatorClass %>Generator from 'generator-jhipster/generators/<%= jhipsterGenerator %>';
<%_ } _%>
<%_ if (priorities.find(priority => priority.name === 'initializing')) { _%>
import command from './command.<%- js ? '' : 'm' %>js';
import command from './command.<%- blueprintMjsExtension %>';
<%_ } _%>

<%_ if (application.dynamic) { _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
export { <%- application.dynamic ? 'createGenerator' : 'default' %> } from './generator.<%- js ? '' : 'm' %>js';
export { default as command } from './command.<%- js ? '' : 'm' %>js';
export { <%- application.dynamic ? 'createGenerator' : 'default' %> } from './generator.<%- blueprintMjsExtension %>';
export { default as command } from './command.<%- blueprintMjsExtension %>';
10 changes: 6 additions & 4 deletions generators/javascript/generators/bootstrap/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ import BaseApplicationGenerator from '../../../base-application/index.js';
import { GENERATOR_PROJECT_NAME } from '../../../generator-list.js';

export default class BootstrapGenerator extends BaseApplicationGenerator {
constructor(args, options, features) {
super(args, options, { queueCommandTasks: true, ...features });
}

async beforeQueue() {
if (!this.fromBlueprint) {
await this.composeWithBlueprints();
Expand All @@ -43,6 +39,12 @@ export default class BootstrapGenerator extends BaseApplicationGenerator {
this.fetchFromInstalledJHipster('javascript', 'resources', 'package.json'),
);
},
jsExtensions({ applicationDefaults, application }) {
applicationDefaults({
cjsExtension: application.packageJsonTypeCommonjs ? '.js' : '.cjs',
mjsExtension: application.packageJsonTypeCommonjs ? '.js' : '.mjs',
});
},
});
}

Expand Down
2 changes: 2 additions & 0 deletions generators/javascript/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export type JavaScriptSourceType = {
export type JavaScriptApplication = JavascriptBootstrapProperties & {
packageJsonNodeEngine?: boolean | string;
eslintConfigFile?: string;
cjsExtension?: string;
mjsExtension?: string;

addPrettierExtensions?: (extensions: string[]) => void;
};
1 change: 1 addition & 0 deletions lib/command/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { CommandConfigScope, JHipsterConfigs, JHispterChoices } from './typ
const prepareChoices = (key: string, choices: JHispterChoices) =>
choices
.map(choice => (typeof choice === 'string' ? { value: choice } : choice))
.filter(choice => choice.value != null)
.map(choice => ({ ...choice, choiceKey: `${key}${upperFirst(choice.value)}` }));

const filteredScopeEntries = (commandsConfigs: JHipsterConfigs, scopes: CommandConfigScope[]) =>
Expand Down
Loading