js-yaml#Schema TypeScript Examples
The following examples show how to use
js-yaml#Schema.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: read-file-or-url.ts From graphql-mesh with MIT License | 6 votes |
function getSchema(filepath: string, logger?: Logger): Schema {
return DEFAULT_SCHEMA.extend([
new Type('!include', {
kind: 'scalar',
resolve(path: string) {
return typeof path === 'string';
},
construct(path: string) {
const newCwd = pathModule.dirname(filepath);
const absoluteFilePath = pathModule.isAbsolute(path) ? path : pathModule.resolve(newCwd, path);
const content = fs.readFileSync(absoluteFilePath, 'utf8');
return loadYaml(absoluteFilePath, content, logger);
},
}),
new Type('!includes', {
kind: 'scalar',
resolve(path: string) {
return typeof path === 'string';
},
construct(path: string) {
const newCwd = pathModule.dirname(filepath);
const absoluteDirPath = pathModule.isAbsolute(path) ? path : pathModule.resolve(newCwd, path);
const files = fs.readdirSync(absoluteDirPath);
return files.map(filePath => {
const absoluteFilePath = pathModule.resolve(absoluteDirPath, filePath);
const fileContent = fs.readFileSync(absoluteFilePath, 'utf8');
return loadYaml(absoluteFilePath, fileContent, logger);
});
},
}),
]);
}