Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 }).catch((error) => | 218 }).catch((error) => |
219 { | 219 { |
220 console.error(error); | 220 console.error(error); |
221 }); | 221 }); |
222 }); | 222 }); |
223 } | 223 } |
224 | 224 |
225 /** | 225 /** |
226 * Reads JSON file and assign filename and locale to it | 226 * Reads JSON file and assign filename and locale to it |
227 * @param {string} filePath - ex.: "locales/en_US/desktop-options.json" | 227 * @param {string} filePath - ex.: "locales/en_US/desktop-options.json" |
228 * @param {function} callback - fileName, locale and strings of locale file | 228 * @returns {Promise<Object>} resolves fileName, locale and strings of the |
Thomas Greiner
2018/06/12 14:50:42
Detail: This parameter no longer exists. Instead,
saroyanm
2018/06/13 15:36:25
Done.
| |
229 * Parameters: | 229 * locale file |
230 * * Error message | 230 */ |
231 * * Object containing fileName, locale and strings | 231 function readJson(filePath) |
232 * @returns {Promise} | 232 { |
233 */ | 233 return readFile(filePath, "utf8").then((data) => |
234 function readJson(filePath, callback) | |
235 { | |
236 return new Promise((resolve, reject) => | |
Thomas Greiner
2018/06/12 14:50:42
You can simply return the promise you get from `re
saroyanm
2018/06/13 15:36:25
Done.
| |
237 { | 234 { |
238 const {dir, base} = path.parse(filePath); | 235 const {dir, base} = path.parse(filePath); |
239 readFile(filePath, "utf8").then((data) => | 236 const locale = dir.split(path.sep).pop(); |
240 { | 237 const strings = JSON.parse(data); |
241 const locale = dir.split(path.sep).pop(); | 238 return {fileName: base, locale, strings}; |
242 const strings = JSON.parse(data); | |
243 resolve({fileName: base, locale, strings}); | |
244 }).catch((err) => | |
245 { | |
246 reject(err); | |
247 }); | |
248 }); | 239 }); |
249 } | 240 } |
250 | 241 |
251 /** | 242 /** |
252 * Exit process and log error message | 243 * Exit process and log error message |
253 * @param {String} error error message | 244 * @param {String} error error message |
254 */ | 245 */ |
255 function exitProcess(error) | 246 function exitProcess(error) |
256 { | 247 { |
257 console.error(error); | 248 console.error(error); |
258 process.exit(1); | 249 process.exit(1); |
259 } | 250 } |
260 | 251 |
261 // CLI | 252 // CLI |
262 const helpText = ` | 253 const helpText = ` |
263 About: Converts locale files between CSV and JSON formats | 254 About: Converts locale files between CSV and JSON formats |
264 Usage: csv-export.js [option] [argument] | 255 Usage: csv-export.js [option] [argument] |
265 Options: | 256 Options: |
266 -f [FILENAME] Name of the files to be exported ex.: -f firstRun.json | 257 -f [FILENAME] Name of the files to be exported ex.: -f firstRun.json |
267 option can be used multiple times. | 258 option can be used multiple times. |
268 If omitted all files are being exported | 259 If omitted all files are being exported |
269 | 260 |
270 -o [FILENAME] Output filename ex.: | 261 -o [FILENAME] Output filename ex.: |
271 -f firstRun.json -o {hash}-firstRun.csv | 262 -f firstRun.json -o firstRun.csv |
272 Placeholders: | |
273 {hash} - Mercurial current revision hash | |
Thomas Greiner
2018/06/12 14:50:42
Detail: Again, these placeholders no longer exists
saroyanm
2018/06/13 15:36:26
Done.
| |
274 If omitted the output fileName is set to | 263 If omitted the output fileName is set to |
275 translations-{repo}-{hash}.csv | 264 translations.csv |
276 | 265 |
277 -i [FILENAME] Import file path ex: -i issue-reporter.csv | 266 -i [FILENAME] Import file path ex: -i issue-reporter.csv |
278 `; | 267 `; |
279 | 268 |
280 const argv = process.argv.slice(2); | 269 const argv = process.argv.slice(2); |
281 let stopExportScript = false; | 270 let stopExportScript = false; |
282 // Filter to be used export to the fileNames inside | 271 // Filter to be used export to the fileNames inside |
283 const filesFilter = []; | 272 const filesFilter = []; |
284 | 273 |
285 for (let i = 0; i < argv.length; i++) | 274 for (let i = 0; i < argv.length; i++) |
(...skipping 25 matching lines...) Expand all Loading... | |
311 } | 300 } |
312 const importFile = argv[i + 1]; | 301 const importFile = argv[i + 1]; |
313 importTranslations(importFile); | 302 importTranslations(importFile); |
314 stopExportScript = true; | 303 stopExportScript = true; |
315 break; | 304 break; |
316 } | 305 } |
317 } | 306 } |
318 | 307 |
319 if (!stopExportScript) | 308 if (!stopExportScript) |
320 exportTranslations(filesFilter); | 309 exportTranslations(filesFilter); |
LEFT | RIGHT |