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

Adding module count, module label, and theme screenshot marketplace validators #504

Merged
merged 11 commits into from
May 24, 2021

Conversation

brandenrodgers
Copy link
Contributor

@brandenrodgers brandenrodgers commented May 18, 2021

Description and Context

Adding two new validator types for the marketplace theme validation command. This is a continuation of #449

Screenshots

Example console output (I set max # modules to 3 in this example):
image

TODO

  • I am going to look into DRY-ing this up a bit because there is some repeated code for parsing out unique modules

Who to Notify

@brandenrodgers brandenrodgers changed the title [WIP] Adding module count and module label marketplace validators Adding module count, module label, and theme screenshot marketplace validators May 20, 2021
constructor(options) {
super(options);

this.errors = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KatzMitch I'm open to suggestions for better error messaging in all of these. I haven't gotten any design input on any of it, and I'm sure there's better phrasing that I could be using.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pulled in Amanda for feedback

};
}

getUniqueModulesFromFiles(files) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parses the file path list and picks out all of the unique modules in it. It returns an object that looks like this:

const uniqueModules = {
  '/Users/brodgers/src/cms-devex-super-repo/hubspot-cli/tmp/my_module.module': {
    'fields.json': '/Users/brodgers/src/cms-devex-super-repo/hubspot-cli/tmp/my_module.module/fields.json',
    'meta.json': '/Users/brodgers/src/cms-devex-super-repo/hubspot-cli/tmp/my_module.module/meta.json',
    'module.html': '/Users/brodgers/src/cms-devex-super-repo/hubspot-cli/tmp/my_module.module/module.html'
  },
  '/Users/brodgers/src/cms-devex-super-repo/hubspot-cli/tmp/my_module_1.module': {
    'fields.json': '/Users/brodgers/src/cms-devex-super-repo/hubspot-cli/tmp/my_module_1.module/fields.json',
    'meta.json': '/Users/brodgers/src/cms-devex-super-repo/hubspot-cli/tmp/my_module_1.module/meta.json',
    'module.css': '/Users/brodgers/src/cms-devex-super-repo/hubspot-cli/tmp/my_module_1.module/module.css',
    'module.html': '/Users/brodgers/src/cms-devex-super-repo/hubspot-cli/tmp/my_module_1.module/module.html',
    'module.js': '/Users/brodgers/src/cms-devex-super-repo/hubspot-cli/tmp/my_module_1.module/module.js'
  },
  '/Users/brodgers/src/cms-devex-super-repo/hubspot-cli/tmp/my_module_2.module': {
    'fields.json': '/Users/brodgers/src/cms-devex-super-repo/hubspot-cli/tmp/my_module_2.module/fields.json',
    'meta.json': '/Users/brodgers/src/cms-devex-super-repo/hubspot-cli/tmp/my_module_2.module/meta.json',
    'module.css': '/Users/brodgers/src/cms-devex-super-repo/hubspot-cli/tmp/my_module_2.module/module.css',
    'module.html': '/Users/brodgers/src/cms-devex-super-repo/hubspot-cli/tmp/my_module_2.module/module.html',
    'module.js': '/Users/brodgers/src/cms-devex-super-repo/hubspot-cli/tmp/my_module_2.module/module.js'
  }
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be easier to store this as an array of the relative paths of the files? It looks like we are manipulating these to be that anyway later.

const uniqueModules = {
  '/Users/brodgers/src/cms-devex-super-repo/hubspot-cli/tmp/my_module.module': [
    'fields.json',
    'meta.json',
    'module.html'
  ],
  '/Users/brodgers/src/cms-devex-super-repo/hubspot-cli/tmp/my_module_1.module': [
    'fields.json',
    'meta.json',
    'module.css',
    'module.html',
    'module.js'
  ],
  '/Users/brodgers/src/cms-devex-super-repo/hubspot-cli/tmp/my_module_2.module': [
    'fields.json',
    'meta.json',
    'module.css',
    'module.html',
    'module.js'
  ]
}

@brandenrodgers
Copy link
Contributor Author

To make the code a little DRY-er, I combined some of the validators that were doing similar things. For example, the ModuleCountValidator and ModuleLabelValidator both needed to parse the file path list to pick out the unique modules. Rather than doing that twice, I just combined them into one single ModuleValidator.

INVALID: {
key: 'invalid',
INVALID_THEME_JSON: {
key: 'invalidThemeJSON',
getCopy: () => 'Invalid json in theme.json file',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this invalid JSON syntax, or includes invalid fields (or has fields that aren't a thing)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is invalid JSON syntax

packages/cli/lib/validators/__tests__/ModuleValidator.js Outdated Show resolved Hide resolved
};
}

getUniqueModulesFromFiles(files) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be easier to store this as an array of the relative paths of the files? It looks like we are manipulating these to be that anyway later.

const uniqueModules = {
  '/Users/brodgers/src/cms-devex-super-repo/hubspot-cli/tmp/my_module.module': [
    'fields.json',
    'meta.json',
    'module.html'
  ],
  '/Users/brodgers/src/cms-devex-super-repo/hubspot-cli/tmp/my_module_1.module': [
    'fields.json',
    'meta.json',
    'module.css',
    'module.html',
    'module.js'
  ],
  '/Users/brodgers/src/cms-devex-super-repo/hubspot-cli/tmp/my_module_2.module': [
    'fields.json',
    'meta.json',
    'module.css',
    'module.html',
    'module.js'
  ]
}


Object.keys(uniqueModules).forEach(modulePath => {
const metaJSONFile = uniqueModules[modulePath]['meta.json'];
const relativePath = modulePath.replace(`${absoluteThemePath}/`, '');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we stored the uniqueModules as an array of the relative filepaths, this could be a bit easier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if I'm misunderstanding what you're suggesting, but I think what I have in place now is simpler than that.

I posted an example of the current shape of uniqueModules here.

Right now I'm using this object for two things. The first thing I need is to find the total number of modules, which I can do by counting the number of keys in the uniqueModules object (which should each correspond to a module in the theme). The second thing I need to do is find the path to the meta.json file for each module. Storing the files as an array would mean that I'd need to parse the array of files for each module to find the meta.json file. As it is now, I can look up the meta.json file by doing something like this uniqueModules[<module path>]['meta.json']

@brandenrodgers
Copy link
Contributor Author

I'm going to merge this and address any remaining comments/concerns in my follow up PR here.

@brandenrodgers brandenrodgers merged commit 05d0008 into master May 24, 2021
@brandenrodgers brandenrodgers deleted the marketplace-theme-validators-1 branch May 24, 2021 19:33
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

Successfully merging this pull request may close these issues.

5 participants