strapi / codemods

A set of scripts to help migrate Strapi plugins (and in some cases Strapi applications) from v3 to v4
44 stars 13 forks source link

[feature request] New codemod to migrate controllers, routes and services files to v4 version #25

Closed tonoli closed 2 years ago

tonoli commented 2 years ago

The idea is to create a codemod that loops on all the folder of the new src/api folder. And edits the files in the folders controllers/<route-name>.js, routes/<route-name>.js andservices/<route-name>.js with the new methods createCoreController, createCoreRouter, createCoreService

v3 Router

module.exports = [
  {
    method: 'GET',
    path: '/actualites',
    handler: 'actualite.find',
    config: { policies: [] }
  },
  {
    method: 'GET',
    path: '/actualites/:id',
    handler: 'actualite.findOne',
    config: { policies: [] }
  },
  {
    method: 'POST',
    path: '/actualites',
    handler: 'actualite.create',
    config: { policies: [] }
  },
  {
    method: 'PUT',
    path: '/actualites/:id',
    handler: 'actualite.update',
    config: { policies: [] }
  },
  {
    method: 'DELETE',
    path: '/actualites/:id',
    handler: 'actualite.delete',
    config: { policies: [] }
  }
]

v4 Router

'use strict';

/**
 * actualite router.
 */

const { createCoreRouter } = require('@strapi/strapi').factories;

module.exports = createCoreRouter('api::actualite.actualite');
markkaylor commented 2 years ago

@tonoli Thanks for this suggestion. I have this one in the backlog and I think it would be great if we could add it soon. Out of curiosity is this something you would be interested in working on?

markkaylor commented 2 years ago

Closing since this was handled on https://github.com/strapi/codemods/pull/36