-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Validations and zip scripts added #13
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
base: main
Are you sure you want to change the base?
Conversation
const archive = archiver('zip', { zlib: { level: COMPRESSION_LEVEL } }); | ||
|
||
output.on('close', function () { | ||
console.log(`Successfully zipped out folder to out.zip`); |
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.
Successfully created [name].zip
import { readFileSync } from 'fs'; | ||
import { resolve } from 'path'; | ||
|
||
const 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.
should not be a global variable.
const requiredFields = ['id', 'title', 'url', 'scopes']; | ||
const optionalFields = ['props']; | ||
|
||
checkRedundantFields(config, requiredFields, optionalFields); |
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.
pass args as an object
const optionalFields = ['props']; | ||
|
||
checkRedundantFields(config, requiredFields, optionalFields); | ||
validateRequiredFields(config, requiredFields, true); |
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.
pass args as an object
function validateRequiredFields({ config, requiredFields, isWidget }) { | ||
const errors = []; | ||
|
||
requiredFields.forEach(field => { |
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.
can use reduce?
const path = resolve(process.cwd(), 'manifest.json'); | ||
const config = JSON.parse(readFileSync(path)); | ||
|
||
try { |
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.
why is try catch needed?
tools/validate.js
Outdated
}; | ||
|
||
const validateProps = props => { | ||
const errors = [`Value of field props should be an object`]; |
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.
Field props of ___ should be an object
tools/validate.js
Outdated
Object.entries(config).reduce((acc, [key]) => { | ||
if (!requiredFields.includes(key) && !optionalFields.includes(key)) { | ||
acc.push( | ||
`Field '${key}' should be removed from ${ |
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.
should be removed from <> not supported
tools/validate.js
Outdated
if (!requiredFields.includes(key) && !optionalFields.includes(key)) { | ||
acc.push( | ||
`Field '${key}' should be removed from ${ | ||
isWidget !== undefined ? `${isWidget ? 'widget' : 'page'} "${config.title}"` : 'manifest object' |
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.
too complicated. move to a function. return full strings
tools/validate.js
Outdated
if (!(field in config)) { | ||
acc.push(`Field '${field}' is required in manifest object`); | ||
} else if (field === 'integrationType' && !INTEGRATION_TYPES.includes(config[field])) { | ||
acc.push(`Field ${field} should be one of ${INTEGRATION_TYPES}`); |
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.
we already know if its a react type widget of iframe. user doesnt need to choose. it should be according to the widget type
scripts/zip.js
Outdated
const path = resolve(process.cwd(), 'manifest.json'); | ||
const config = JSON.parse(readFileSync(path)); | ||
|
||
const zipFileName = config.name + ' ' + config.version + '.zip'; |
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.
template literal?
scripts/validate.js
Outdated
|
||
const appType = '<%=appType%>'; | ||
|
||
const INTEGRATION_TYPES = { 'React Component': 'VIRTUALIZED', iFrame: 'CONTAINERIZED' }; |
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.
can we put all these keys, values in constants and use that everywhere?
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.
should we rename this to something like APP_TYPE_VS_INT_TYPE
?
scripts/validate.js
Outdated
}; | ||
|
||
const checkRedundantFields = ({ config, requiredFields, optionalFields, isWidget }) => | ||
Object.entries(config).reduce((acc, [key]) => { |
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.
Object.keys() ?
scripts/validate.js
Outdated
return acc; | ||
}, []); | ||
|
||
const validateManifestOptionalFields = (config, optionalFields) => |
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.
can we reduce over config and remove optionalFields arg?
scripts/validate.js
Outdated
const validateManifestOptionalFields = (config, optionalFields) => | ||
optionalFields.reduce((acc, field) => { | ||
if (field === 'basePath') { | ||
if (field in config && !(typeof config[field] === 'string' && isUrlValid(config[field]))) { |
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.
just need !isUrlValid check?
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.
also we can use exhaustive switch statement here
No description provided.