Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
generateOptions () {
super.generateOptions()
this.options.name = common.sanitizeName(this.options.name, '-._+a-zA-Z0-9')
if (!this.options.description && !this.options.productDescription) {
throw new Error("No Description or ProductDescription provided. Please set either a description in the app's package.json or provide it in the options.")
}
if (this.options.description) {
// Do not end with a period
this.options.description = this.options.description.replace(/\.*$/, '')
}
// Wrap the extended description to avoid rpmlint warning about
// `description-line-too-long`.
this.options.productDescription = wrap(this.options.productDescription, { width: 80, indent: '' })
// Merges user and default dependencies
this.options.requires = common.mergeUserSpecified(this.userSupplied, 'requires', this.defaults)
sanitizeName (name) {
if (name.length > 30) {
throw new Error(`The max length of the name is 30 characters, you have ${name.length}`)
}
const sanitized = common.sanitizeName(name.toLowerCase(), '-a-z0-9')
if (!/[a-z]/.test(sanitized)) {
throw new Error('The snap name needs to have at least one letter')
}
return sanitized
}
sanitizeName (name) {
const sanitized = common.sanitizeName(name.toLowerCase(), '-+.a-z0-9')
if (sanitized.length < 2) {
throw new Error('Package name must be at least two characters')
}
if (/^[^a-z0-9]/.test(sanitized)) {
throw new Error('Package name must start with an ASCII number or letter')
}
return sanitized
}
}
generateOptions () {
super.generateOptions()
this.options.name = common.sanitizeName(this.options.name, 'a-zA-Z0-9', '_')
if (!this.options.description && !this.options.productDescription) {
throw new Error("No Description or ProductDescription provided. Please set either a description in the app's package.json or provide it in the this.options.")
}
if (!this.options.authors) {
throw new Error("No Authors provided. Please set an author in the app's package.json or provide it in the this.options.")
}
return this.options
}