mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 15:13:21 +00:00
don't generate default routes when generating plugin api (#5586)
* don't generate default routes when generating plugin api Signed-off-by: Pierre Noël <pierre.noel@strapi.io> * remove console log Signed-off-by: Pierre Noël <pierre.noel@strapi.io> Co-authored-by: Pierre Noël <pierre.noel@strapi.io> Co-authored-by: Alexandre BODIN <alexandrebodin@users.noreply.github.com>
This commit is contained in:
parent
44d77d8063
commit
a63c692fca
@ -97,46 +97,19 @@ function generateCollectionTypeRoutes({ route, name }) {
|
||||
*/
|
||||
|
||||
module.exports = scope => {
|
||||
const routes =
|
||||
scope.contentTypeKind === 'singleType'
|
||||
? generateSingleTypeRoutes({
|
||||
route: scope.route,
|
||||
name: scope.name,
|
||||
})
|
||||
: generateCollectionTypeRoutes({
|
||||
route: scope.route,
|
||||
name: scope.name,
|
||||
});
|
||||
let routes = [];
|
||||
if (!scope.args.plugin) {
|
||||
routes =
|
||||
scope.contentTypeKind === 'singleType'
|
||||
? generateSingleTypeRoutes({ route: scope.route, name: scope.name })
|
||||
: generateCollectionTypeRoutes({ route: scope.route, name: scope.name });
|
||||
}
|
||||
|
||||
// We have to delete current file
|
||||
// if routes.json already exists, then merge
|
||||
if (fs.existsSync(scope.rootPath)) {
|
||||
let current;
|
||||
|
||||
try {
|
||||
// Copy current routes.json
|
||||
current = require(scope.rootPath);
|
||||
|
||||
// Remove current routes.json
|
||||
fs.unlinkSync(scope.rootPath);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
current = {
|
||||
routes: [],
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
_.set(
|
||||
current,
|
||||
'routes',
|
||||
_.concat(routes, _.differenceWith(current.routes, routes, _.isEqual))
|
||||
);
|
||||
|
||||
return current;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return;
|
||||
}
|
||||
let current = require(scope.rootPath);
|
||||
fs.unlinkSync(scope.rootPath);
|
||||
routes = _.concat(routes, _.differenceWith(current.routes, routes, _.isEqual));
|
||||
}
|
||||
|
||||
return { routes };
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user