Skip to content

Commit

Permalink
adjusts to generate-sample
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Jul 22, 2024
1 parent 062658a commit f815bf9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
24 changes: 19 additions & 5 deletions .blueprint/generate-sample/command.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
*/
import { existsSync, readdirSync } from 'node:fs';
import { getSamples } from './get-samples.mjs';
import { entitiesByType } from './support/index.mjs';
import { entitiesByType, workflowSamples } from './support/index.mjs';

const updateSampleName = sample =>
sample.replace('ngx', 'ng').replace('ms-ng-eureka-oauth2-mongodb-caffeine', 'ms-ng-oauth2-mongodb-caffeine');

const revertSampleName = sample =>
sample.replace('ng-', 'ngx-').replace('ms-ng-oauth2-mongodb-caffeine', 'ms-ng-eureka-oauth2-mongodb-caffeine');

/**
* @type {import('generator-jhipster').JHipsterCommandDefinition}
*/
Expand Down Expand Up @@ -78,7 +81,11 @@ const command = {
},
configure: gen => {
if (gen.appSample && gen.appSample !== 'jdl') {
gen.samplesFolder = `json-samples/${updateSampleName(gen.appSample)}`;
gen.appSample = revertSampleName(gen.appSample);

let { appSample } = gen;
appSample = workflowSamples[appSample]?.['app-sample'] ?? appSample;
gen.samplesFolder = `json-samples/${updateSampleName(appSample)}`;
gen.entrypointGenerator = 'app';
}
},
Expand Down Expand Up @@ -109,7 +116,10 @@ const command = {
type: String,
},
configure: gen => {
const { entityType } = gen;
let { entityType } = gen;
if (!entityType && gen.appSample) {
entityType = workflowSamples[gen.appSample]?.entity;
}
if (entityType && entityType !== 'none') {
gen.supportingSamples.push(...entitiesByType[entityType].map(entity => `.jhipster/${entity}.json`));
}
Expand All @@ -124,8 +134,12 @@ const command = {
env: 'JHI_JDL_ENTITY',
},
configure: gen => {
if (gen.jdlEntities) {
const entities = gen.jdlEntities.split(',');
let { jdlEntities } = gen;
if (!jdlEntities && gen.appSample) {
jdlEntities = workflowSamples[gen.appSample]?.['jdl-entity'];
}
if (jdlEntities) {
const entities = jdlEntities.split(',');
gen.generatorArgs = '*.jdl';
gen.entrypointGenerator = 'jdl';
if (entities && entities.length > 0) {
Expand Down
1 change: 1 addition & 0 deletions .blueprint/generate-sample/support/index.mjs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './entities-by-type.mjs';
export * from './workflow-samples.mjs';
7 changes: 7 additions & 0 deletions .blueprint/generate-sample/support/workflow-samples.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { readFileSync } from 'fs';

const angularSamples = readFileSync(new URL('../../../test-integration/workflow-samples/angular.json', import.meta.url), 'utf8');
const reactSamples = readFileSync(new URL('../../../test-integration/workflow-samples/react.json', import.meta.url), 'utf8');

const samples = [...JSON.parse(angularSamples).include, ...JSON.parse(reactSamples).include];
export const workflowSamples = Object.fromEntries(samples.map(({ name, ...sample }) => [name, sample]));

0 comments on commit f815bf9

Please sign in to comment.