diff --git a/packages/generators/generators/src/index.ts b/packages/generators/generators/src/index.ts index 9ddc77b344..8fb42b7dd9 100644 --- a/packages/generators/generators/src/index.ts +++ b/packages/generators/generators/src/index.ts @@ -11,7 +11,13 @@ export const runCLI = async () => { }, (env) => { const argv = process.argv.slice(2); // Extract command-line arguments - Plop.execute(env, argv, (env, argv) => run(env, argv, true)); // Pass the third argument 'true' for passArgsBeforeDashes + Plop.execute(env, argv, (env, argv) => { + const options = { + ...env, + dest: join(process.cwd(), 'src'), // this will make the destination path to be based on the cwd when calling the wrapper + }; + return run(options, argv, true); // Pass the third argument 'true' for passArgsBeforeDashes + }); } ); }; diff --git a/packages/generators/generators/src/plopfile.ts b/packages/generators/generators/src/plopfile.ts index 8fff331985..0063124b49 100644 --- a/packages/generators/generators/src/plopfile.ts +++ b/packages/generators/generators/src/plopfile.ts @@ -12,7 +12,7 @@ import generateService from './plops/service'; export default (plop: NodePlopAPI) => { // Plop config plop.setWelcomeMessage('Strapi Generators'); - plop.addHelper('pluralize', (text: string) => pluralize(text)); + plop.setHelper('pluralize', (text: string) => pluralize(text)); // Generators generateApi(plop); diff --git a/packages/generators/generators/src/plops/api.ts b/packages/generators/generators/src/plops/api.ts index ccdff3b621..e1e5ddf06d 100644 --- a/packages/generators/generators/src/plops/api.ts +++ b/packages/generators/generators/src/plops/api.ts @@ -29,7 +29,6 @@ export default (plop: NodePlopAPI) => { async choices() { const pluginsPath = join(plop.getDestBasePath(), 'plugins'); const exists = await fs.pathExists(pluginsPath); - if (!exists) { throw Error('Couldn\'t find a "plugins" directory'); } @@ -51,7 +50,7 @@ export default (plop: NodePlopAPI) => { } const filePath = - answers.isPluginApi && answers.plugin ? 'plugins/{{ plugin }}' : 'api/{{ id }}'; + answers.isPluginApi && answers.plugin ? 'plugins/{{ plugin }}/server' : 'api/{{ id }}'; const currentDir = process.cwd(); const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js'; diff --git a/packages/generators/generators/src/plops/content-type.ts b/packages/generators/generators/src/plops/content-type.ts index 88628c2eb8..2b6f690fff 100644 --- a/packages/generators/generators/src/plops/content-type.ts +++ b/packages/generators/generators/src/plops/content-type.ts @@ -81,7 +81,6 @@ export default (plop: NodePlopAPI) => { }, {}); const filePath = getFilePath(answers.destination); - // TODO: use basePath instead const currentDir = process.cwd(); const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js'; diff --git a/packages/generators/generators/src/plops/policy.ts b/packages/generators/generators/src/plops/policy.ts index 0cce1c2296..2ce334bec9 100644 --- a/packages/generators/generators/src/plops/policy.ts +++ b/packages/generators/generators/src/plops/policy.ts @@ -23,8 +23,8 @@ export default (plop: NodePlopAPI) => { return []; } - const filePath = getFilePath(answers.destination); const currentDir = process.cwd(); + const filePath = getFilePath(answers.destination); const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js'; return [