Skip to content

Commit

Permalink
feat: add a logic for create repositories subdirectory
Browse files Browse the repository at this point in the history
Signed-off-by: warisniz02 <[email protected]>
  • Loading branch information
warisniz02 committed Oct 7, 2024
1 parent e329f85 commit 74efce8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
16 changes: 16 additions & 0 deletions packages/cli/generators/repository/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,13 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
subdirectory,
'model',
);
const subdir = subdirectory.split('models')[1];
if (!this.artifactInfo.modelSubDirs) {
this.artifactInfo.modelSubDirs = {};
}
subdirectoryModelList.forEach(model => {
this.artifactInfo.modelSubDirs[model] = subdir;
});
modelList = modelList.concat(subdirectoryModelList);
} catch (err) {
console.error(
Expand Down Expand Up @@ -584,6 +591,15 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
this.artifactInfo.modelName,
);

const outFile = `${
this.artifactInfo.modelSubDirs[
this.artifactInfo.modelName || this.artifactInfo.name
]
}/${this.artifactInfo.outFile}`;
if (!outFile.includes('undefined')) {
this.artifactInfo.outFile = outFile.slice(1, outFile.length);
}

this.artifactInfo.indexesToBeUpdated.push({
dir: this.artifactInfo.outDir,
file: this.artifactInfo.outFile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ import {inject} from '@loopback/core';
<%if (isRepositoryBaseBuiltin) { -%>
import {<%= repositoryTypeClass %>} from '@loopback/repository';
<% } -%>
import {<%= dataSourceClassName %>} from '../datasources';
import {<%= modelName %>, <%= modelName %>Relations} from '../models';
<%if (modelSubDirs[modelName]) { -%>
import {<%= dataSourceClassName %>} from '../../datasources';
import {<%= modelName %>, <%= modelName %>Relations} from '../../models';
<% } -%>

<%if (!modelSubDirs[modelName]) { -%>
import {<%= dataSourceClassName %>} from '../datasources';
import {<%= modelName %>, <%= modelName %>Relations} from '../models';
<% } -%>

<%if ( !isRepositoryBaseBuiltin ) { -%>
import {<%=repositoryBaseClass %>} from './<%=repositoryBaseFile %>';
<% } -%>
Expand Down

0 comments on commit 74efce8

Please sign in to comment.