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

Update addon validation #259

Merged
merged 6 commits into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/commands/addons/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,15 @@ class AddonsCreateCommand extends Command {
console.log(
`${chalk.redBright.underline.bold(`Error: Missing required configuration for "${addonName} add-on"`)}`
)
console.log(`Please supply the configuration values as CLI flags`)
console.log()
render.missingValues(missingValues, manifest)
console.log()
const msg = `netlify addons:create ${addonName}`
console.log(`Please supply the configuration values as CLI flags`)
console.log()
console.log(`Alternatively, you can run ${chalk.cyan(msg)} with no flags to walk through the setup steps`)
console.log()
return false
}

await createSiteAddon({
Expand Down Expand Up @@ -110,6 +115,13 @@ class AddonsCreateCommand extends Command {
const userInput = await inquirer.prompt(prompts)
// Merge user input with the flags specified
configValues = updateConfigValues(manifest.config, rawFlags, userInput)
const missingRequiredValues = missingConfigValues(required, configValues)
if (missingRequiredValues && missingRequiredValues.length) {
missingRequiredValues.forEach((val) => {
console.log(`Missing required value "${val}". Please run the command again`)
})
return false
}
}

await createSiteAddon({
Expand Down
6 changes: 4 additions & 2 deletions src/commands/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ class DeployCommand extends Command {
}

let functionsFolder
// Support "functions" and "Functions"
const funcConfig = get(config, 'build.functions') || get(config, 'build.Functions')
if (flags['functions']) {
functionsFolder = path.resolve(process.cwd(), flags['functions'])
} else if (get(config, 'build.functions')) {
functionsFolder = path.resolve(site.root, get(config, 'build.functions'))
} else if (funcConfig) {
functionsFolder = path.resolve(site.root, funcConfig)
} else if (get(siteData, 'build_settings.functions_dir')) {
functionsFolder = path.resolve(site.root, get(siteData, 'build_settings.functions_dir'))
}
Expand Down
17 changes: 14 additions & 3 deletions src/utils/addons/prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ module.exports = function generatePrompts(settings) {
return prompt
}

const validateFunction = (setting.pattern) ? validate(setting.pattern) : noValidate

// For future use. Once UX is decided
// const defaultValidation = (setting.required) ? validateRequired : noValidate
const defaultValidation = noValidate
const validateFunction = (setting.pattern) ? validate(setting.pattern) : defaultValidation
const isRequiredText = (setting.required) ? ` (${chalk.yellow('required')})` : ''
if (setting.type === 'string' || setting.type.match((/string/))) {
prompt = {
type: 'input',
name: key,
message: `${chalk.white(key)} - ${setting.displayName}` || `Please enter value for ${key}`,
message: `${chalk.white(key)}${isRequiredText} - ${setting.displayName}` || `Please enter value for ${key}`,
validate: validateFunction
}
// if value previously set show it
Expand All @@ -67,6 +70,14 @@ function noValidate() {
return true
}

// Will use this soon
function validateRequired(value) { // eslint-disable-line
if (value) {
return true
}
return `Please enter a value this field is required`
}

function validate(pattern) {
return function(value) {
const regex = new RegExp(pattern)
Expand Down