UNPKG

2.79 kBJavaScriptView Raw
1// Generated by CoffeeScript 1.10.0
2(function() {
3 var autocode, path;
4
5 path = require('path');
6
7 process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
8
9 global.ErrorInvalid = function(name, type) {
10 this.name = 'ErrorInvalid';
11 return this.message = "'" + name + "' is invalid.";
12 };
13
14 global.ErrorInvalid.prototype = Error.prototype;
15
16 global.ErrorType = function(name, type) {
17 this.name = 'ErrorType';
18 return this.message = "'" + name + "' must be of type (" + type + ").";
19 };
20
21 global.ErrorType.prototype = Error.prototype;
22
23 global.ErrorRequired = function(name) {
24 this.name = 'ErrorRequired';
25 return this.message = "'" + name + "' is required.";
26 };
27
28 global.ErrorRequired.prototype = Error.prototype;
29
30 autocode = function(config) {
31 var i, len, match, message, method, methods, validate;
32 methods = ['build', 'cache', 'generate', 'init', 'install', 'load', 'run', 'save', 'search', 'stop', 'test', 'update', 'validate'];
33 for (i = 0, len = methods.length; i < len; i++) {
34 method = methods[i];
35 this[method] = require("./autocode/" + method);
36 }
37 if (typeof config === 'object') {
38 validate = this.validate(config);
39 if (!validate.valid) {
40 match = 'Failed "type" criteria:';
41 if (validate.errors[0].message.match(match)) {
42 message = validate.errors[0].message.replace(/Failed "type" criteria: expecting (.*?), found (.*?)$/, "`" + (validate.errors[0].context.substr(2)) + "` must be a `$1`, not a `$2`.");
43 message = message.replace(/\ or\ /, '` or `');
44 throw new Error(message);
45 }
46 match = 'Failed "required" criteria:';
47 if (validate.errors[0].message.match(match)) {
48 message = validate.errors[0].message.replace(/Failed "required" criteria: missing property \((.*?)\)$/, "`" + (validate.errors[0].context.substr(2).replace(/\//, '.')) + ".$1` is required.");
49 message = message.replace(/\ or\ /, '` or `');
50 throw new Error(message);
51 }
52 console.log(validate);
53 throw new Error("Config is invalid.");
54 }
55 this.config = config;
56 this.path = this.config.path ? this.config.path : process.cwd();
57 } else if (typeof config === 'string') {
58 this.config = this.load(config);
59 this.path = this.config.path ? this.config.path : config;
60 } else {
61 this.config = {};
62 this.path = process.cwd();
63 }
64 if (!this.path.match(/^\//)) {
65 this.path = path.normalize((process.cwd()) + "/" + this.path);
66 }
67 if (this.config === false) {
68 throw new Error("Unable to load config for (" + this.path + ").");
69 }
70 if (!this.config.host) {
71 this.config.host = 'github.com';
72 }
73 return this;
74 };
75
76 module.exports = autocode;
77
78}).call(this);