mirror of
https://github.com/strapi/strapi.git
synced 2025-12-26 22:54:31 +00:00
allow the choice of the new API name
This commit is contained in:
parent
c32a1921e9
commit
ba4072fdec
@ -129,6 +129,7 @@ const generateAPI = ({ singularName, kind = 'collectionType', pluralName, displa
|
||||
{
|
||||
kind,
|
||||
singularName,
|
||||
id: singularName,
|
||||
pluralName,
|
||||
displayName,
|
||||
destination: 'new',
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
const { join } = require('path');
|
||||
const slugify = require('@sindresorhus/slugify');
|
||||
const fs = require('fs-extra');
|
||||
|
||||
const getDestinationPrompts = require('./prompts/get-destination-prompts');
|
||||
const getFilePath = require('./utils/get-file-path');
|
||||
@ -18,14 +20,42 @@ module.exports = plop => {
|
||||
const config = await inquirer.prompt([
|
||||
...ctNamesPrompts,
|
||||
...kindPrompts,
|
||||
...getDestinationPrompts('model', plop.getDestBasePath()),
|
||||
...draftAndPublishPrompts,
|
||||
...bootstrapApiPrompts,
|
||||
]);
|
||||
const attributes = await getAttributesPrompts(inquirer);
|
||||
|
||||
const api = await inquirer.prompt([
|
||||
...getDestinationPrompts('model', plop.getDestBasePath()),
|
||||
{
|
||||
when: answers => answers.destination === 'new',
|
||||
type: 'input',
|
||||
name: 'id',
|
||||
default: config.singularName,
|
||||
message: 'Name of the new API?',
|
||||
async validate(input) {
|
||||
const apiPath = join(plop.getDestBasePath(), 'api');
|
||||
const exists = await fs.pathExists(apiPath);
|
||||
|
||||
if (!exists) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const apiDir = await fs.readdir(apiPath, { withFileTypes: true });
|
||||
const apiDirContent = apiDir.filter(fd => fd.isDirectory());
|
||||
|
||||
if (apiDirContent.findIndex(api => api.name === input) !== -1) {
|
||||
throw new Error('This name is already taken.');
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
},
|
||||
...bootstrapApiPrompts,
|
||||
]);
|
||||
|
||||
return {
|
||||
...config,
|
||||
...api,
|
||||
attributes,
|
||||
};
|
||||
},
|
||||
@ -47,8 +77,6 @@ module.exports = plop => {
|
||||
|
||||
const filePath = getFilePath(answers.destination);
|
||||
|
||||
answers.id = answers.singularName;
|
||||
|
||||
const baseActions = [
|
||||
{
|
||||
type: 'add',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user