-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate.ts
38 lines (33 loc) · 1.14 KB
/
validate.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import path from 'path';
import {validateRepositoryDefinition} from './src/repository-definition/validation';
import {
createRepositoryDefinitionLoader,
FailedLoadHandler,
} from './src/repository-loader';
import {createYamlSource} from './src/repository-loader/sources';
import {createLoggerFactory, loggerFactory, nullWriter} from './src/logger';
(async () => {
const logger = loggerFactory.createLogger();
const onFailedLoad: FailedLoadHandler = (source, e) =>
logger.error(`An error occurred loading from source ${source.id()}`, e);
const repositoryLoader = createRepositoryDefinitionLoader(
[
createYamlSource(
path.join(__dirname, 'repositories'),
createLoggerFactory(nullWriter)
),
],
onFailedLoad
);
repositoryLoader.subscribe(async definition => {
const validationResults = await validateRepositoryDefinition(definition);
if (validationResults.length > 0) {
validationResults.forEach(error =>
logger.error('Validation error:', error)
);
throw new Error(
`Repository ${definition.id} failed Claviger Repository schema validation.`
);
}
});
})();