Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort fields inside JSON files for easier code review #152

Open
Dominic-Preap opened this issue Feb 5, 2025 · 0 comments
Open

Sort fields inside JSON files for easier code review #152

Dominic-Preap opened this issue Feb 5, 2025 · 0 comments

Comments

@Dominic-Preap
Copy link

Dominic-Preap commented Feb 5, 2025

Is your feature request related to a problem? Please describe.

Currently when we make change in Directus and run pull command, all of the fields in files sometimes changes the ordering making the code review is difficult to follow (example image below).

Describe the solution you'd like

In the past, we used directus-utilities to import the changes, it has the same issues but we make custom script to make sure sort alphabetically. I think we can do something similar.

Either sort fields alphabetically or default fields but make sure it's consistent.

// Example script we used in directus-utilities of Directus 10

const { Directus } = require('@directus/sdk'); // Directus SDK v10
const sortJson = require('sort-json');

const {
  exportDefaultPreset,
  exportPublicPermissions,
  exportPermissionsByRolename
} = require('directus-utilities');

const { presets, publicPermission, roles } = require('./config');

const run = async () => {
  const directus = new Directus('http://localhost:8055', {
    auth: { staticToken: 'MY_TOKEN' }
  });

  await Promise.all(presets.map(x => exportDefaultPreset(directus, x.collection, x.target)));
  await Promise.all(roles.map(x => exportPermissionsByRolename(directus, x.roleName, x.target)));
  await exportPublicPermissions(directus, publicPermission);

 // Sort fields in json
  sortJson.overwrite([
    ...presets.map(x => x.target),
    ...roles.map(x => x.target),
    publicPermission
  ]);
};

run().then(() => {
  process.exit();
});

Describe alternatives you've considered
N/A

Additional context

Image

Image

@Dominic-Preap Dominic-Preap changed the title Sort fields inside JSON files of for easier code review Sort fields inside JSON files for easier code review Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant