-
Notifications
You must be signed in to change notification settings - Fork 56
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
Conversation
constructor(options) { | ||
super(options); | ||
|
||
this.errors = { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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'
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool!
There was a problem hiding this comment.
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'
]
}
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', |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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/marketplaceValidators/theme/ThemeValidator.js
Show resolved
Hide resolved
packages/cli/lib/validators/marketplaceValidators/theme/ModuleValidator.js
Outdated
Show resolved
Hide resolved
packages/cli/lib/validators/marketplaceValidators/theme/ModuleValidator.js
Show resolved
Hide resolved
}; | ||
} | ||
|
||
getUniqueModulesFromFiles(files) { |
There was a problem hiding this comment.
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}/`, ''); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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']
I'm going to merge this and address any remaining comments/concerns in my follow up PR here. |
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):
TODO
Who to Notify