@returns {Schemas}
()
| 57 | |
| 58 | /** @returns {Schemas} */ |
| 59 | load() { |
| 60 | |
| 61 | /** |
| 62 | * @param {Plugin} plugin |
| 63 | * @param {string} filePath |
| 64 | */ |
| 65 | const createSchema = (plugin, filePath) => { |
| 66 | const json = fs.readJSONSync(filePath); |
| 67 | const isExtensionSchema = Boolean(json.properties.pluginLocations); |
| 68 | const InferredSchemaClass = (isExtensionSchema ? ExtensionSchema : ModelSchema); |
| 69 | const inferredSchemaName = (plugin.name === 'core') ? |
| 70 | path.parse(filePath).name.split('.')[0] : // if core, get schema name from file name |
| 71 | isExtensionSchema ? |
| 72 | plugin.name : // assume schema name is plugin name |
| 73 | plugin.targetAttribute; // assume schema name is plugin._[type] value |
| 74 | return new InferredSchemaClass({ |
| 75 | name: inferredSchemaName, |
| 76 | plugin, |
| 77 | framework: this.framework, |
| 78 | filePath, |
| 79 | globalsType: plugin.type, |
| 80 | targetAttribute: plugin.targetAttribute |
| 81 | }); |
| 82 | }; |
| 83 | |
| 84 | this.plugins = new Plugins({ |
| 85 | framework: this.framework, |
| 86 | includedFilter: this.includedFilter, |
| 87 | sourcePath: this.sourcePath, |
| 88 | log: this.log, |
| 89 | warn: this.warn |
| 90 | }); |
| 91 | this.plugins.load(); |
| 92 | |
| 93 | this.schemas = []; |
| 94 | this.plugins.plugins.forEach(plugin => globs.sync(plugin.schemaLocations).forEach(filePath => { |
| 95 | const schema = createSchema(plugin, filePath); |
| 96 | schema.load(); |
| 97 | this.schemas.push(schema); |
| 98 | })); |
| 99 | |
| 100 | this.generateCourseGlobals(); |
| 101 | this.generateModelExtensions(); |
| 102 | |
| 103 | return this; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Copy globals schema extensions from model/extension plugins to the course._globals |
no test coverage detected