Skip to content
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

feat: support outDir option for controllers #10814

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/cli/generators/controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ module.exports = class ControllerGenerator extends ArtifactGenerator {
required: false,
description: g.f('Type for the %s', this.artifactInfo.type),
});
this.option('outDir', {
type: String,
required: false,
description: 'Custom output directory for controller',
});

return super._setupGenerator();
}
Expand Down Expand Up @@ -261,6 +266,9 @@ module.exports = class ControllerGenerator extends ArtifactGenerator {
if (debug.enabled) {
debug(`Using template at: ${source}`);
}
if (this.options.outDir) {
this.artifactInfo.outDir = path.resolve(this.options.outDir);
}
const dest = this.destinationPath(
path.join(this.artifactInfo.outDir, this.artifactInfo.outFile),
);
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/lib/base-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,20 +494,20 @@ module.exports = class BaseGenerator extends Generator {
}

async _updateIndexFile(dir, file) {
await updateIndex(dir, file, this.fs);

// Output for users
const updateDirRelPath = path.relative(
this.artifactInfo.relPath,
this.artifactInfo.outDir,
);

const outPath = path.join(
await updateIndex(
this.artifactInfo.relPath,
file,
this.fs,
updateDirRelPath,
'index.ts',
);

// Output for users
const outPath = path.join(this.artifactInfo.relPath, 'index.ts');
this.log(chalk.green(' update'), `${outPath}`);
}
};
4 changes: 2 additions & 2 deletions packages/cli/lib/update-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const defaultFs = {
* @param {String} dir The directory in which index.ts is to be updated/created
* @param {*} file The new file to be exported from index.ts
*/
module.exports = async function (dir, file, fsApis) {
module.exports = async function (dir, file, fsApis, subDir = '') {
const {read, write, append, exists} = {...defaultFs, ...fsApis};
debug(`Updating index with ${path.join(dir, file)}`);
const indexFile = path.join(dir, 'index.ts');
Expand All @@ -32,7 +32,7 @@ module.exports = async function (dir, file, fsApis) {
if (indexExists) {
index = await read(indexFile);
}
const content = `export * from './${file.slice(0, -3)}';\n`;
const content = `export * from './${subDir ? subDir + '/' : ''}${file.slice(0, -3)}';\n`;
if (!index.includes(content)) {
if (indexExists) {
await append(indexFile, content);
Expand Down
1 change: 0 additions & 1 deletion packages/rest/src/validation/request-body.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ export async function validateValueAgainstSchema(
buildErrorDetails(validationErrors),
);
}

// Throw invalid value error
throw RestHttpErrors.invalidData(value, options.name ?? '(unknown)', {
details: buildErrorDetails(validationErrors),
Expand Down
Loading