UNPKG

zapier-platform-cli

Version:

The CLI for apps in the Zapier Developer Platform.

112 lines (101 loc) 6.33 kB
'use strict'; var _ = require('lodash'); var colors = require('colors/safe'); var utils = require('../utils'); // shadow of engine/style_checker/_condense_issues var condenseIssues = function condenseIssues(styleResult) { var res = []; var docURL = 'https://zapier.com/developer/documentation/v2/style-checks-reference'; for (var severity in styleResult) { for (var type in styleResult[severity]) { for (var method in styleResult[severity][type]) { // for ... of becaues this is an array finally var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; try { for (var _iterator = styleResult[severity][type][method][Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var message = _step.value; res.push({ category: severity, method: type + '.' + method, description: message, link: docURL + '#' + message.substr(-7, 6) }); } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } } } } return res; }; var validate = function validate(context) { context.line('\nValidating project locally.'); return Promise.resolve().then(function () { return utils.localAppCommand({ command: 'validate' }); }).then(function (errors) { var newErrors = errors.map(function (error) { error = _.extend({}, error); error.property = error.property.replace('instance.', 'App.'); error.docLinks = (error.docLinks || []).join('\n'); return error; }); var ifEmpty = colors.grey('No structural errors found during validation routine.'); utils.printData(newErrors, [['Property', 'property'], ['Message', 'message'], ['Links', 'docLinks']], ifEmpty, true); if (newErrors.length) { context.line('Your app is structurally invalid. Address concerns and run this command again.'); process.exitCode = 1; } else { context.line('This project is structurally sound!'); } }).then(function () { if (!utils.isCorrectVersion(context)) { process.exitCode = 1; } }).then(function () { if (!global.argOpts['without-style']) { context.line('\nChecking app style.'); return utils.localAppCommand({ command: 'definition' }).then(function (rawDefinition) { return utils.callAPI('/style-check', { skipDeployKey: true, method: 'POST', body: rawDefinition }); }); } else { return Promise.resolve([]); } }).then(function (styleResult) { // process errors var styleErrors = condenseIssues(styleResult); var ifEmpty = colors.grey('No style errors found during validation routine.'); utils.printData(styleErrors, [['Category', 'category'], ['Method', 'method'], ['Description', 'description'], ['Link', 'link']], ifEmpty, true); if (styleErrors.length) { process.exitCode = 1; context.line('Errors will prevent promotions, warnings are things to improve on.\n'); } else { context.line('Your app looks great!\n'); } }); }; validate.argsSpec = []; validate.argOptsSpec = { 'without-style': { flag: true, help: 'forgo pinging the Zapier server to do a style check' } }; validate.help = 'Validates the current app.'; validate.example = 'zapier validate'; validate.docs = '\nRuns the standard validation routine powered by json-schema that checks your app for any structural errors. This is the same routine that runs during `zapier build`, `zapier upload`, `zapier push` or even as a test in `zapier test`.\n\n**Arguments**\n\n' + utils.argsFragment(validate.argsSpec) + '\n' + utils.argOptsFragment(validate.argOptsSpec) + '\n' + utils.defaultArgOptsFragment() + '\n\n' + '```' + 'bash\n$ zapier validate\n# Validating project locally.\n#\n# No errors found during validation routine.\n#\n# This project is structurally sound!\n\n$ zapier validate\n# Validating project locally.\n#\n# \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n# \u2502 = 1 = \u2502\n# \u2502 Property \u2502 instance \u2502\n# \u2502 Message \u2502 requires property "platformVersion" \u2502\n# \u2502 Links \u2502 https://github.com/zapier/zapier-platform-schema/blob/v1.0.0/docs/build/schema.md#appschema \u2502\n# \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n#\n# Make any changes to your project and rerun this command.\n' + '```' + '\n'; module.exports = validate;