forked from jhipster/generator-jhipster
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'jhipster:main' into main
- Loading branch information
Showing
265 changed files
with
5,520 additions
and
3,819 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
} | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.