1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-05 09:56:22 +00:00
HackMyResume/dist/verbs/create.js

104 lines
2.5 KiB
JavaScript
Raw Normal View History

2016-01-27 10:29:26 +00:00
/**
Implementation of the 'create' verb for HackMyResume.
@module verbs/create
@license MIT. See LICENSE.md for details.
*/
(function() {
var CreateVerb, HMEVENT, HMSTATUS, MKDIRP, PATH, Verb, _, _create, _createOne, chalk,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
2016-01-27 10:29:26 +00:00
MKDIRP = require('mkdirp');
PATH = require('path');
chalk = require('chalk');
Verb = require('../verbs/verb');
_ = require('underscore');
HMSTATUS = require('../core/status-codes');
HMEVENT = require('../core/event-codes');
module.exports = CreateVerb = (function(superClass) {
extend(CreateVerb, superClass);
function CreateVerb() {
CreateVerb.__super__.constructor.call(this, 'new', _create);
2016-01-27 10:29:26 +00:00
}
return CreateVerb;
})(Verb);
2016-01-27 10:29:26 +00:00
2016-02-02 02:14:36 +00:00
/** Create a new empty resume in either FRESH or JRS format. */
2016-01-27 10:29:26 +00:00
2016-02-02 02:14:36 +00:00
_create = function(src, dst, opts) {
var results;
2016-01-27 10:29:26 +00:00
if (!src || !src.length) {
2016-02-02 02:14:36 +00:00
this.err(HMSTATUS.createNameMissing, {
2016-01-27 10:29:26 +00:00
quit: true
2016-02-02 02:14:36 +00:00
});
return null;
}
results = _.map(src, function(t) {
var r;
if (opts.assert && this.hasError()) {
return {};
}
r = _createOne.call(this, t, opts);
if (r.fluenterror) {
r.quit = opts.assert;
this.err(r.fluenterror, r);
}
return r;
}, this);
if (this.hasError() && !opts.assert) {
2016-02-02 03:56:08 +00:00
this.reject(this.errorCode);
2016-02-02 02:14:36 +00:00
} else if (!this.hasError()) {
this.resolve(results);
2016-01-27 10:29:26 +00:00
}
2016-02-02 02:14:36 +00:00
return results;
};
/** Create a single new resume */
_createOne = function(t, opts) {
var RezClass, newRez, ret, safeFmt;
try {
ret = null;
2016-01-27 10:29:26 +00:00
safeFmt = opts.format.toUpperCase();
this.stat(HMEVENT.beforeCreate, {
fmt: safeFmt,
file: t
});
MKDIRP.sync(PATH.dirname(t));
RezClass = require('../core/' + safeFmt.toLowerCase() + '-resume');
2016-02-02 02:14:36 +00:00
newRez = RezClass["default"]();
newRez.save(t);
ret = newRez;
} catch (_error) {
ret = {
fluenterror: HMSTATUS.createError,
inner: _error
};
} finally {
this.stat(HMEVENT.afterCreate, {
2016-01-27 10:29:26 +00:00
fmt: safeFmt,
2016-02-02 02:14:36 +00:00
file: t,
isError: ret.fluenterror
2016-01-27 10:29:26 +00:00
});
2016-02-02 02:14:36 +00:00
return ret;
}
2016-01-27 10:29:26 +00:00
};
}).call(this);
2016-02-02 02:14:36 +00:00
//# sourceMappingURL=create.js.map