1
0
Fork 0
freesewing/packages/plugin-validate/src/index.js

61 lines
2 KiB
JavaScript
Raw Normal View History

2019-08-03 15:03:33 +02:00
import { version, name } from '../package.json'
import validate from './validate'
2018-08-10 16:03:39 +02:00
export default {
name: name,
version: version,
hooks: {
2021-01-31 09:22:15 +01:00
preDraft: function (pattern) {
2019-08-03 15:03:33 +02:00
if (typeof pattern.settings.measurements === 'undefined')
return pattern.debug({
2019-08-03 15:03:33 +02:00
type: 'error',
label: '👕 No measurements provided',
2019-08-03 15:03:33 +02:00
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({
2019-08-03 15:03:33 +02:00
type: 'error',
label: '👕 Missing measurement:',
msg: measurement
2019-08-03 15:03:33 +02:00
})
pattern.debug({
2019-08-03 15:03:33 +02:00
type: 'info',
label: '👕 All measurements:',
msg: pattern.settings.measurements
2019-08-03 15:03:33 +02:00
})
throw new Error(`Missing measurement: ${measurement}`)
} else {
2018-12-20 07:59:16 +01:00
pattern.debug({
2019-08-03 15:03:33 +02:00
type: 'success',
label: '👕 ' + measurement + ' is ok',
msg: pattern.settings.measurements[measurement]
2019-08-03 15:03:33 +02:00
})
2018-08-10 16:03:39 +02:00
}
}
},
2021-01-31 09:22:15 +01:00
postDraft: function (pattern) {
2019-08-03 15:03:33 +02:00
for (let partId in pattern.parts) {
let part = pattern.parts[partId]
let { debug } = part.shorthand()
for (let pointId in part.points) {
validate.point(part.points[pointId], partId, pointId, debug)
validate.text('point', part.points[pointId], partId, pointId, debug)
}
2019-08-03 15:03:33 +02:00
for (let pathId in part.paths) {
validate.path(part.paths[pathId], partId, pathId, debug)
validate.text('path', part.paths[pathId], partId, pathId, debug)
}
2019-08-03 15:03:33 +02:00
for (let snippetId in part.snippets) {
if (!validate.snippet(part.snippets[snippetId], partId, snippetId, debug)) {
throw new Error(
`pattern.parts.${partId}.snippets.${snippetId} is not a valid Snippet object`
)
}
}
}
2018-08-10 16:03:39 +02:00
}
}
2019-08-03 15:03:33 +02:00
}