-
-
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
9 changed files
with
106 additions
and
82 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,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