mirror of
https://github.com/strapi/strapi.git
synced 2025-08-08 08:46:42 +00:00
update route generation
This commit is contained in:
parent
d5113d6acb
commit
efbd9fcf42
@ -122,9 +122,22 @@ const createContentType = async ({ contentType, components = [] }, options = {})
|
||||
* Generate an API squeleton
|
||||
* @param {string} name
|
||||
*/
|
||||
const generateAPI = ({ singularName, kind = 'collectionType' }) => {
|
||||
const generateAPI = ({ singularName, kind = 'collectionType', pluralName, displayName }) => {
|
||||
const strapiGenerators = require('@strapi/generators');
|
||||
return strapiGenerators.generate('api', { id: singularName, kind }, { dir: strapi.dirs.root });
|
||||
return strapiGenerators.generate(
|
||||
'api',
|
||||
{
|
||||
id: singularName,
|
||||
kind,
|
||||
singularName,
|
||||
pluralName,
|
||||
displayName,
|
||||
createContentType: true,
|
||||
generateDefaultRoutes: true,
|
||||
attributes: [],
|
||||
},
|
||||
{ dir: strapi.dirs.root }
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -3,10 +3,11 @@
|
||||
const { join } = require('path');
|
||||
const fs = require('fs-extra');
|
||||
const validateInput = require('./utils/validate-input');
|
||||
const getCtNamesPrompts = require('./utils/get-ct-names-prompts');
|
||||
const getKindPrompts = require('./utils/get-kind-prompts');
|
||||
const getDraftAndPublishPrompts = require('./utils/get-draft-and-publish-prompts');
|
||||
const getAttributesPrompts = require('./utils/get-attributes-prompts');
|
||||
const getCtNamesPrompts = require('./prompts/get-ct-names-prompts');
|
||||
const getKindPrompts = require('./prompts/get-kind-prompts');
|
||||
const getDraftAndPublishPrompts = require('./prompts/get-draft-and-publish-prompts');
|
||||
const getAttributesPrompts = require('./prompts/get-attributes-prompts');
|
||||
const getDefaultRoutesPrompts = require('./prompts/get-default-routes-prompts');
|
||||
|
||||
module.exports = plop => {
|
||||
// API generator
|
||||
@ -48,26 +49,10 @@ module.exports = plop => {
|
||||
return pluginsDirContent;
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'list',
|
||||
name: 'kind',
|
||||
message: 'Please choose the model type',
|
||||
default: 'collectionType',
|
||||
choices: [
|
||||
{ name: 'Collection Type', value: 'collectionType' },
|
||||
{ name: 'Single Type', value: 'singleType' },
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'confirm',
|
||||
name: 'useDraftAndPublish',
|
||||
default: false,
|
||||
message: 'Use draft and publish?',
|
||||
},
|
||||
{
|
||||
type: 'confirm',
|
||||
name: 'createContentType',
|
||||
default: false,
|
||||
default: true,
|
||||
message: 'Create a content-type?',
|
||||
},
|
||||
]);
|
||||
@ -82,6 +67,7 @@ module.exports = plop => {
|
||||
...getCtNamesPrompts,
|
||||
...getKindPrompts,
|
||||
...getDraftAndPublishPrompts,
|
||||
...getDefaultRoutesPrompts,
|
||||
])),
|
||||
attributes: await getAttributesPrompts(inquirer),
|
||||
};
|
||||
@ -111,33 +97,41 @@ module.exports = plop => {
|
||||
return baseActions;
|
||||
}
|
||||
|
||||
const routeType =
|
||||
answers.kind === 'singleType'
|
||||
? 'single-type-routes.js.hbs'
|
||||
: 'collection-type-routes.js.hbs';
|
||||
|
||||
if (answers.createContentType) {
|
||||
baseActions.push(
|
||||
...(answers.isPluginApi && answers.plugin
|
||||
? plop.getGenerator('content-type').actions({
|
||||
...answers,
|
||||
destination: 'plugin',
|
||||
plugin: answers.id,
|
||||
})
|
||||
: plop.getGenerator('content-type').actions({
|
||||
...answers,
|
||||
destination: 'new',
|
||||
}))
|
||||
);
|
||||
if (!answers.createContentType) {
|
||||
return [
|
||||
{
|
||||
type: 'add',
|
||||
path: `${filePath}/routes/{{id}}.js`,
|
||||
templateFile: `templates/single-route.js.hbs`,
|
||||
},
|
||||
...baseActions,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
if (answers.generateDefaultRoutes) {
|
||||
const routeType =
|
||||
answers.kind === 'singleType'
|
||||
? 'single-type-routes.js.hbs'
|
||||
: 'collection-type-routes.js.hbs';
|
||||
|
||||
baseActions.push({
|
||||
type: 'add',
|
||||
path: `${filePath}/routes/{{id}}.js`,
|
||||
templateFile: `templates/${routeType}`,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const destination =
|
||||
answers.isPluginApi && answers.plugin
|
||||
? { destination: 'plugin', plugin: answers.id }
|
||||
: { destination: 'new' };
|
||||
|
||||
return [
|
||||
...baseActions,
|
||||
...plop.getGenerator('content-type').actions({
|
||||
...answers,
|
||||
...destination,
|
||||
}),
|
||||
];
|
||||
},
|
||||
});
|
||||
|
@ -2,12 +2,12 @@
|
||||
|
||||
const slugify = require('@sindresorhus/slugify');
|
||||
|
||||
const getDestinationPrompts = require('./utils/get-destination-prompts');
|
||||
const getDestinationPrompts = require('./prompts/get-destination-prompts');
|
||||
const getFilePath = require('./utils/get-file-path');
|
||||
const getCtNamesPrompts = require('./utils/get-ct-names-prompts');
|
||||
const getKindPrompts = require('./utils/get-kind-prompts');
|
||||
const getDraftAndPublishPrompts = require('./utils/get-draft-and-publish-prompts');
|
||||
const getAttributesPrompts = require('./utils/get-attributes-prompts');
|
||||
const getCtNamesPrompts = require('./prompts/get-ct-names-prompts');
|
||||
const getKindPrompts = require('./prompts/get-kind-prompts');
|
||||
const getDraftAndPublishPrompts = require('./prompts/get-draft-and-publish-prompts');
|
||||
const getAttributesPrompts = require('./prompts/get-attributes-prompts');
|
||||
|
||||
module.exports = plop => {
|
||||
// Model generator
|
||||
|
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const getDestinationPrompts = require('./utils/get-destination-prompts');
|
||||
const getDestinationPrompts = require('./prompts/get-destination-prompts');
|
||||
const getFilePath = require('./utils/get-file-path');
|
||||
const validateInput = require('./utils/validate-input');
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const getDestinationPrompts = require('./utils/get-destination-prompts');
|
||||
const getDestinationPrompts = require('./prompts/get-destination-prompts');
|
||||
|
||||
module.exports = plop => {
|
||||
// middleware generator
|
||||
|
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const getDestinationPrompts = require('./utils/get-destination-prompts');
|
||||
const getDestinationPrompts = require('./prompts/get-destination-prompts');
|
||||
|
||||
module.exports = plop => {
|
||||
// Policy generator
|
||||
|
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const validateInput = require('./validate-input');
|
||||
const validateInput = require('../utils/validate-input');
|
||||
|
||||
const DEFAULT_TYPES = [
|
||||
// advanced types
|
@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = [
|
||||
{
|
||||
type: 'confirm',
|
||||
name: 'generateDefaultRoutes',
|
||||
default: true,
|
||||
message: 'Generate default routes?',
|
||||
},
|
||||
];
|
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const validateInput = require('./validate-input');
|
||||
const validateInput = require('../utils/validate-input');
|
||||
|
||||
module.exports = [
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const getDestinationPrompts = require('./utils/get-destination-prompts');
|
||||
const getDestinationPrompts = require('./prompts/get-destination-prompts');
|
||||
const getFilePath = require('./utils/get-file-path');
|
||||
|
||||
module.exports = plop => {
|
||||
|
@ -0,0 +1,12 @@
|
||||
module.exports = {
|
||||
routes: [
|
||||
// {
|
||||
// method: 'GET',
|
||||
// path: '/{{id}}',
|
||||
// handler: '{{id}}.exampleAction',
|
||||
// config: {
|
||||
// policies: [],
|
||||
// },
|
||||
// },
|
||||
],
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user