mirror of
https://github.com/strapi/strapi.git
synced 2025-08-09 17:26:11 +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
|
* Generate an API squeleton
|
||||||
* @param {string} name
|
* @param {string} name
|
||||||
*/
|
*/
|
||||||
const generateAPI = ({ singularName, kind = 'collectionType' }) => {
|
const generateAPI = ({ singularName, kind = 'collectionType', pluralName, displayName }) => {
|
||||||
const strapiGenerators = require('@strapi/generators');
|
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 { join } = require('path');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const validateInput = require('./utils/validate-input');
|
const validateInput = require('./utils/validate-input');
|
||||||
const getCtNamesPrompts = require('./utils/get-ct-names-prompts');
|
const getCtNamesPrompts = require('./prompts/get-ct-names-prompts');
|
||||||
const getKindPrompts = require('./utils/get-kind-prompts');
|
const getKindPrompts = require('./prompts/get-kind-prompts');
|
||||||
const getDraftAndPublishPrompts = require('./utils/get-draft-and-publish-prompts');
|
const getDraftAndPublishPrompts = require('./prompts/get-draft-and-publish-prompts');
|
||||||
const getAttributesPrompts = require('./utils/get-attributes-prompts');
|
const getAttributesPrompts = require('./prompts/get-attributes-prompts');
|
||||||
|
const getDefaultRoutesPrompts = require('./prompts/get-default-routes-prompts');
|
||||||
|
|
||||||
module.exports = plop => {
|
module.exports = plop => {
|
||||||
// API generator
|
// API generator
|
||||||
@ -48,26 +49,10 @@ module.exports = plop => {
|
|||||||
return pluginsDirContent;
|
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',
|
type: 'confirm',
|
||||||
name: 'createContentType',
|
name: 'createContentType',
|
||||||
default: false,
|
default: true,
|
||||||
message: 'Create a content-type?',
|
message: 'Create a content-type?',
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
@ -82,6 +67,7 @@ module.exports = plop => {
|
|||||||
...getCtNamesPrompts,
|
...getCtNamesPrompts,
|
||||||
...getKindPrompts,
|
...getKindPrompts,
|
||||||
...getDraftAndPublishPrompts,
|
...getDraftAndPublishPrompts,
|
||||||
|
...getDefaultRoutesPrompts,
|
||||||
])),
|
])),
|
||||||
attributes: await getAttributesPrompts(inquirer),
|
attributes: await getAttributesPrompts(inquirer),
|
||||||
};
|
};
|
||||||
@ -111,33 +97,41 @@ module.exports = plop => {
|
|||||||
return baseActions;
|
return baseActions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!answers.createContentType) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
type: 'add',
|
||||||
|
path: `${filePath}/routes/{{id}}.js`,
|
||||||
|
templateFile: `templates/single-route.js.hbs`,
|
||||||
|
},
|
||||||
|
...baseActions,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (answers.generateDefaultRoutes) {
|
||||||
const routeType =
|
const routeType =
|
||||||
answers.kind === 'singleType'
|
answers.kind === 'singleType'
|
||||||
? 'single-type-routes.js.hbs'
|
? 'single-type-routes.js.hbs'
|
||||||
: 'collection-type-routes.js.hbs';
|
: 'collection-type-routes.js.hbs';
|
||||||
|
|
||||||
if (answers.createContentType) {
|
baseActions.push({
|
||||||
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',
|
|
||||||
}))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
type: 'add',
|
type: 'add',
|
||||||
path: `${filePath}/routes/{{id}}.js`,
|
path: `${filePath}/routes/{{id}}.js`,
|
||||||
templateFile: `templates/${routeType}`,
|
templateFile: `templates/${routeType}`,
|
||||||
},
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const destination =
|
||||||
|
answers.isPluginApi && answers.plugin
|
||||||
|
? { destination: 'plugin', plugin: answers.id }
|
||||||
|
: { destination: 'new' };
|
||||||
|
|
||||||
|
return [
|
||||||
...baseActions,
|
...baseActions,
|
||||||
|
...plop.getGenerator('content-type').actions({
|
||||||
|
...answers,
|
||||||
|
...destination,
|
||||||
|
}),
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
const slugify = require('@sindresorhus/slugify');
|
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 getFilePath = require('./utils/get-file-path');
|
||||||
const getCtNamesPrompts = require('./utils/get-ct-names-prompts');
|
const getCtNamesPrompts = require('./prompts/get-ct-names-prompts');
|
||||||
const getKindPrompts = require('./utils/get-kind-prompts');
|
const getKindPrompts = require('./prompts/get-kind-prompts');
|
||||||
const getDraftAndPublishPrompts = require('./utils/get-draft-and-publish-prompts');
|
const getDraftAndPublishPrompts = require('./prompts/get-draft-and-publish-prompts');
|
||||||
const getAttributesPrompts = require('./utils/get-attributes-prompts');
|
const getAttributesPrompts = require('./prompts/get-attributes-prompts');
|
||||||
|
|
||||||
module.exports = plop => {
|
module.exports = plop => {
|
||||||
// Model generator
|
// Model generator
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const getDestinationPrompts = require('./utils/get-destination-prompts');
|
const getDestinationPrompts = require('./prompts/get-destination-prompts');
|
||||||
const getFilePath = require('./utils/get-file-path');
|
const getFilePath = require('./utils/get-file-path');
|
||||||
const validateInput = require('./utils/validate-input');
|
const validateInput = require('./utils/validate-input');
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const getDestinationPrompts = require('./utils/get-destination-prompts');
|
const getDestinationPrompts = require('./prompts/get-destination-prompts');
|
||||||
|
|
||||||
module.exports = plop => {
|
module.exports = plop => {
|
||||||
// middleware generator
|
// middleware generator
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const getDestinationPrompts = require('./utils/get-destination-prompts');
|
const getDestinationPrompts = require('./prompts/get-destination-prompts');
|
||||||
|
|
||||||
module.exports = plop => {
|
module.exports = plop => {
|
||||||
// Policy generator
|
// Policy generator
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const validateInput = require('./validate-input');
|
const validateInput = require('../utils/validate-input');
|
||||||
|
|
||||||
const DEFAULT_TYPES = [
|
const DEFAULT_TYPES = [
|
||||||
// advanced 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';
|
'use strict';
|
||||||
|
|
||||||
const validateInput = require('./validate-input');
|
const validateInput = require('../utils/validate-input');
|
||||||
|
|
||||||
module.exports = [
|
module.exports = [
|
||||||
{
|
{
|
@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const getDestinationPrompts = require('./utils/get-destination-prompts');
|
const getDestinationPrompts = require('./prompts/get-destination-prompts');
|
||||||
const getFilePath = require('./utils/get-file-path');
|
const getFilePath = require('./utils/get-file-path');
|
||||||
|
|
||||||
module.exports = plop => {
|
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