-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
74 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { existsSync, mkdirSync, opendirSync } from 'fs'; | ||
import _ from 'lodash'; | ||
import { basename, extname } from 'path'; | ||
import type Storage from 'yeoman-generator/lib/util/storage.js'; | ||
|
||
import BaseGenerator from '../base/index.mjs'; | ||
import { JHIPSTER_CONFIG_DIR } from '../generator-constants.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); | ||
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(); | ||
|
||
const entities: { name: string; definition: Record<string, any> }[] = []; | ||
for (const entityName of [...new Set(((this.jhipsterConfig.entities as string[]) || []).concat(entityNames))]) { | ||
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
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