Skip to content

Commit

Permalink
Merge branch 'jhipster:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
yhao3 authored Jun 8, 2024
2 parents ec4317d + 749e9fb commit 7c5d7dd
Show file tree
Hide file tree
Showing 265 changed files with 5,520 additions and 3,819 deletions.
18 changes: 16 additions & 2 deletions .blueprint/from-issue/command.mts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,25 @@
*/
import { JHipsterCommandDefinition } from '../../generators/base/api.js';
import { GENERATOR_APP, GENERATOR_WORKSPACES } from '../../generators/generator-list.js';
import { parseIssue } from '../../testing/github.js';

const command: JHipsterCommandDefinition = {
arguments: {
configs: {
issue: {
type: String,
argument: {
type: String,
description: 'GitHub issue to generate',
},
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;
}
},
scope: 'generator',
},
},
options: {
Expand Down
156 changes: 0 additions & 156 deletions .blueprint/from-issue/generator.mjs

This file was deleted.

123 changes: 123 additions & 0 deletions .blueprint/from-issue/generator.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import { join } from 'node:path';

import BaseGenerator from '../../generators/base/index.js';
import { getGithubIssue, setGithubTaskOutput, prepareSample } from '../../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 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 CONTAINS_SAMPLE = 'contains-sample';

const BLANK = 'blank';
const VALID = 'valid';
const ERROR = 'error';
const SUCCESS = 'successfully generated';

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

get [BaseGenerator.INITIALIZING]() {
return this.asInitializingTaskGroup({
async parseCommand() {
await this.parseCurrentJHipsterCommand();
},
});
}

get [BaseGenerator.PROMPTING]() {
return this.asPromptingTaskGroup({
async promptOptions() {
if (this.codeWorkspace) {
await promptSamplesFolder.call(this);
}
},
});
}

get [BaseGenerator.CONFIGURING]() {
return this.asConfiguringTaskGroup({
async configure() {
await this.configureCurrentJHipsterCommandConfig();
},
});
}

get [BaseGenerator.DEFAULT]() {
return this.asDefaultTaskGroup({
async generateSample() {
const issue = await getGithubIssue({ owner: this.owner, repository: this.repository, issue: this.issue });

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

this.data = extractDataFromInfo(issue.body ?? '');
if (this.data.yoRcBlank) {
setGithubTaskOutput(YO_RC_OUTPUT, BLANK);
} else {
setGithubTaskOutput(YO_RC_OUTPUT, this.data.yoRcValid ? VALID : ERROR);
}

setGithubTaskOutput(ENTITIES_JDL_OUTPUT, this.data.jdlEntitiesDefinitions ? VALID : BLANK);
setGithubTaskOutput(CONTAINS_SAMPLE, Boolean(this.data.yoRcContent && this.data.jdlEntitiesDefinitions));
setGithubTaskOutput(VALID_OUTPUT, this.data.yoRcValid);

for (const file of await prepareSample(this.projectFolder, this.data.files)) {
this.writeDestination(file.filename, file.content);
}
},
});
}

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 };
delete generatorOptions.sharedData;

const { workspacesFolders, jdlEntitiesDefinitions, yoRcContent, jdlDefinitions } = this.data;
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:${workspacesFolders ? GENERATOR_WORKSPACES : GENERATOR_APP}`],
{ ...generatorOptions, ...(workspacesFolders ? { workspacesFolders, generateApplications: true } : {}) },
envOptions,
);
} else if (jdlDefinitions) {
await EnvironmentBuilder.run([`jhipster:${GENERATOR_JDL}`], { ...generatorOptions, inline: jdlDefinitions }, envOptions);
}
setGithubTaskOutput(RESULT_OUTPUT, SUCCESS);

if (this.codeWorkspace) {
await this.composeWithJHipster('@jhipster/jhipster-dev:code-workspace', {
generatorOptions: {
samplePath: this.projectFolder,
} as any,
});
}
},
});
}
}
49 changes: 43 additions & 6 deletions .blueprint/generate-sample/command.mts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { join } from 'node:path';
import process from 'node:process';
import { defaultSamplesFolder } from '../constants.js';
import { JHipsterCommandDefinition } from '../../generators/base/api.js';
import { GENERATOR_APP, GENERATOR_WORKSPACES } from '../../generators/generator-list.js';

Expand All @@ -25,17 +28,51 @@ const command: JHipsterCommandDefinition = {
type: String,
},
},
options: {
configs: {
entitiesSample: {
cli: {
type: String,
description: 'Entities sample to copy',
},
configure: (gen: any) => {
if (['mongodb', 'couchbase'].includes(gen.entitiesSample)) {
gen.entitiesSample = 'document';
}
},
choices: ['sql', 'sqllight', 'micro', 'sqlfull', 'none', 'neo4j', 'mongodb', 'document', 'cassandra', 'couchbase'],
scope: 'generator',
},
global: {
type: Boolean,
description: 'Generate in global samples folder',
cli: {
type: Boolean,
description: 'Generate in global samples folder',
},
configure: (gen: any) => {
if (gen.global && !gen.projectFolder) {
gen.projectFolder = join(gen._globalConfig.get('samplesFolder') ?? defaultSamplesFolder, gen.sampleName);
}
},
scope: 'generator',
},
projectFolder: {
type: String,
description: 'Folder to generate the sample',
cli: {
type: String,
description: 'Folder to generate the sample',
env: 'JHI_FOLDER_APP',
},
configure: (gen: any) => {
if (!gen.projectFolder) {
gen.projectFolder = process.cwd();
}
},
scope: 'generator',
},
},
options: {
sampleYorcFolder: {
type: Boolean,
description: 'Treat sample arg as .yo-rc.json folder path',
scope: 'generator',
env: 'JHI_FOLDER_APP',
},
},
import: [GENERATOR_APP, GENERATOR_WORKSPACES],
Expand Down
Loading

0 comments on commit 7c5d7dd

Please sign in to comment.