Skip to content

Instantly share code, notes, and snippets.

@xavdid
Created April 19, 2017 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xavdid/3b96d92e50b43ad33e5e5341c92eb126 to your computer and use it in GitHub Desktop.
Save xavdid/3b96d92e50b43ad33e5e5341c92eb126 to your computer and use it in GitHub Desktop.
'use strict';
var _ = require('lodash');
var colors = require('colors/safe');
var utils = require('../utils');
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);
return errors;
}).then(function (errors) {
if (errors.length) {
context.line('Your app is structurally invalid. Address concerns and run this command again.');
} else {
context.line('This project looks good!');
}
}).then(function () {
if (global.argOpts['include-style']) {
utils.localAppCommand({ command: 'definition' }).then(function (rawDefinition) {
return utils.callAPI('/style-check', {
skipDeployKey: true,
method: 'POST',
body: rawDefinition
});
}).then(function (styleResult) {
// process errors
var res = [];
context.line('\nChecking app style.');
var ifEmpty = colors.grey('No style errors found during validation routine.');
for (var severity in styleResult) {
for (var type in styleResult[severity]) {
for (var method in styleResult[severity][type]) {
res.push({
category: severity,
method: type + '.' + method,
description: styleResult[severity][type][method].join('\n')
});
}
}
}
if (res.length) {
utils.printData(res, [['Category', 'category'], ['Method', 'method'], ['Description', 'description']], ifEmpty, true);
context.line('Errors will prevent deploys, warnings are things to improve on.\n');
} else {
context.line('Your app looks great!\n');
}
});
}
});
};
validate.argsSpec = [];
validate.argOptsSpec = {
'include-style': { flag: true, help: 'ping the Zapier server to do a style check' }
};
validate.help = 'Validates the current app.';
validate.example = 'zapier validate';
validate.docs = 'Runs 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 uploard`, `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 looks good!\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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment