2018-08-10 16:03:39 +02:00
|
|
|
import { version, name } from "../package.json";
|
2018-12-18 15:25:19 +01:00
|
|
|
import validate from "./validate";
|
2018-09-05 16:38:51 +02:00
|
|
|
|
2018-08-10 16:03:39 +02:00
|
|
|
export default {
|
|
|
|
name: name,
|
|
|
|
version: version,
|
|
|
|
hooks: {
|
2018-12-18 15:25:19 +01:00
|
|
|
preDraft: function(pattern) {
|
|
|
|
if(typeof pattern.settings.measurements === "undefined")
|
|
|
|
return pattern.debug({
|
|
|
|
type: "error",
|
|
|
|
label: '👕 No measurements provided',
|
|
|
|
msg: "You did not provide any measurements. Most, if not all, patterns require measurements, so this is most likely an issue."
|
|
|
|
});
|
|
|
|
for(let measurement of pattern.config.measurements) {
|
|
|
|
if(!pattern.settings.measurements[measurement]) {
|
|
|
|
pattern.debug({
|
|
|
|
type: "error",
|
|
|
|
label: '👕 Missing measurement:',
|
|
|
|
msg: measurement
|
|
|
|
});
|
|
|
|
pattern.debug({
|
|
|
|
type: "info",
|
|
|
|
label: '👕 All measurements:',
|
|
|
|
msg: pattern.settings.measurements
|
|
|
|
});
|
|
|
|
throw new Error(`Missing measurement: ${measurement}`);
|
|
|
|
} else {
|
2018-12-20 07:59:16 +01:00
|
|
|
pattern.debug({
|
2018-12-18 15:25:19 +01:00
|
|
|
type: "success",
|
|
|
|
label: '👕 '+measurement+' is ok',
|
|
|
|
msg: pattern.settings.measurements[measurement]
|
|
|
|
});
|
2018-08-10 16:03:39 +02:00
|
|
|
}
|
|
|
|
}
|
2018-09-05 16:38:51 +02:00
|
|
|
},
|
2018-12-18 15:25:19 +01:00
|
|
|
postDraft: function(pattern) {
|
|
|
|
for(let partId in pattern.parts) {
|
|
|
|
let part = pattern.parts[partId];
|
2018-09-05 16:38:51 +02:00
|
|
|
let { debug } = part.shorthand();
|
|
|
|
for(let pointId in part.points) {
|
2018-12-18 15:25:19 +01:00
|
|
|
validate.point(part.points[pointId], partId, pointId, debug);
|
|
|
|
validate.text('point', part.points[pointId], partId, pointId, debug);
|
2018-09-05 16:38:51 +02:00
|
|
|
}
|
|
|
|
for(let pathId in part.paths) {
|
2018-12-18 15:25:19 +01:00
|
|
|
validate.path(part.paths[pathId], partId, pathId, debug);
|
|
|
|
validate.text('path', part.paths[pathId], partId, pathId, debug);
|
2018-09-05 16:38:51 +02:00
|
|
|
}
|
|
|
|
for(let snippetId in part.snippets) {
|
2018-12-18 15:25:19 +01:00
|
|
|
if(!validate.snippet(part.snippets[snippetId], partId, snippetId, debug)) {
|
|
|
|
throw new Error(`pattern.parts.${partId}.snippets.${snippetId} is not a valid Snippet object`);
|
2018-09-05 16:38:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-08-10 16:03:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|