-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
move entity to base-application #20957
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import _ from 'lodash'; | ||
import type Storage from 'yeoman-generator/lib/util/storage.js'; | ||
|
||
import BaseGenerator from '../base/index.mjs'; | ||
import { JHIPSTER_CONFIG_DIR } from '../generator-constants.mjs'; | ||
import { getEntitiesFromDir } from './support/index.mjs'; | ||
|
||
const { upperFirst } = _; | ||
|
||
// Temporary Generator with Typescript implementations | ||
export default class BaseApplicationTsGenerator extends BaseGenerator { | ||
/** | ||
* Get all the generator configuration from the .yo-rc.json file | ||
* @param entityName - Name of the entity to load. | ||
* @param create - Create storage if doesn't exists. | ||
*/ | ||
getEntityConfig(entityName: string, create = false): Storage | undefined { | ||
const entityPath = this.destinationPath(JHIPSTER_CONFIG_DIR, `${upperFirst(entityName)}.json`); | ||
if (!create && !this.fs.exists(entityPath)) return undefined; | ||
return this.createStorage(entityPath, { sorted: true } as any); | ||
} | ||
|
||
/** | ||
* get sorted list of entitiy names according to changelog date (i.e. the order in which they were added) | ||
*/ | ||
getExistingEntityNames(): string[] { | ||
return this.getExistingEntities().map(entity => entity.name); | ||
} | ||
|
||
/** | ||
* get sorted list of entities according to changelog date (i.e. the order in which they were added) | ||
*/ | ||
getExistingEntities(): { name: string; definition: Record<string, any> }[] { | ||
function isBefore(e1, e2) { | ||
return e1.definition.changelogDate - e2.definition.changelogDate; | ||
} | ||
|
||
const configDir = this.destinationPath(JHIPSTER_CONFIG_DIR); | ||
|
||
const entities: { name: string; definition: Record<string, any> }[] = []; | ||
for (const entityName of [...new Set(((this.jhipsterConfig.entities as string[]) || []).concat(getEntitiesFromDir(configDir)))]) { | ||
const definition = this.getEntityConfig(entityName)?.getAll(); | ||
if (definition) { | ||
entities.push({ name: entityName, definition }); | ||
} | ||
} | ||
entities.sort(isBefore); | ||
this.jhipsterConfig.entities = entities.map(({ name }) => name); | ||
return entities; | ||
} | ||
} |
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,39 @@ | ||
/** | ||
* Copyright 2013-2023 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, mkdirSync, opendirSync } from 'fs'; | ||
import { extname, basename } from 'path'; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export function getEntitiesFromDir(configDir: string): string[] { | ||
if (!existsSync(configDir)) { | ||
mkdirSync(configDir); | ||
} | ||
const dir = opendirSync(configDir); | ||
const entityNames: string[] = []; | ||
let dirent = dir.readSync(); | ||
while (dirent !== null) { | ||
const extension = extname(dirent.name); | ||
if (dirent.isFile() && extension === '.json') { | ||
entityNames.push(basename(dirent.name, extension)); | ||
} | ||
dirent = dir.readSync(); | ||
} | ||
dir.closeSync(); | ||
return entityNames; | ||
} |
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
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
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be in a support file isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO no.
Every core api should be implemented inline in the generator (except some utilities).
And we should avoid utilities to use any complex parameter like the generator and the log.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why am I stating that: these APIs will certainly be used by many generators, so we'll avoid passing complex parameters (
generator
) reusing them by moving this method to a dedicatedsupport
package.I agree
generator
should not be passed as an attribute. LogAdapter looks to be a must (quite systematic) as there's no slf4j-like static injection fwk