2016-01-27 10:29:26 +00:00
|
|
|
(function() {
|
2018-02-12 05:05:29 +00:00
|
|
|
/**
|
|
|
|
Implementation of the 'create' verb for HackMyResume.
|
|
|
|
@module verbs/create
|
|
|
|
@license MIT. See LICENSE.md for details.
|
|
|
|
*/
|
|
|
|
/** Create a new empty resume in either FRESH or JRS format. */
|
|
|
|
/** Create a single new resume */
|
|
|
|
var CreateVerb, HMEVENT, HMSTATUS, MKDIRP, PATH, Verb, _, _create, _createOne, chalk;
|
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');
|
|
|
|
|
2018-02-12 05:05:29 +00:00
|
|
|
module.exports = CreateVerb = class CreateVerb extends Verb {
|
|
|
|
constructor() {
|
|
|
|
super('new', _create);
|
2016-01-27 10:29:26 +00:00
|
|
|
}
|
2016-02-02 04:16:49 +00:00
|
|
|
|
2018-02-12 05:05:29 +00:00
|
|
|
};
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
_createOne = function(t, opts) {
|
2018-02-12 05:05:29 +00:00
|
|
|
var RezClass, err, newRez, ret, safeFmt;
|
2016-02-02 02:14:36 +00:00
|
|
|
try {
|
|
|
|
ret = null;
|
2016-01-27 10:29:26 +00:00
|
|
|
safeFmt = opts.format.toUpperCase();
|
|
|
|
this.stat(HMEVENT.beforeCreate, {
|
|
|
|
fmt: safeFmt,
|
|
|
|
file: t
|
|
|
|
});
|
2018-02-12 05:05:29 +00:00
|
|
|
MKDIRP.sync(PATH.dirname(t)); // Ensure dest folder exists;
|
2016-01-27 10:29:26 +00:00
|
|
|
RezClass = require('../core/' + safeFmt.toLowerCase() + '-resume');
|
2018-02-12 05:05:29 +00:00
|
|
|
newRez = RezClass.default();
|
2016-02-02 02:14:36 +00:00
|
|
|
newRez.save(t);
|
|
|
|
ret = newRez;
|
2018-02-12 05:05:29 +00:00
|
|
|
} catch (error) {
|
|
|
|
err = error;
|
2016-02-02 02:14:36 +00:00
|
|
|
ret = {
|
|
|
|
fluenterror: HMSTATUS.createError,
|
2018-02-12 05:05:29 +00:00
|
|
|
inner: err
|
2016-02-02 02:14:36 +00:00
|
|
|
};
|
|
|
|
} 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
|