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:
Pierre Noël 2020-03-25 09:31:21 +01:00 committed by GitHub
parent 44d77d8063
commit a63c692fca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 };