Skip to content

Commit

Permalink
Merge branch 'main' into react-logout
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima authored Dec 10, 2024
2 parents aa962d4 + cbbf5bd commit 2beb670
Show file tree
Hide file tree
Showing 503 changed files with 7,320 additions and 5,428 deletions.
12 changes: 7 additions & 5 deletions .blueprint/from-issue/command.mts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ const command: JHipsterCommandDefinition = {
},
configure(gen: any) {
// Gets the owner, repo and issue_number from a string such as, "jhipster/generator-jhipster#12345"
const parsedIssue = parseIssue(gen.issue);
if (parsedIssue) {
gen.owner = parsedIssue.owner;
gen.repository = parsedIssue.repository;
gen.issue = parsedIssue.issue;
const { owner, repository, issue } = parseIssue(gen.issue);
if (owner) {
gen.owner = owner;
}
if (repository) {
gen.repository = repository;
}
gen.issueNumber = issue;
},
scope: 'generator',
},
Expand Down
131 changes: 97 additions & 34 deletions .blueprint/from-issue/generator.mts
Original file line number Diff line number Diff line change
@@ -1,30 +1,59 @@
import { join } from 'node:path';

import BaseGenerator from '../../generators/base/index.js';
import { getGithubIssue, setGithubTaskOutput, prepareSample } from '../../lib/testing/index.js';
import { getGithubIssue, setGithubTaskOutput, prepareSample, appendToSummary } from '../../lib/testing/index.js';
import { promptSamplesFolder } from '../support.mjs';
import { GENERATOR_APP, GENERATOR_JDL, GENERATOR_WORKSPACES } from '../../generators/generator-list.js';
import { extractDataFromInfo, type InfoData } from '../../generators/info/support/index.js';
import { extractDataFromInfo, markdownDetails, type InfoData } from '../../generators/info/support/index.js';
import EnvironmentBuilder from '../../cli/environment-builder.mjs';

const YO_RC_OUTPUT = 'yo-rc';
const ENTITIES_JDL_OUTPUT = 'entities-jdl';
const RESULT_OUTPUT = 'result';
const VALID_OUTPUT = 'valid';
const SUMMARY_OUTPUT = 'summary';
const FOOTER_OUTPUT = 'footer';
const DIFFS_OUTPUT = 'diffs';

const CONTAINS_SAMPLE = 'contains-sample';

const BLANK = 'blank';
const VALID = 'valid';
const VALID_EMOJI = ':heavy_check_mark:';
const ERROR = 'error';
const ERROR_EMOJI = ':x:';
const SUCCESS = 'successfully generated';

const generateSummary = (data: InfoData, { applicationGenerated, issue }: { applicationGenerated: boolean; issue: string }) => `
| ${issue} | Value |
| --- | --- |${data.yoRcBlank ? `` : `\n| **.yo-rc.json** | ${data.yoRcValid ? VALID_EMOJI : ERROR_EMOJI} |`}${
(data.jdlApplications ?? 0) > 0 ? `\n| **JDL** | ${VALID_EMOJI} |` : ``
}
| **Entities JDL** | ${data.jdlEntitiesDefinitions ? VALID_EMOJI : '-'} |
| --- | --- |
| **Application Generation** | ${applicationGenerated ? VALID_EMOJI : ERROR_EMOJI} |
`;

const generateFooter = (data: InfoData) =>
data.files.map(info => markdownDetails({ title: info.filename, codeType: 'jdl', content: info.content })).join('\n\n');

const generateDiffOutput = (title: string, content: string) => markdownDetails({ title, codeType: 'diff', content });

