files.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const fs = require('fs');
  2. const path = require('path');
  3. const tiny = require("@peterpanhihi/tiny");
  4. const getFilesIn = require('get-files-in')
  5. const globalVariables = require('../lib/globalVars');
  6. const Language = require("@shypes/language-translator");
  7. Language.setActiveLang(globalVariables.language)
  8. module.exports = {
  9. getCurrentDirectoryBase: () => {
  10. return path.basename(process.cwd());
  11. },
  12. directoryExists: (filePath) => {
  13. return fs.existsSync(filePath);
  14. },
  15. writeIpAddress: (value) => {
  16. const data = {
  17. ipAddress: value
  18. }
  19. try {
  20. fs.writeFileSync('./data/options.json', JSON.stringify(data))
  21. } catch (err) {
  22. console.log(err)
  23. }
  24. },
  25. loadPackageList: () => {
  26. try {
  27. const packageList = JSON.parse(fs.readFileSync('./data/xiaomiPackageRemovalList.json', 'utf8'));
  28. return packageList
  29. } catch (err) {
  30. console.log(err)
  31. }
  32. },
  33. renameLocalApk: async (apkList) => {
  34. return new Promise(function (resolve, reject) {
  35. for (let e of apkList) {
  36. a = tiny(e)
  37. fs.rename(e, a, function (err) {
  38. if (err) console.log('ERROR: ' + err);
  39. });
  40. }
  41. resolve(x / y);
  42. }).catch(err => NaN)
  43. },
  44. getListOfAPk: (path) => {
  45. const result = getFilesIn(path, matchFiletypes = ["apk"], checkSubDirectories = false)
  46. return result
  47. },
  48. getLanguageFiles: () => {
  49. const result = getFilesIn('./lang/', matchFiletypes = ["json"], checkSubDirectories = false)
  50. return result
  51. },
  52. }