fix: make generate command work (#22443)

This commit is contained in:
Bassel Kanso 2024-12-19 15:20:50 +02:00 committed by GitHub
parent 75bf07970a
commit 40d132bcf8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 10 additions and 6 deletions

View File

@ -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
});
}
);
};

View File

@ -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);

View File

@ -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';

View File

@ -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';

View File

@ -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 [