export default class extends BaseGenerator {
issue!: string;
projectFolder!: string;
owner!: string;
issue!: string;
codeWorkspace!: boolean;

issueNumber!: string;
owner!: string;
repository!: string;

data!: InfoData;
logCwd = this.destinationPath();

summaryData = '';
summaryFooter = '';
summaryDiffs = '';

constructor(args, options, features) {
super(args, options, { queueCommandTasks: true, ...features });
Expand All @@ -43,10 +72,10 @@ export default class extends BaseGenerator {
get [BaseGenerator.DEFAULT]() {
return this.asDefaultTaskGroup({
async generateSample() {
const issue = await getGithubIssue({ owner: this.owner, repository: this.repository, issue: this.issue });
const issue = await getGithubIssue({ owner: this.owner, repository: this.repository, issue: this.issueNumber });

this.projectFolder = this.destinationPath(
this.projectFolder ?? join(this._globalConfig.get('samplesFolder'), `issues/${this.issue}`),
this.destinationRoot(
this.destinationPath(this.projectFolder ?? join(this._globalConfig.get('samplesFolder'), `issues/${this.issueNumber}`)),
);

this.data = extractDataFromInfo(issue.body ?? '');
Expand All @@ -59,8 +88,13 @@ export default class extends BaseGenerator {
setGithubTaskOutput(ENTITIES_JDL_OUTPUT, this.data.jdlEntitiesDefinitions ? VALID : BLANK);
setGithubTaskOutput(CONTAINS_SAMPLE, Boolean(this.data.jdlDefinitions || this.data.yoRcContent));
setGithubTaskOutput(VALID_OUTPUT, this.data.yoRcValid);
this.summaryFooter = generateFooter(this.data);
setGithubTaskOutput(FOOTER_OUTPUT, this.summaryFooter);

for (const file of await prepareSample(this.projectFolder, this.data.files)) {
for (const file of await prepareSample(
this.destinationPath(),
this.data.files.filter(file => file.type === 'yo-rc'),
)) {
this.writeDestination(file.filename, file.content);
}
},
Expand All @@ -70,48 +104,77 @@ export default class extends BaseGenerator {
get [BaseGenerator.END]() {
return this.asEndTaskGroup({
async generateSample() {
const envOptions = { cwd: this.projectFolder, logCwd: this.destinationPath() };
const generatorOptions = { ...this.options, skipPriorities: ['prompting'], skipInstall: true, experimental: true };
const envOptions = { cwd: this.destinationPath(), logCwd: this.logCwd };
const generatorOptions = { ...this.options, skipPriorities: ['prompting'], skipInstall: true, experimental: true, force: true };
delete generatorOptions.sharedData;

const { workspacesFolders, jdlEntitiesDefinitions, yoRcContent, jdlDefinitions } = this.data;
if (jdlEntitiesDefinitions) {
try {
const { workspacesFolders, jdlEntitiesDefinitions, yoRcContent, jdlApplications = 0, files } = this.data;
try {
if (jdlEntitiesDefinitions) {
try {
await EnvironmentBuilder.run(
[`jhipster:${GENERATOR_JDL}`],
{ ...generatorOptions, inline: jdlEntitiesDefinitions, jsonOnly: true },
envOptions,
);
} catch (error) {
setGithubTaskOutput(ENTITIES_JDL_OUTPUT, ERROR);
throw error;
}
}
if (yoRcContent) {
await EnvironmentBuilder.run(
[`jhipster:${GENERATOR_JDL}`],
{ ...generatorOptions, inline: jdlEntitiesDefinitions, jsonOnly: true },
[`jhipster:${workspacesFolders ? GENERATOR_WORKSPACES : GENERATOR_APP}`],
{ ...generatorOptions, ...(workspacesFolders ? { workspacesFolders, generateApplications: true } : {}) },
envOptions,
);
} catch (error) {
setGithubTaskOutput(ENTITIES_JDL_OUTPUT, ERROR);
throw error;
} else if (jdlApplications > 0) {
const workspaceOpts = jdlApplications > 1 ? { workspaces: true, monorepository: true } : {};
const diffs: string[] = [];
for (const file of files.filter(file => file.type === 'jdl')) {
await EnvironmentBuilder.run(
[`jhipster:${GENERATOR_JDL}`],
{ ...generatorOptions, ...workspaceOpts, inline: file.content },
envOptions,
);
const git = this.createGit();
const status = await git.status();
if (!status.isClean()) {
await git.add('.').commit(`chore: generate application from ${file.filename}`);
const { all } = await this.spawn('git', ['diff', '--no-color', '@~1'], { stdio: 'pipe', all: true });
if (all) {
this.log(all);
diffs.push(generateDiffOutput(`diff ${file.filename}`, all));
}
}
}
this.summaryDiffs = diffs.join('\n\n');
setGithubTaskOutput(DIFFS_OUTPUT, this.summaryDiffs);
}
} catch (error) {
this.summaryData = generateSummary(this.data, { applicationGenerated: false, issue: this.issue });
setGithubTaskOutput(SUMMARY_OUTPUT, this.summaryData);
this.appendSummary();
throw error;
}
if (yoRcContent) {
await EnvironmentBuilder.run(
[`jhipster:${workspacesFolders ? GENERATOR_WORKSPACES : GENERATOR_APP}`],
{ ...generatorOptions, ...(workspacesFolders ? { workspacesFolders, generateApplications: true } : {}) },
envOptions,
);
} else if (jdlDefinitions) {
const applications = (jdlDefinitions.match(/application\s*\{/g) || []).length;
const workspaceOpts = applications > 1 ? { workspaces: true, monorepository: true } : {};
await EnvironmentBuilder.run(
[`jhipster:${GENERATOR_JDL}`],
{ ...generatorOptions, ...workspaceOpts, inline: jdlDefinitions },
envOptions,
);
}

setGithubTaskOutput(RESULT_OUTPUT, SUCCESS);
this.summaryData = generateSummary(this.data, { applicationGenerated: true, issue: this.issue });
setGithubTaskOutput(SUMMARY_OUTPUT, this.summaryData);
this.appendSummary();

if (this.codeWorkspace) {
await this.composeWithJHipster('@jhipster/jhipster-dev:code-workspace', {
generatorOptions: {
samplePath: this.projectFolder,
samplePath: this.destinationPath(),
} as any,
});
}
},
});
}

appendSummary() {
appendToSummary(this.summaryData + this.summaryDiffs + this.summaryFooter);
}
}
Loading

0 comments on commit 2beb670

Please sign in to comment.