diff --git a/.gitignore b/.gitignore index 302ba138..e466d665 100644 --- a/.gitignore +++ b/.gitignore @@ -72,4 +72,5 @@ web-build/ # @end expo-cli -.vscode/ \ No newline at end of file +.vscode/ +src/sources/en/generators/ \ No newline at end of file diff --git a/package.json b/package.json index 9d55e3d3..65e28fab 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "buildRelease": "cd android && gradlew clean && gradlew assembleRelease", "sources:madara": "node scripts/generateMadaraSource.cjs && prettier --write {src/sources/multisrc/madara/MadaraGenerator.ts,src/sources/sources.json}", "source:generator": "node scripts/generateSource.cjs", + "strings": "node scripts/stringTypes.cjs", "prepare": "husky install" }, "dependencies": { diff --git a/scripts/stringTypes.cjs b/scripts/stringTypes.cjs new file mode 100644 index 00000000..920e7d77 --- /dev/null +++ b/scripts/stringTypes.cjs @@ -0,0 +1,46 @@ +const fs = require('fs'); +const path = require('path'); +const prettier = require('prettier'); +const prettierConfig = require('../.prettierrc'); + +const flatten = (obj, target, prefix) => { + (target = target || {}), (prefix = prefix || ''); + + Object.keys(obj).forEach(function (key) { + if (typeof obj[key] === 'object' && obj[key] !== null) { + flatten(obj[key], target, prefix + key + '.'); + } else { + return (target[prefix + key] = 'string'); + } + }); + + return target; +}; + +const strings = fs.readFileSync( + path.resolve(process.cwd(), 'strings/languages/en/strings.json'), + 'utf8', +); + +console.log(flatten(JSON.parse(strings, ''))); + +const stringTypes = `/**\n * This file is auto-generated\n */\n\n + +export interface StringMap ${JSON.stringify(flatten(JSON.parse(strings)))} + +`; + +const formatContent = prettier.format(stringTypes, { + parser: 'typescript', + ...prettierConfig, +}); + +fs.writeFile( + path.resolve(process.cwd(), 'strings/types/index.ts'), + formatContent, + err => { + if (err) { + console.log(err); + } + }, +); diff --git a/strings/types/index.ts b/strings/types/index.ts index fdcc1b20..c7b74442 100644 --- a/strings/types/index.ts +++ b/strings/types/index.ts @@ -1,24 +1,43 @@ +/** + * This file is auto-generated + */ + export interface StringMap { - 'browse': 'string'; - 'browseScreen.searchbar': 'string'; + 'library': 'string'; + 'libraryScreen.searchbar': 'string'; + 'libraryScreen.empty': 'string'; + 'libraryScreen.bottomSheet.filters.downloaded': 'string'; + 'libraryScreen.bottomSheet.filters.unread': 'string'; + 'libraryScreen.bottomSheet.filters.completed': 'string'; + 'libraryScreen.bottomSheet.sortOrders.dateAdded': 'string'; + 'libraryScreen.bottomSheet.sortOrders.alphabetically': 'string'; + 'libraryScreen.bottomSheet.sortOrders.totalChapters': 'string'; + 'libraryScreen.bottomSheet.display.displayMode': 'string'; + 'libraryScreen.bottomSheet.display.compact': 'string'; + 'libraryScreen.bottomSheet.display.comfortable': 'string'; + 'libraryScreen.bottomSheet.display.noTitle': 'string'; + 'libraryScreen.bottomSheet.display.list': 'string'; + 'libraryScreen.bottomSheet.display.badges': 'string'; + 'libraryScreen.bottomSheet.display.downloadBadges': 'string'; + 'libraryScreen.bottomSheet.display.unreadBadges': 'string'; + 'libraryScreen.bottomSheet.display.showNoOfItems': 'string'; + 'updates': 'string'; + 'updatesScreen.searchbar': 'string'; + 'updatesScreen.lastUpdatedAt': 'string'; 'history': 'string'; 'historyScreen.searchbar': 'string'; - 'library': 'string'; - 'libraryScreen.empty': 'string'; - 'libraryScreen.searchbar': 'string'; + 'browse': 'string'; + 'browseScreen.searchbar': 'string'; + 'novelScreen.addToLibaray': 'string'; + 'novelScreen.inLibaray': 'string'; + 'novelScreen.continueReading': 'string'; + 'novelScreen.chapters': 'string'; + 'novelScreen.migrate': 'string'; + 'novelScreen.bottomSheet.filter': 'string'; + 'novelScreen.bottomSheet.sort': 'string'; + 'novelScreen.bottomSheet.display': 'string'; 'more': 'string'; 'moreScreen.settings': 'string'; 'moreScreen.settingsScreen.generalSettings': 'string'; 'moreScreen.settingsScreen.readerSettings': 'string'; - 'novelScreen.addToLibaray': 'string'; - 'novelScreen.bottomSheet.display': 'string'; - 'novelScreen.bottomSheet.filter': 'string'; - 'novelScreen.bottomSheet.sort': 'string'; - 'novelScreen.chapters': 'string'; - 'novelScreen.continueReading': 'string'; - 'novelScreen.inLibaray': 'string'; - 'novelScreen.migrate': 'string'; - 'updates': 'string'; - 'updatesScreen.searchbar': 'string'; - 'updatesScreen.lastUpdatedAt': 'string'; }