@returns {Language}
()
| 61 | |
| 62 | /** @returns {Language} */ |
| 63 | load() { |
| 64 | this.files = []; |
| 65 | this._itemIdIndex = {}; |
| 66 | this.courseFileItem = null; |
| 67 | |
| 68 | const dataFiles = globs.sync(path.join(this.path, '*.' + this.jsonext)).map((dataFilePath) => { |
| 69 | const relativePath = dataFilePath.slice(this.path.length); |
| 70 | return relativePath; |
| 71 | }).filter((dataFilePath) => { |
| 72 | const isManifest = (dataFilePath === this.manifestPath); |
| 73 | // Skip file if it is the Authoring Tool import/export asset manifest |
| 74 | const isAATAssetJSON = (dataFilePath === 'assets.json'); |
| 75 | return !isManifest && !isAATAssetJSON; |
| 76 | }); |
| 77 | |
| 78 | dataFiles.forEach(jsonFileName => { |
| 79 | const jsonFilePath = (this.path + jsonFileName).replace(/\\/g, '/'); |
| 80 | const file = new LanguageFile({ |
| 81 | framework: this.framework, |
| 82 | language: this, |
| 83 | jsonext: this.jsonext, |
| 84 | path: jsonFilePath, |
| 85 | data: null, |
| 86 | hasChanged: false |
| 87 | }); |
| 88 | file.load(); |
| 89 | this.files.push(file); |
| 90 | }); |
| 91 | |
| 92 | this._itemIdIndex = this.getAllFileItems().reduce((index, fileItem) => { |
| 93 | const { file, item } = fileItem; |
| 94 | if (item._id && index[item._id]) { |
| 95 | const err = new Error(`Duplicate ids ${item._id} in ${index[item._id].file.path} and ${file.path}`); |
| 96 | err.number = 10006; |
| 97 | throw err; |
| 98 | } else if (item._id) { |
| 99 | index[item._id] = fileItem; |
| 100 | } |
| 101 | if (item._type === 'course' && this.courseFileItem) { |
| 102 | const err = new Error(`Duplicate course items found, in ${index[item._id].file.path} and ${file.path}`); |
| 103 | err.number = 10007; |
| 104 | throw err; |
| 105 | } else if (item._type === 'course') { |
| 106 | this.courseFileItem = fileItem; |
| 107 | } |
| 108 | return index; |
| 109 | }, {}); |
| 110 | |
| 111 | return this; |
| 112 | } |
| 113 | |
| 114 | /** @type {boolean} */ |
| 115 | get isValid() { |
no test coverage detected