-
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #383 from mshima/jhipster8
upgrade to generator-jhipster v8
- Loading branch information
Showing
473 changed files
with
54,243 additions
and
35,259 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 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,157 @@ | ||
/** | ||
* Copyright 2013-2024 the original author or authors from the JHipster project. | ||
* | ||
* This file is part of the JHipster project, see https://www.jhipster.tech/ | ||
* for more information. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { existsSync, readdirSync } from 'node:fs'; | ||
import { getSamples } from './get-samples.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} | ||
*/ | ||
const command = { | ||
arguments: { | ||
sampleName: { | ||
type: String, | ||
}, | ||
}, | ||
configs: { | ||
sampleName: { | ||
prompt: gen => ({ | ||
when: !gen.all && existsSync(gen.templatePath(gen.samplesFolder)), | ||
type: 'list', | ||
message: 'which sample do you want to generate?', | ||
choices: async () => getSamples(gen.templatePath(gen.samplesFolder)), | ||
}), | ||
scope: 'generator', | ||
}, | ||
all: { | ||
description: 'Generate every sample in a workspace', | ||
cli: { | ||
type: Boolean, | ||
}, | ||
configure: gen => { | ||
if (gen.all) { | ||
gen.generatorArgs = readdirSync(this.templatePath('samples')); | ||
} | ||
}, | ||
scope: 'generator', | ||
}, | ||
samplesFolder: { | ||
description: 'Path to the samples folder', | ||
cli: { | ||
type: String, | ||
}, | ||
default: 'samples', | ||
scope: 'generator', | ||
}, | ||
entrypointGenerator: { | ||
description: 'The generator to use as the entrypoint', | ||
cli: { | ||
type: String, | ||
}, | ||
default: 'jdl', | ||
scope: 'generator', | ||
}, | ||
appSample: { | ||
description: 'Sample name to generate', | ||
cli: { | ||
type: String, | ||
env: 'JHI_APP', | ||
}, | ||
configure: gen => { | ||
if (gen.appSample && gen.appSample !== 'jdl') { | ||
gen.appSample = revertSampleName(gen.appSample); | ||
|
||
let { appSample } = gen; | ||
appSample = workflowSamples[appSample]?.['app-sample'] ?? appSample; | ||
gen.samplesFolder = `json-samples/${updateSampleName(appSample)}`; | ||
gen.entrypointGenerator = 'app'; | ||
} | ||
}, | ||
scope: 'generator', | ||
}, | ||
jdlSamples: { | ||
description: 'Generate JDL samples', | ||
cli: { | ||
type: String, | ||
env: 'JHI_JDL_APP', | ||
}, | ||
configure: gen => { | ||
if (gen.jdlSamples) { | ||
const [app, ...entities] = gen.jdlSamples.split(','); | ||
gen.samplesFolder = `jdl-samples/${updateSampleName(app)}`; | ||
gen.generatorArgs = '*.jdl'; | ||
if (entities && entities.length > 0) { | ||
gen.supportingSamples.push(...entities.map(entity => `${entity}.jdl`)); | ||
} | ||
} | ||
}, | ||
scope: 'generator', | ||
}, | ||
entityType: { | ||
description: 'Entity type to generate', | ||
cli: { | ||
env: 'JHI_ENTITY', | ||
type: String, | ||
}, | ||
configure: 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`)); | ||
} | ||
}, | ||
choices: [...Object.keys(entitiesByType), 'none'], | ||
scope: 'generator', | ||
}, | ||
jdlEntities: { | ||
description: 'Generate JDL entities samples', | ||
cli: { | ||
type: String, | ||
env: 'JHI_JDL_ENTITY', | ||
}, | ||
configure: gen => { | ||
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) { | ||
gen.supportingSamples.push(...entities.map(entity => `${entity}.jdl`)); | ||
} | ||
} | ||
}, | ||
scope: 'generator', | ||
}, | ||
}, | ||
options: {}, | ||
import: ['app', 'workspaces'], | ||
}; | ||
|
||
export default command; |
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,105 @@ | ||
import { readdir } from 'node:fs/promises'; | ||
import { readFileSync } from 'node:fs'; | ||
import BaseGenerator from 'generator-jhipster/generators/base'; | ||
|
||
export default class extends BaseGenerator { | ||
sampleName; | ||
all; | ||
samplesFolder; | ||
entrypointGenerator; | ||
generatorArgs; | ||
appSample; | ||
entityType; | ||
jdlSamples; | ||
supportingSamples = []; | ||
|
||
constructor(args, opts, features) { | ||
super(args, opts, { ...features, jhipsterBootstrap: false }); | ||
} | ||
|
||
get [BaseGenerator.INITIALIZING]() { | ||
return this.asInitializingTaskGroup({ | ||
async parseCommand() { | ||
await this.parseCurrentJHipsterCommand(); | ||
}, | ||
}); | ||
} | ||
|
||
get [BaseGenerator.PROMPTING]() { | ||
return this.asPromptingTaskGroup({ | ||
async askForSample() { | ||
await this.promptCurrentJHipsterCommand(); | ||
}, | ||
}); | ||
} | ||
|
||
get [BaseGenerator.CONFIGURING]() { | ||
return this.asConfiguringTaskGroup({ | ||
async configureCommand() { | ||
await this.configureCurrentJHipsterCommandConfig(); | ||
}, | ||
}); | ||
} | ||
|
||
get [BaseGenerator.LOADING]() { | ||
return this.asLoadingTaskGroup({ | ||
async loadCommand() { | ||
await this.loadCurrentJHipsterCommandConfig(this); | ||
}, | ||
}); | ||
} | ||
|
||
get [BaseGenerator.WRITING]() { | ||
return this.asWritingTaskGroup({ | ||
async copySample() { | ||
if (this.all) { | ||
this.log.info(`Copying all samples from ${this.samplesFolder}`); | ||
this.copyTemplate(`${this.samplesFolder}/*.jdl`, ''); | ||
} else if (this.sampleName) { | ||
this.log.info(`Copying sample from ${this.samplesFolder}/${this.sampleName}`); | ||
this.copyTemplate(`${this.samplesFolder}/${this.sampleName}`, this.sampleName, { noGlob: true }); | ||
} else { | ||
this.log.info(`Copying all files from ${this.samplesFolder}`); | ||
this.copyTemplate('*', '', { fromBasePath: this.templatePath(this.samplesFolder), globOptions: { dot: true } }); | ||
} | ||
}, | ||
async copySupportingSamples() { | ||
const { supportingSamples } = this; | ||
if (supportingSamples && supportingSamples.length > 0) { | ||
this.log.info(`Copying support samples ${supportingSamples}`); | ||
this.copyTemplate(supportingSamples, '', { | ||
fromBasePath: this.templatePath('supporting-samples'), | ||
globOptions: { dot: true }, | ||
}); | ||
} | ||
}, | ||
}); | ||
} | ||
|
||
get [BaseGenerator.END]() { | ||
return this.asEndTaskGroup({ | ||
async generateSample() { | ||
const packageJson = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url))); | ||
const projectVersion = `${packageJson.version}-git`; | ||
|
||
if (this.generatorArgs === '*.jdl') { | ||
this.generatorArgs = (await readdir(this.destinationPath())).filter(file => file.endsWith('.jdl')); | ||
} | ||
await this.composeWithJHipster(this.entrypointGenerator, { | ||
generatorArgs: this.generatorArgs ?? [this.sampleName], | ||
generatorOptions: { | ||
skipJhipsterDependencies: true, | ||
insight: false, | ||
skipChecks: true, | ||
projectVersion, | ||
ignoreApplication: false, | ||
...(this.all ? { workspaces: true, monorepository: true } : { skipInstall: true }), | ||
}, | ||
}); | ||
}, | ||
async jhipsterInfo() { | ||
await this.composeWithJHipster('info'); | ||
}, | ||
}); | ||
} | ||
} |
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,11 @@ | ||
import { readdir, stat } from 'node:fs/promises'; | ||
import { extname } from 'path'; | ||
|
||
export const getSamples = async samplesFolder => { | ||
const filenames = await readdir(samplesFolder); | ||
const entries = await Promise.all(filenames.map(async filename => [filename, await stat(`${samplesFolder}/${filename}`)])); | ||
return entries | ||
.filter(([filename, statResult]) => extname(filename) === '.jdl' || statResult.isDirectory()) | ||
.map(([filename]) => filename) | ||
.filter(filename => !filename.includes('disabled')); | ||
}; |
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,2 @@ | ||
export { default } from './generator.mjs'; | ||
export { default as command } from './command.mjs'; |
103 changes: 103 additions & 0 deletions
103
.blueprint/generate-sample/support/entities-by-type.mjs
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,103 @@ | ||
const sqllight = ['BankAccount', 'Label', 'Operation']; | ||
|
||
const document = [ | ||
'DocumentBankAccount', | ||
'EmbeddedOperation', | ||
'Place', | ||
'Division', | ||
|
||
'FieldTestEntity', | ||
'FieldTestMapstructAndServiceClassEntity', | ||
'FieldTestServiceClassAndJpaFilteringEntity', | ||
'FieldTestServiceImplEntity', | ||
'FieldTestInfiniteScrollEntity', | ||
'FieldTestPaginationEntity', | ||
|
||
'EntityWithDTO', | ||
'EntityWithPaginationAndDTO', | ||
'EntityWithServiceClassAndPagination', | ||
'EntityWithServiceClassPaginationAndDTO', | ||
'EntityWithServiceImplAndDTO', | ||
'EntityWithServiceImplAndPagination', | ||
'EntityWithServiceImplPaginationAndDTO', | ||
]; | ||
|
||
const sql = [ | ||
...sqllight, | ||
|
||
'FieldTestEntity', | ||
'FieldTestMapstructAndServiceClassEntity', | ||
'FieldTestServiceClassAndJpaFilteringEntity', | ||
'FieldTestServiceImplEntity', | ||
'FieldTestInfiniteScrollEntity', | ||
'FieldTestPaginationEntity', | ||
'FieldTestEnumWithValue', | ||
|
||
'EntityWithDTO', | ||
'EntityWithPaginationAndDTO', | ||
'EntityWithServiceClassAndPagination', | ||
'EntityWithServiceClassPaginationAndDTO', | ||
'EntityWithServiceImplAndDTO', | ||
'EntityWithServiceImplAndPagination', | ||
'EntityWithServiceImplPaginationAndDTO', | ||
|
||
'MapsIdUserProfileWithDTO', | ||
]; | ||
|
||
export const entitiesByType = { | ||
document, | ||
mongodb: document, | ||
couchbase: document, | ||
neo4j: ['Album', 'Track', 'Genre', 'Artist'], | ||
cassandra: [ | ||
'CassBankAccount', | ||
|
||
'FieldTestEntity', | ||
'FieldTestServiceImplEntity', | ||
'FieldTestMapstructAndServiceClassEntity', | ||
'FieldTestPaginationEntity', | ||
], | ||
micro: [ | ||
'MicroserviceBankAccount', | ||
'MicroserviceOperation', | ||
'MicroserviceLabel', | ||
|
||
'FieldTestEntity', | ||
'FieldTestMapstructAndServiceClassEntity', | ||
'FieldTestServiceClassAndJpaFilteringEntity', | ||
'FieldTestServiceImplEntity', | ||
'FieldTestInfiniteScrollEntity', | ||
'FieldTestPaginationEntity', | ||
], | ||
sqllight, | ||
sql, | ||
sqlfull: [ | ||
...sql, | ||
'Place', | ||
'Division', | ||
|
||
'TestEntity', | ||
'TestMapstruct', | ||
'TestServiceClass', | ||
'TestServiceImpl', | ||
'TestInfiniteScroll', | ||
'TestPagination', | ||
'TestManyToOne', | ||
'TestManyToMany', | ||
'TestManyRelPaginDTO', | ||
'TestOneToOne', | ||
'TestCustomTableName', | ||
'TestTwoRelationshipsSameEntity', | ||
'SuperMegaLargeTestEntity', | ||
|
||
'MapsIdParentEntityWithoutDTO', | ||
'MapsIdChildEntityWithoutDTO', | ||
'MapsIdGrandchildEntityWithoutDTO', | ||
'MapsIdParentEntityWithDTO', | ||
'MapsIdChildEntityWithDTO', | ||
'MapsIdGrandchildEntityWithDTO', | ||
|
||
'JpaFilteringRelationship', | ||
'JpaFilteringOtherSide', | ||
], | ||
}; |
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,2 @@ | ||
export * from './entities-by-type.mjs'; | ||
export * from './workflow-samples.mjs'; |
Oops, something went wrong.