* @param {string} fromName * @param {string} toName * @param {boolean} replace * @returns {Language}
(fromName, toName, replace = false)
| 121 | * @returns {Language} |
| 122 | */ |
| 123 | copyLanguage(fromName, toName, replace = false) { |
| 124 | const fromLang = this.getLanguage(fromName); |
| 125 | const newPath = (`${fromLang.rootPath}/${toName}/`).replace(/\\/g, '/'); |
| 126 | |
| 127 | if (this.languageNames.includes(toName) && !replace) { |
| 128 | const err = new Error(`Folder already exists. ${newPath}`); |
| 129 | err.number = 10003; |
| 130 | throw err; |
| 131 | } |
| 132 | |
| 133 | let toLang; |
| 134 | if (this.languageNames.includes(toName)) { |
| 135 | toLang = this.getLanguage(toName); |
| 136 | } else { |
| 137 | toLang = new Language({ |
| 138 | framework: this.framework, |
| 139 | languagePath: newPath, |
| 140 | courseDir: this.courseDir, |
| 141 | jsonext: this.jsonext, |
| 142 | trackingIdType: this.trackingIdType |
| 143 | }); |
| 144 | this.languages.push(toLang); |
| 145 | } |
| 146 | |
| 147 | fs.mkdirpSync(newPath); |
| 148 | |
| 149 | fromLang.files.forEach(file => { |
| 150 | const pathParsed = path.parse(file.path.replace(/\\/g, '/')); |
| 151 | const newLocation = `${newPath}${pathParsed.name}${pathParsed.ext}`; |
| 152 | fs.removeSync(newLocation); |
| 153 | fs.copyFileSync(file.path, newLocation); |
| 154 | }); |
| 155 | |
| 156 | toLang.load(); |
| 157 | return toLang; |
| 158 | } |
| 159 | |
| 160 | /** @returns {Data} */ |
| 161 | checkIds() { |
no test coverage detected