refactor(CLI-Generate): ♻️ fix getFilePath path for plugins

This commit is contained in:
Marin 2022-01-21 14:19:02 +02:00
parent fc099f4f15
commit e1375a80e1
6 changed files with 11 additions and 23 deletions

View File

@ -2,6 +2,7 @@
const { join } = require('path');
const fs = require('fs-extra');
const getFilePath = require('./utils/get-file-path');
const validateInput = require('./utils/validate-input');
module.exports = plop => {
@ -45,7 +46,8 @@ module.exports = plop => {
},
],
actions(answers) {
const filePath = answers.isPluginApi && answers.plugin ? 'plugins/{{plugin}}/server' : 'api/{{id}}';
const answerDestination = answers.isPluginApi && answers.plugin ? 'plugin' : 'api';
const filePath = getFilePath(answerDestination);
const baseActions = [
{

View File

@ -18,8 +18,7 @@ module.exports = plop => {
...getDestinationPrompts('controller', plop.getDestBasePath()),
],
actions(answers) {
const resolveFilePath = (isPlugin,filePath) => isPlugin ? `${filePath}/server` : filePath;
const filePath = resolveFilePath(answers.plugin,getFilePath(answers.destination));
const filePath = getFilePath(answers.destination);
return [
{

View File

@ -1,6 +1,7 @@
'use strict';
const getDestinationPrompts = require('./prompts/get-destination-prompts');
const getFilePath = require('./utils/get-file-path');
module.exports = plop => {
// middleware generator
@ -15,15 +16,7 @@ module.exports = plop => {
...getDestinationPrompts('middleware', plop.getDestBasePath(), { rootFolder: true }),
],
actions(answers) {
let filePath;
if (answers.destination === 'api') {
filePath = `api/{{ api }}`;
} else if (answers.destination === 'plugin') {
filePath = `plugins/{{ plugin }}/server`;
} else {
filePath = `./`;
}
const filePath = getFilePath(answers.destination);
return [
{
type: 'add',

View File

@ -1,6 +1,7 @@
'use strict';
const getDestinationPrompts = require('./prompts/get-destination-prompts');
const getFilePath = require('./utils/get-file-path');
module.exports = plop => {
// Policy generator
@ -15,14 +16,7 @@ module.exports = plop => {
...getDestinationPrompts('policy', plop.getDestBasePath(), { rootFolder: true }),
],
actions(answers) {
let filePath;
if (answers.destination === 'api') {
filePath = `api/{{api}}`;
} else if (answers.destination === 'plugin') {
filePath = `plugins/{{plugin}}/server`;
} else {
filePath = `./`;
}
const filePath = getFilePath(answers.destination);
return [
{

View File

@ -16,8 +16,8 @@ module.exports = plop => {
...getDestinationPrompts('service', plop.getDestBasePath()),
],
actions(answers) {
const resolveFilePath = (isPlugin,filePath) => isPlugin ? `${filePath}/server` : filePath;
const filePath = resolveFilePath(answers.plugin,getFilePath(answers.destination));
const filePath = getFilePath(answers.destination);
return [
{
type: 'add',

View File

@ -6,7 +6,7 @@ module.exports = destination => {
}
if (destination === 'plugin') {
return `plugins/{{ plugin }}`;
return `plugins/{{ plugin }}/server`;
}
return `api/{{ id }}`;